|
|
@@ -136,35 +136,36 @@ namespace ET
|
|
|
get => this.parent;
|
|
|
set
|
|
|
{
|
|
|
- if (value == null)
|
|
|
+ if (value == this)
|
|
|
{
|
|
|
- throw new Exception($"cant set parent null: {this.GetType().Name}");
|
|
|
+ throw new Exception($"cant set parent self: {this.GetType().Name}");
|
|
|
}
|
|
|
|
|
|
if (this.parent != null) // 之前有parent
|
|
|
{
|
|
|
// parent相同,不设置
|
|
|
- if (this.parent.InstanceId == value.InstanceId)
|
|
|
+ if (value != null && this.parent.InstanceId == value.InstanceId)
|
|
|
{
|
|
|
Log.Error($"重复设置了Parent: {this.GetType().Name} parent: {this.parent.GetType().Name}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.parent.RemoveChild(this);
|
|
|
-
|
|
|
- this.parent = value;
|
|
|
- this.parent.AddChild(this);
|
|
|
-
|
|
|
- this.Domain = this.parent.domain;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (value == null)
|
|
|
+ {
|
|
|
+ this.parent = null;
|
|
|
+ this.IsComponent = false;
|
|
|
+ this.Domain = null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.parent = value;
|
|
|
this.parent.AddChild(this);
|
|
|
-
|
|
|
this.IsComponent = false;
|
|
|
-
|
|
|
- AfterSetParent();
|
|
|
+ this.Domain = this.parent.domain;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -220,54 +221,48 @@ namespace ET
|
|
|
get => this.domain;
|
|
|
set
|
|
|
{
|
|
|
- if (value == null)
|
|
|
+ if (this.InstanceId == 0)
|
|
|
{
|
|
|
- return;
|
|
|
+ this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Entity preDomain = this.domain;
|
|
|
this.domain = value;
|
|
|
-
|
|
|
- //if (!(this.domain is Scene))
|
|
|
- //{
|
|
|
- // throw new Exception($"domain is not scene: {this.GetType().Name}");
|
|
|
- //}
|
|
|
-
|
|
|
- if (preDomain == null)
|
|
|
+
|
|
|
+ // 是否注册跟parent一致
|
|
|
+ if (this.parent != null)
|
|
|
{
|
|
|
- this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
|
|
|
+ this.IsRegister = this.Parent.IsRegister;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ this.IsRegister = false;
|
|
|
+ }
|
|
|
|
|
|
+ if (preDomain == null && !this.IsCreate)
|
|
|
+ {
|
|
|
// 反序列化出来的需要设置父子关系
|
|
|
- if (!this.IsCreate)
|
|
|
+ if (this.componentsDB != null)
|
|
|
{
|
|
|
- if (this.componentsDB != null)
|
|
|
+ foreach (Entity component in this.componentsDB)
|
|
|
{
|
|
|
- foreach (Entity component in this.componentsDB)
|
|
|
- {
|
|
|
- component.IsComponent = true;
|
|
|
- this.Components.Add(component.GetType(), component);
|
|
|
- component.parent = this;
|
|
|
- }
|
|
|
+ component.IsComponent = true;
|
|
|
+ this.Components.Add(component.GetType(), component);
|
|
|
+ component.parent = this;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (this.childrenDB != null)
|
|
|
+ if (this.childrenDB != null)
|
|
|
+ {
|
|
|
+ foreach (Entity child in this.childrenDB)
|
|
|
{
|
|
|
- foreach (Entity child in this.childrenDB)
|
|
|
- {
|
|
|
- child.IsComponent = false;
|
|
|
- this.Children.Add(child.Id, child);
|
|
|
- child.parent = this;
|
|
|
- }
|
|
|
+ child.IsComponent = false;
|
|
|
+ this.Children.Add(child.Id, child);
|
|
|
+ child.parent = this;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 是否注册跟parent一致
|
|
|
- if (this.parent != null)
|
|
|
- {
|
|
|
- this.IsRegister = this.Parent.IsRegister;
|
|
|
- }
|
|
|
-
|
|
|
// 递归设置孩子的Domain
|
|
|
if (this.children != null)
|
|
|
{
|