ソースを参照

1.消除Type.Name的gc,Type.FullName没有gc
2.消除移动中GameObject.transform的gc

tanghai 2 年 前
コミット
1c45840ba5

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Session/NetInnerComponentOnReadEvent.cs

@@ -34,7 +34,7 @@ namespace ET.Server
             }
             catch (Exception e)
             {
-                Log.Error($"InnerMessageDispatcher error: {args.Message.GetType().Name}\n{e}");
+                Log.Error($"InnerMessageDispatcher error: {args.Message.GetType().FullName}\n{e}");
             }
 
             await ETTask.CompletedTask;

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/AMActorHandler.cs

@@ -17,7 +17,7 @@ namespace ET.Server
 
             if (entity is not E e)
             {
-                Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Message).Name}");
+                Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).Name} --{typeof (Message).FullName}");
                 return;
             }
 

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/AMActorRpcHandler.cs

@@ -19,7 +19,7 @@ namespace ET.Server
 
                 if (entity is not E ee)
                 {
-                    Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Request).Name}");
+                    Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).FullName} --{typeof (Request).FullName}");
                     return;
                 }
 

+ 2 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorHandleHelper.cs

@@ -48,7 +48,7 @@ namespace ET.Server
             MailBoxComponent mailBoxComponent = entity.GetComponent<MailBoxComponent>();
             if (mailBoxComponent == null)
             {
-                Log.Warning($"actor not found mailbox: {entity.GetType().Name} {realActorId} {iActorRequest}");
+                Log.Warning($"actor not found mailbox: {entity.GetType().FullName} {realActorId} {iActorRequest}");
                 IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
                 Reply(fromProcess, response);
                 return;
@@ -101,7 +101,7 @@ namespace ET.Server
             MailBoxComponent mailBoxComponent = entity.GetComponent<MailBoxComponent>();
             if (mailBoxComponent == null)
             {
-                Log.Error($"actor not found mailbox: {entity.GetType().Name} {realActorId} {iActorMessage}");
+                Log.Error($"actor not found mailbox: {entity.GetType().FullName} {realActorId} {iActorMessage}");
                 return;
             }
 

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs

@@ -98,7 +98,7 @@ namespace ET.Server
             List<ActorMessageDispatcherInfo> list;
             if (!self.ActorMessageHandlers.TryGetValue(message.GetType(), out list))
             {
-                throw new Exception($"not found message handler: {message} {entity.GetType().Name}");
+                throw new Exception($"not found message handler: {message} {entity.GetType().FullName}");
             }
 
             SceneType sceneType = entity.Domain.SceneType;

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/ActorLocation/AMActorLocationHandler.cs

@@ -17,7 +17,7 @@ namespace ET.Server
 
             if (entity is not E e)
             {
-                Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Message).Name}");
+                Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).FullName} --{typeof (Message).FullName}");
                 return;
             }
             

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/ActorLocation/AMActorLocationRpcHandler.cs

@@ -19,7 +19,7 @@ namespace ET.Server
 
                 if (entity is not E ee)
                 {
-                    Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Request).Name}");
+                    Log.Error($"Actor类型转换错误: {entity.GetType().FullName} to {typeof (E).FullName} --{typeof (Request).FullName}");
                     return;
                 }
 

+ 2 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Demo/Unit/ChangePosition_SyncGameObjectPos.cs

@@ -13,7 +13,8 @@ namespace ET.Client
             {
                 return;
             }
-            Transform transform = gameObjectComponent.GameObject.transform;
+
+            Transform transform = gameObjectComponent.Transform;
             transform.position = unit.Position;
             await ETTask.CompletedTask;
         }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/AMHandler.cs

@@ -11,7 +11,7 @@ namespace ET
             Message message = msg as Message;
             if (message == null)
             {
-                Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof (Message).Name}");
+                Log.Error($"消息类型转换错误: {msg.GetType().FullName} to {typeof (Message).Name}");
                 return;
             }
 

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/OpcodeTypeComponent.cs

