diff --git a/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs b/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs index 4037079888..0b04ceb784 100644 --- a/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs +++ b/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs @@ -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 @@ -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 assemblyTypes = null; + Dictionary assemblyTypes = null; - if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes)) - { - componentCache[assemblyPath] = assemblyTypes = new Dictionary(); - } + if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes)) + { + componentCache[assemblyPath] = assemblyTypes = new Dictionary(); + } - 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 } @@ -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);