瀏覽代碼

调整设置IScene的代码

tanghai 1 年之前
父節點
當前提交
5e35725650
共有 1 個文件被更改,包括 29 次插入30 次删除
  1. 29 30
      Unity/Assets/Scripts/Core/Entity/Entity.cs

+ 29 - 30
Unity/Assets/Scripts/Core/Entity/Entity.cs

@@ -191,10 +191,10 @@ namespace ET
                     throw new Exception($"cant set parent self: {this.GetType().FullName}");
                 }
 
-                // 严格限制parent必须要有domain,也就是说parent必须在数据树上面
+                // 严格限制parent必须要有iSence,也就是说parent必须在数据树上面
                 if (value.IScene == null)
                 {
-                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().FullName} {value.GetType().FullName}");
+                    throw new Exception($"cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName}");
                 }
 
                 if (this.parent != null) // 之前有parent
@@ -255,10 +255,10 @@ namespace ET
                     throw new Exception($"cant set parent self: {this.GetType().FullName}");
                 }
 
-                // 严格限制parent必须要有domain,也就是说parent必须在数据树上面
+                // 严格限制parent必须要有iSence,也就是说parent必须在数据树上面
                 if (value.IScene == null)
                 {
-                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().FullName} {value.GetType().FullName}");
+                    throw new Exception($"cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName}");
                 }
 
                 if (this.parent != null) // 之前有parent
@@ -315,7 +315,7 @@ namespace ET
             {
                 if (value == null)
                 {
-                    throw new Exception($"domain cant set null: {this.GetType().FullName}");
+                    throw new Exception($"iScene cant set null: {this.GetType().FullName}");
                 }
 
                 if (this.iScene == value)
@@ -323,43 +323,42 @@ namespace ET
                     return;
                 }
 
-                IScene preScene = this.iScene;
-                this.iScene = value;
+                if (this.iScene != null)
+                {
+                    this.iScene = value;
+                    return;
+                }
 
-                if (preScene == null)
+                if (this.InstanceId == 0)
                 {
-                    if (this.InstanceId == 0)
-                    {
-                        this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
-                    }
+                    this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
+                }
 
-                    this.IsRegister = true;
+                this.IsRegister = true;
 
-                    // 反序列化出来的需要设置父子关系
-                    if (this.components != null)
+                // 反序列化出来的需要设置父子关系
+                if (this.components != null)
+                {
+                    foreach ((long _, Entity component) in this.components)
                     {
-                        foreach ((long _, Entity component) in this.components)
-                        {
-                            component.IsComponent = true;
-                            component.parent = this;
-                            component.IScene = this.iScene;
-                        }
+                        component.IsComponent = true;
+                        component.parent = this;
+                        component.IScene = this.iScene;
                     }
+                }
 
-                    if (this.children != null)
+                if (this.children != null)
+                {
+                    foreach ((long _, Entity child) in this.children)
                     {
-                        foreach ((long _, Entity child) in this.children)
-                        {
-                            child.IsComponent = false;
-                            child.parent = this;
-                            child.IScene = this.iScene;
-                        }
+                        child.IsComponent = false;
+                        child.parent = this;
+                        child.IScene = this.iScene;
                     }
                 }
-
+                    
                 if (!this.IsNew)
                 {
-                    this.IsNew = true;
                     EntitySystemSingleton.Instance.Deserialize(this);
                 }
             }