Przeglądaj źródła

IsRegister IsCreate属于框架使用,设置成protected,防止被人乱用

tanghai 4 lat temu
rodzic
commit
5d5571636c

+ 3 - 14
Unity/Assets/Model/Core/Entity/EntitySceneFactory.cs

@@ -4,32 +4,21 @@
     {
     {
         public static Scene CreateScene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent = null)
         public static Scene CreateScene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent = null)
         {
         {
-            Scene scene = new Scene(id, instanceId, zone, sceneType, name);
-            scene.IsRegister = true;
-            scene.Parent = parent;
-            scene.Domain = scene;
+            Scene scene = new Scene(id, instanceId, zone, sceneType, name, parent);
 
 
             return scene;
             return scene;
         }
         }
 
 
         public static Scene CreateScene(long instanceId, int zone, SceneType sceneType, string name, Entity parent = null)
         public static Scene CreateScene(long instanceId, int zone, SceneType sceneType, string name, Entity parent = null)
         {
         {
-            Scene scene = new Scene(instanceId, zone, sceneType, name);
-            scene.IsRegister = true;
-            scene.Parent = parent;
-            scene.Domain = scene;
-
+            Scene scene = new Scene(instanceId, zone, sceneType, name, parent);
             return scene;
             return scene;
         }
         }
 
 
         public static Scene CreateScene(int zone, SceneType sceneType, string name, Entity parent = null)
         public static Scene CreateScene(int zone, SceneType sceneType, string name, Entity parent = null)
         {
         {
             long instanceId = IdGenerater.Instance.GenerateInstanceId();
             long instanceId = IdGenerater.Instance.GenerateInstanceId();
-            Scene scene = new Scene(instanceId, zone, sceneType, name);
-            scene.IsRegister = true;
-            scene.Parent = parent;
-            scene.Domain = scene;
-
+            Scene scene = new Scene(instanceId, zone, sceneType, name, parent);
             return scene;
             return scene;
         }
         }
     }
     }

+ 8 - 4
Unity/Assets/Model/Core/Entity/Scene.cs

@@ -18,7 +18,7 @@
             set;
             set;
         }
         }
 
 
-        public Scene(long instanceId, int zone, SceneType sceneType, string name)
+        public Scene(long instanceId, int zone, SceneType sceneType, string name, Entity parent)
         {
         {
             this.Id = instanceId;
             this.Id = instanceId;
             this.InstanceId = instanceId;
             this.InstanceId = instanceId;
@@ -26,11 +26,13 @@
             this.SceneType = sceneType;
             this.SceneType = sceneType;
             this.Name = name;
             this.Name = name;
             this.IsCreate = true;
             this.IsCreate = true;
-            
+            this.IsRegister = true;
+            this.Parent = parent;
+            this.Domain = this;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
         }
 
 
-        public Scene(long id, long instanceId, int zone, SceneType sceneType, string name)
+        public Scene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent)
         {
         {
             this.Id = id;
             this.Id = id;
             this.InstanceId = instanceId;
             this.InstanceId = instanceId;
@@ -38,7 +40,9 @@
             this.SceneType = sceneType;
             this.SceneType = sceneType;
             this.Name = name;
             this.Name = name;
             this.IsCreate = true;
             this.IsCreate = true;
-            
+            this.IsRegister = true;
+            this.Parent = parent;
+            this.Domain = this;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
         }
 
 

+ 7 - 10
Unity/Assets/Model/Core/Object/Entity.cs

@@ -31,7 +31,7 @@ namespace ET
         public long InstanceId
         public long InstanceId
         {
         {
             get;
             get;
-            set;
+            protected set;
         }
         }
 
 
         protected Entity()
         protected Entity()
@@ -44,7 +44,7 @@ namespace ET
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]
         [BsonIgnore]
         [BsonIgnore]
-        public bool IsFromPool
+        private bool IsFromPool
         {
         {
             get => (this.status & EntityStatus.IsFromPool) == EntityStatus.IsFromPool;
             get => (this.status & EntityStatus.IsFromPool) == EntityStatus.IsFromPool;
             set
             set
@@ -62,7 +62,7 @@ namespace ET
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]
         [BsonIgnore]
         [BsonIgnore]
-        public bool IsRegister
+        protected bool IsRegister
         {
         {
             get => (this.status & EntityStatus.IsRegister) == EntityStatus.IsRegister;
             get => (this.status & EntityStatus.IsRegister) == EntityStatus.IsRegister;
             set
             set
@@ -105,7 +105,7 @@ namespace ET
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]
         [BsonIgnore]
         [BsonIgnore]
-        public bool IsCreate
+        protected bool IsCreate
         {
         {
             get => (this.status & EntityStatus.IsCreate) == EntityStatus.IsCreate;
             get => (this.status & EntityStatus.IsCreate) == EntityStatus.IsCreate;
             set
             set
@@ -298,7 +298,7 @@ namespace ET
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]
         [BsonIgnore]
         [BsonIgnore]
-        public Dictionary<long, Entity> Children => this.children ?? (this.children = childrenPool.Fetch());
+        public Dictionary<long, Entity> Children => this.children ??= childrenPool.Fetch();
 
 
         private void AddChild(Entity entity)
         private void AddChild(Entity entity)
         {
         {
@@ -331,10 +331,7 @@ namespace ET
                 return;
                 return;
             }
             }
 
 
-            if (this.childrenDB == null)
-            {
-                this.childrenDB = hashSetPool.Fetch();
-            }
+            this.childrenDB ??= hashSetPool.Fetch();
 
 
             this.childrenDB.Add(entity);
             this.childrenDB.Add(entity);
         }
         }
@@ -374,7 +371,7 @@ namespace ET
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]
         [BsonIgnore]
         [BsonIgnore]
-        public Dictionary<Type, Entity> Components => this.components ?? (this.components = dictPool.Fetch());
+        public Dictionary<Type, Entity> Components => this.components ??= dictPool.Fetch();
 
 
         public override void Dispose()
         public override void Dispose()
         {
         {