Преглед изворни кода

Merge pull request #1349 from LumaDigital/MB_ReparentNoComponentUpdate

Fixes CSComponents on reparented nodes not being re-added to the scene for updates
JoshEngebretson пре 9 година
родитељ
комит
38e7f8e8ad
1 измењених фајлова са 17 додато и 9 уклоњено
  1. 17 9
      Script/AtomicNET/AtomicNET/Scene/Scene.cs

+ 17 - 9
Script/AtomicNET/AtomicNET/Scene/Scene.cs

@@ -14,7 +14,16 @@ namespace AtomicEngine
             {
                 //Log.Info($"Node ADDED: {e.Node.Name}");
 
-                // TODO: How to handle adding components on existing node?
+                // The NodeAdded event is generated when adding a node as a child
+
+                e.Node.GetComponents<CSComponent>(componentVector);
+
+                for (uint i = 0; i < componentVector.Size; i++)
+                {
+                    AddCSComponent(componentVector[i]);
+                }
+
+                componentVector.Clear();
 
             });
 
@@ -292,17 +301,16 @@ namespace AtomicEngine
 
             cslist.Add(csc);
 
-            if (cscomponentStart.Contains(csc))
+            if (!csc.started)
             {
-                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
-            }
+                if (cscomponentStart.Contains(csc))
+                {
+                    throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
+                }
 
-            if (csc.started)
-            {
-                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already started");
-            }
 
-            cscomponentStart.Add(csc);
+                cscomponentStart.Add(csc);
+            }
 
         }