Skip to content

Commit c76b86e

Browse files
committed
Improved type lookup
1 parent 8bd20f5 commit c76b86e

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

Assets/Kekser/SaveSystem/Attributes/LoadAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Kekser.SaveSystem.Attributes
44
{
55
[AttributeUsage(AttributeTargets.Method)]
6-
public class LoadAttribute : Attribute
6+
public class LoadAttribute : SaveSystemAttribute
77
{
88

99
}

Assets/Kekser/SaveSystem/Attributes/SavableAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Kekser.SaveSystem.Attributes
44
{
55
[AttributeUsage(AttributeTargets.Field)]
6-
public class SavableAttribute : Attribute
6+
public class SavableAttribute : SaveSystemAttribute
77
{
88

99
}

Assets/Kekser/SaveSystem/Attributes/SaveAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Kekser.SaveSystem.Attributes
44
{
55
[AttributeUsage(AttributeTargets.Method)]
6-
public class SaveAttribute : Attribute
6+
public class SaveAttribute : SaveSystemAttribute
77
{
88

99
}

Assets/Kekser/SaveSystem/Attributes/SaveAttributeManager.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5-
using System.Text.RegularExpressions;
65
using Kekser.SaveSystem.Data;
76
using UnityEngine;
87

@@ -55,13 +54,16 @@ public static void CacheTypes()
5554
if (_prefabRegistry == null)
5655
throw new Exception("PrefabRegistry not found! Save/Load system will not work!");
5756

58-
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
57+
string definedIn = typeof(SaveSystemAttribute).Assembly.GetName().Name;
58+
5959
Dictionary<Type, FieldInfo[]> checkedFields = new Dictionary<Type, FieldInfo[]>();
6060
Dictionary<Type, MethodInfo[]> checkedMethods = new Dictionary<Type, MethodInfo[]>();
6161

62-
foreach (Assembly assembly in assemblies)
62+
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
6363
{
64-
if (Regex.IsMatch(assembly.FullName, AssembliesToIgnoreRegex))
64+
if (assembly.GlobalAssemblyCache
65+
|| assembly.GetName().Name != definedIn
66+
&& assembly.GetReferencedAssemblies().All(assemblyName => assemblyName.Name != definedIn))
6567
continue;
6668

6769
Type[] types = assembly.GetTypes();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Kekser.SaveSystem.Attributes
4+
{
5+
public abstract class SaveSystemAttribute : Attribute
6+
{
7+
8+
}
9+
}

Assets/Kekser/SaveSystem/Attributes/SaveSystemAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Kekser/SaveSystem/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.kekser.savesystem",
33
"displayName": "SaveSystem",
44
"author": { "name": "Kekser", "url": "https://github.com/DerKekser" },
5-
"version": "1.1.2",
5+
"version": "1.1.3",
66
"unity": "2020.3",
77
"description": "A save system for unity.",
88
"keywords": [ "save", "load" ],

0 commit comments

Comments
 (0)