@@ -77,7 +77,7 @@ namespace ET
         {
             if (!self.requestResponse.TryGetValue(request, out Type response))
             {
-                throw new Exception($"not found response type, request type: {request.GetType().Name}");
+                throw new Exception($"not found response type, request type: {request.GetType().FullName}");
             }
             return response;
         }

+ 16 - 1
Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Unit/GameObjectComponent.cs

@@ -5,6 +5,21 @@ namespace ET.Client
     [ComponentOf(typeof(Unit))]
     public class GameObjectComponent: Entity, IAwake, IDestroy
     {
-        public GameObject GameObject { get; set; }
+        private GameObject gameObject;
+
+        public GameObject GameObject
+        {
+            get
+            {
+                return this.gameObject;
+            }
+            set
+            {
+                this.gameObject = value;
+                this.Transform = value.transform;
+            }
+        }
+
+        public Transform Transform { get; private set; }
     }
 }

+ 20 - 20
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -173,18 +173,18 @@ namespace ET
             {
                 if (value == null)
                 {
-                    throw new Exception($"cant set parent null: {this.GetType().Name}");
+                    throw new Exception($"cant set parent null: {this.GetType().FullName}");
                 }
 
                 if (value == this)
                 {
-                    throw new Exception($"cant set parent self: {this.GetType().Name}");
+                    throw new Exception($"cant set parent self: {this.GetType().FullName}");
                 }
 
                 // 严格限制parent必须要有domain,也就是说parent必须在数据树上面
                 if (value.Domain == null)
                 {
-                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().Name} {value.GetType().Name}");
+                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().FullName} {value.GetType().FullName}");
                 }
 
                 if (this.parent != null) // 之前有parent
@@ -192,7 +192,7 @@ namespace ET
                     // parent相同,不设置
                     if (this.parent == value)
                     {
-                        Log.Error($"重复设置了Parent: {this.GetType().Name} parent: {this.parent.GetType().Name}");
+                        Log.Error($"重复设置了Parent: {this.GetType().FullName} parent: {this.parent.GetType().FullName}");
                         return;
                     }
 
@@ -229,18 +229,18 @@ namespace ET
             {
                 if (value == null)
                 {
-                    throw new Exception($"cant set parent null: {this.GetType().Name}");
+                    throw new Exception($"cant set parent null: {this.GetType().FullName}");
                 }
 
                 if (value == this)
                 {
-                    throw new Exception($"cant set parent self: {this.GetType().Name}");
+                    throw new Exception($"cant set parent self: {this.GetType().FullName}");
                 }
 
                 // 严格限制parent必须要有domain,也就是说parent必须在数据树上面
                 if (value.Domain == null)
                 {
-                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().Name} {value.GetType().Name}");
+                    throw new Exception($"cant set parent because parent domain is null: {this.GetType().FullName} {value.GetType().FullName}");
                 }
 
                 if (this.parent != null) // 之前有parent
@@ -248,7 +248,7 @@ namespace ET
                     // parent相同,不设置
                     if (this.parent == value)
                     {
-                        Log.Error($"重复设置了Parent: {this.GetType().Name} parent: {this.parent.GetType().Name}");
+                        Log.Error($"重复设置了Parent: {this.GetType().FullName} parent: {this.parent.GetType().FullName}");
                         return;
                     }
 
@@ -287,7 +287,7 @@ namespace ET
             {
                 if (value == null)
                 {
-                    throw new Exception($"domain cant set null: {this.GetType().Name}");
+                    throw new Exception($"domain cant set null: {this.GetType().FullName}");
                 }
 
                 if (this.domain == value)
@@ -313,7 +313,7 @@ namespace ET
                         foreach (Entity component in this.componentsDB)
                         {
                             component.IsComponent = true;
-                            this.Components.Add(component.GetType().Name, component);
+                            this.Components.Add(component.GetType().FullName, component);
                             component.parent = this;
                         }
                     }
