Browse Source

Re-add subscription tp CSComponentAssemblyReference, along with re-run 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.
Matt Benic 9 years ago
parent
commit
793ea2c29f
1 changed files with 38 additions and 16 deletions
  1. 38 16
      Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs

+ 38 - 16
Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs

@@ -332,6 +332,21 @@ namespace AtomicEngine
 
         }
 
+        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 @@ namespace AtomicEngine
 
             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
         }
@@ -370,7 +391,8 @@ namespace AtomicEngine
 
             instance = new CSComponentCore();
             instance.ParseComponents();
-            
+
+            instance.SubscribeToEvent("CSComponentAssemblyReference", instance.HandleComponentAssemblyReference);
             instance.SubscribeToEvent("CSComponentLoad", instance.HandleComponentLoad);
             instance.SubscribeToEvent("Update", instance.HandleUpdate);