Skip to content

Commit

Permalink
Re-add subscription tp CSComponentAssemblyReference, along with re-ru…
Browse files Browse the repository at this point in the history
…n check

This is necessary because .Net may not load assemblies for types not directly referenced in the executing assembly, so components in additional dlls were unavailable.
  • Loading branch information
mattbenic committed Sep 13, 2016
1 parent 7477233 commit 793ea2c
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,21 @@ void HandleComponentLoad(uint eventType, ScriptVariantMap eventData)

}

void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
{
#if ATOMIC_DESKTOP || ATOMIC_ANDROID
string assemblyPath = eventData["AssemblyPath"];

string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
if (componentCache.ContainsKey(assemblyName))
return;

Assembly assembly = Assembly.LoadFrom(assemblyPath);

ParseAssembly(assembly);
#endif
}

void ParseComponents()
{
#if ATOMIC_DESKTOP || ATOMIC_ANDROID
Expand All @@ -340,27 +355,33 @@ void ParseComponents()

foreach (Assembly assembly in assemblies)
{
String assemblyPath = assembly.GetName().Name;
ParseAssembly(assembly);
}
#endif
}

void ParseAssembly(Assembly assembly)
{
#if ATOMIC_DESKTOP || ATOMIC_ANDROID
String assemblyPath = assembly.GetName().Name;

Dictionary<string, CSComponentInfo> assemblyTypes = null;
Dictionary<string, CSComponentInfo> assemblyTypes = null;

if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
{
componentCache[assemblyPath] = assemblyTypes = new Dictionary<string, CSComponentInfo>();
}
if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
{
componentCache[assemblyPath] = assemblyTypes = new Dictionary<string, CSComponentInfo>();
}

Type[] types = assembly.GetTypes();
Type[] types = assembly.GetTypes();

foreach (var type in types)
foreach (var type in types)
{
if (type.IsSubclassOf(typeof(CSComponent)))
{
if (type.IsSubclassOf(typeof(CSComponent)))
{
var csinfo = new CSComponentInfo(type);
csinfoLookup[csinfo.Type] = csinfo;
assemblyTypes[type.Name] = csinfo;
}
var csinfo = new CSComponentInfo(type);
csinfoLookup[csinfo.Type] = csinfo;
assemblyTypes[type.Name] = csinfo;
}

}
#endif
}
Expand All @@ -370,7 +391,8 @@ internal static void Initialize()

instance = new CSComponentCore();
instance.ParseComponents();


instance.SubscribeToEvent("CSComponentAssemblyReference", instance.HandleComponentAssemblyReference);
instance.SubscribeToEvent("CSComponentLoad", instance.HandleComponentLoad);
instance.SubscribeToEvent("Update", instance.HandleUpdate);

Expand Down

0 comments on commit 793ea2c

Please sign in to comment.