@@ -499,7 +499,7 @@ namespace ET
 
         private void AddToComponents(Entity component)
         {
-            this.Components.Add(component.GetType().Name, component);
+            this.Components.Add(component.GetType().FullName, component);
         }
 
         private void RemoveFromComponents(Entity component)
@@ -509,7 +509,7 @@ namespace ET
                 return;
             }
 
-            this.components.Remove(component.GetType().Name);
+            this.components.Remove(component.GetType().FullName);
 
             if (this.components.Count == 0)
             {
@@ -620,7 +620,7 @@ namespace ET
             }
 
             Entity component;
-            if (!this.components.TryGetValue(typeof (K).Name, out component))
+            if (!this.components.TryGetValue(typeof (K).FullName, out component))
             {
                 return default;
             }
@@ -642,7 +642,7 @@ namespace ET
             }
 
             Entity component;
-            if (!this.components.TryGetValue(type.Name, out component))
+            if (!this.components.TryGetValue(type.FullName, out component))
             {
                 return null;
             }
@@ -678,7 +678,7 @@ namespace ET
         public Entity AddComponent(Entity component)
         {
             Type type = component.GetType();
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
@@ -695,7 +695,7 @@ namespace ET
 
         public Entity AddComponent(Type type, bool isFromPool = false)
         {
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
@@ -716,7 +716,7 @@ namespace ET
         public K AddComponentWithId<K>(long id, bool isFromPool = false) where K : Entity, IAwake, new()
         {
             Type type = typeof (K);
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
@@ -737,7 +737,7 @@ namespace ET
         public K AddComponentWithId<K, P1>(long id, P1 p1, bool isFromPool = false) where K : Entity, IAwake<P1>, new()
         {
             Type type = typeof (K);
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
@@ -758,7 +758,7 @@ namespace ET
         public K AddComponentWithId<K, P1, P2>(long id, P1 p1, P2 p2, bool isFromPool = false) where K : Entity, IAwake<P1, P2>, new()
         {
             Type type = typeof (K);
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
@@ -779,7 +779,7 @@ namespace ET
         public K AddComponentWithId<K, P1, P2, P3>(long id, P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : Entity, IAwake<P1, P2, P3>, new()
         {
             Type type = typeof (K);
-            if (this.components != null && this.components.ContainsKey(type.Name))
+            if (this.components != null && this.components.ContainsKey(type.FullName))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }

+ 2 - 2
Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs

@@ -616,7 +616,7 @@ namespace ET
                     
                 if (!(eventInfo.IEvent is AEvent<S, T> aEvent))
                 {
-                    Log.Error($"event error: {eventInfo.IEvent.GetType().Name}");
+                    Log.Error($"event error: {eventInfo.IEvent.GetType().FullName}");
                     continue;
                 }
 
@@ -652,7 +652,7 @@ namespace ET
                 
                 if (!(eventInfo.IEvent is AEvent<S, T> aEvent))
                 {
-                    Log.Error($"event error: {eventInfo.IEvent.GetType().Name}");
+                    Log.Error($"event error: {eventInfo.IEvent.GetType().FullName}");
                     continue;
                 }
                 

+ 1 - 1
Unity/Assets/Scripts/Core/Module/Network/AService.cs

@@ -21,7 +21,7 @@ namespace ET
             {
                 if (ReferenceEquals(message, this.lastMessageInfo.Message))
                 {
-                    Log.Debug($"message serialize cache: {message.GetType().Name}");
+                    Log.Debug($"message serialize cache: {message.GetType().FullName}");
                     return lastMessageInfo.MemoryStream;
                 }
                 stream = new MemoryBuffer(); // 因为广播,可能MemoryBuffer会用多次,所以不能用对象池

+ 1 - 1
Unity/Assets/Scripts/Loader/Define.cs

@@ -4,7 +4,7 @@
 	{
 		public const string CodeDir = "Assets/Bundles/Code/";
 		public const string BuildOutputDir = "Temp/Bin/Debug";
-
+		
 #if UNITY_EDITOR && !ASYNC
 		public static bool IsAsync = false;
 #else