浏览代码

给Entity设置新的Parent时,同步更新View Object (#432)

Bill 2 年之前
父节点
当前提交
680b05e38c
共有 1 个文件被更改,包括 17 次插入3 次删除
  1. 17 3
      Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

+ 17 - 3
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -71,8 +71,8 @@ namespace ET
                 {
                     this.status &= ~EntityStatus.IsRegister;
                 }
-
-                
+				
+				
                 if (!value)
                 {
                     Root.Instance.Remove(this.InstanceId);
@@ -82,7 +82,7 @@ namespace ET
                     Root.Instance.Add(this);
                     EventSystem.Instance.RegisterSystem(this);
                 }
-
+                
 #if ENABLE_VIEW && UNITY_EDITOR
                 if (value)
                 {
@@ -202,6 +202,20 @@ namespace ET
                 this.IsComponent = false;
                 this.parent.AddToChildren(this);
                 this.Domain = this.parent.domain;
+
+#if ENABLE_VIEW && UNITY_EDITOR
+                this.viewGO.GetComponent<ComponentView>().Component = this;
+                this.viewGO.transform.SetParent(this.Parent == null ?
+                        UnityEngine.GameObject.Find("Global").transform : this.Parent.viewGO.transform);
+                foreach (var child in this.Children.Values)
+                {
+                    child.viewGO.transform.SetParent(this.viewGO.transform);
+                }
+                foreach (var comp in this.Components.Values)
+                {
+                    comp.viewGO.transform.SetParent(this.viewGO.transform);
+                }
+#endif
             }
         }