Просмотр исходного кода

Hierarchy增加Entity属性展示,能看到客户端跟服务端的Entity,以及成员变量,需要开启ENABLE_CODE宏,并且执行ET目录下的LinkCode脚本

tanghai 3 лет назад
Родитель
Сommit
8bc335be61

+ 10 - 0
Codes/Model/Share/Module/Unit/Unit.cs

@@ -52,5 +52,15 @@ namespace ET
         }
 
         private string DebuggerDisplay => this.Config.Name;
+        
+#if ENABLE_CODES
+        protected override string ViewGoName
+        {
+            get
+            {
+                return $"{this.GetType().Name} ({this.Id})";
+            }
+        }
+#endif
     }
 }

+ 13 - 5
Unity/Assets/Scripts/Core/Entity/Scene.cs

@@ -31,9 +31,9 @@ namespace ET
             this.Name = name;
             this.IsCreated = true;
             this.IsNew = true;
-            this.IsRegister = true;
             this.Parent = parent;
             this.Domain = this;
+            this.IsRegister = true;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
 
@@ -46,9 +46,9 @@ namespace ET
             this.Name = name;
             this.IsCreated = true;
             this.IsNew = true;
-            this.IsRegister = true;
             this.Parent = parent;
             this.Domain = this;
+            this.IsRegister = true;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
 
@@ -90,7 +90,7 @@ namespace ET
             {
                 if (value == null)
                 {
-                    this.parent = this;
+                    //this.parent = this;
                     return;
                 }
 
@@ -98,7 +98,15 @@ namespace ET
                 this.parent.Children.Add(this.Id, this);
             }
         }
-
-        private string DebuggerDisplay => this.SceneType.ToString();
+        
+#if ENABLE_CODES
+        protected override string ViewGoName
+        {
+            get
+            {
+                return $"{this.GetType().Name} ({this.SceneType})";    
+            }
+        }
+#endif
     }
 }

+ 4 - 2
Unity/Assets/Scripts/Mono/MonoBehaviour/ComponentView.cs → Unity/Assets/Scripts/Core/Object/ComponentView.cs

@@ -1,13 +1,15 @@
+#if ENABLE_CODES
 using UnityEngine;
 
 namespace ET
 {
     public class ComponentView: MonoBehaviour
     {
-        public object Component
+        public Entity Component
         {
             get;
             set;
         }
     }
-}
+}
+#endif

+ 1 - 1
Unity/Assets/Scripts/Mono/MonoBehaviour/ComponentView.cs.meta → Unity/Assets/Scripts/Core/Object/ComponentView.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: b158ec37c4e3b544094059f3d54a07ea
+guid: cc2f1b66f9123cf4aa34a74ea30a95d5
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 28 - 0
Unity/Assets/Scripts/Core/Object/Entity.cs

@@ -18,6 +18,10 @@ namespace ET
 
     public partial class Entity: DisposeObject
     {
+#if ENABLE_CODES
+        private UnityEngine.GameObject viewGO;
+#endif
+        
         [IgnoreDataMember]
         [BsonIgnore]
         public long InstanceId
@@ -74,8 +78,32 @@ namespace ET
                 }
 
                 EventSystem.Instance.RegisterSystem(this, value);
+                
+#if ENABLE_CODES
+                if (value)
+                {
+                    this.viewGO = new UnityEngine.GameObject(this.ViewGoName);
+                    this.viewGO.AddComponent<ComponentView>().Component = this;
+                    this.viewGO.transform.SetParent(this.Parent == null? 
+                            UnityEngine.GameObject.Find("Global").transform : this.Parent.viewGO.transform);
+                }
+                else
+                {
+                    UnityEngine.Object.Destroy(this.viewGO);
+                }
+#endif
+            }
+        }
+        
+#if ENABLE_CODES
+        protected virtual string ViewGoName
+        {
+            get
+            {
+                return this.GetType().Name;    
             }
         }
+#endif
 
         [IgnoreDataMember]
         [BsonIgnore]

+ 14 - 1
Unity/Assets/Scripts/Editor/BuildEditor/BuildEditor.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -118,16 +119,28 @@ namespace ET
 			
 			if (GUILayout.Button("BuildCode"))
 			{
+				if (Define.EnableCodes)
+				{
+					throw new Exception("now in ENABLE_CODES mode, do not need Build!");
+				}
 				BuildAssemblieEditor.BuildCode(this.codeOptimization, globalConfig);
 			}
 			
 			if (GUILayout.Button("BuildModel"))
 			{
+				if (Define.EnableCodes)
+				{
+					throw new Exception("now in ENABLE_CODES mode, do not need Build!");
+				}
 				BuildAssemblieEditor.BuildModel(this.codeOptimization, globalConfig);
 			}
 			
 			if (GUILayout.Button("BuildHotfix"))
 			{
+				if (Define.EnableCodes)
+				{
+					throw new Exception("now in ENABLE_CODES mode, do not need Build!");
+				}
 				BuildAssemblieEditor.BuildHotfix(this.codeOptimization, globalConfig);
 			}
 			

+ 13 - 7
Unity/Assets/Scripts/Editor/ComponentViewEditor/ComponentViewEditor.cs

@@ -1,3 +1,4 @@
+#if ENABLE_CODES
 using System;
 using System.Collections.Generic;
 using System.Reflection;
@@ -13,7 +14,7 @@ namespace ET
         public override void OnInspectorGUI()
         {
             ComponentView componentView = (ComponentView) target;
-            object component = componentView.Component;
+            Entity component = componentView.Component;
             ComponentViewHelper.Draw(component);
         }
     }
@@ -37,14 +38,18 @@ namespace ET
             }
         }
         
-        public static void Draw(object obj)
+        public static void Draw(Entity entity)
         {
             try
             {
-                FieldInfo[] fields = obj.GetType()
+                FieldInfo[] fields = entity.GetType()
                         .GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
 
                 EditorGUILayout.BeginVertical();
+                
+                EditorGUILayout.LongField("InstanceId: ", entity.InstanceId);
+                
+                EditorGUILayout.LongField("Id: ", entity.Id);
 
                 foreach (FieldInfo fieldInfo in fields)
                 {
@@ -59,7 +64,7 @@ namespace ET
                         continue;
                     }
 
-                    object value = fieldInfo.GetValue(obj);
+                    object value = fieldInfo.GetValue(entity);
 
                     foreach (ITypeDrawer typeDrawer in typeDrawers)
                     {
@@ -74,7 +79,7 @@ namespace ET
                             fieldName = fieldName.Substring(1, fieldName.Length - 17);
                         }
                         value = typeDrawer.DrawAndGetNewValue(type, fieldName, value, null);
-                        fieldInfo.SetValue(obj, value);
+                        fieldInfo.SetValue(entity, value);
                         break;
                     }
                 }
@@ -83,8 +88,9 @@ namespace ET
             }
             catch (Exception e)
             {
-                UnityEngine.Debug.Log($"component view error: {obj.GetType().FullName} {e}");
+                UnityEngine.Debug.Log($"component view error: {entity.GetType().FullName} {e}");
             }
         }
     }
-}
+}
+#endif

+ 3 - 1
Unity/Assets/Scripts/Editor/ComponentViewEditor/Tree/EntityTreeView.cs

@@ -1,3 +1,4 @@
+#if ENABLE_CODES
 using System.Collections.Generic;
 using UnityEditor;
 using UnityEditor.IMGUI.Controls;
@@ -98,4 +99,5 @@ namespace ET
             Selection.activeObject            = EntityTreeWindow.VIEW_MONO;
         }
     }
-}
+}
+#endif

+ 3 - 1
Unity/Assets/Scripts/Editor/ComponentViewEditor/Tree/EntityTreeWindow.cs

@@ -1,3 +1,4 @@
+#if ENABLE_CODES
 using UnityEditor;
 using UnityEditor.IMGUI.Controls;
 using UnityEngine;
@@ -104,4 +105,5 @@ namespace ET
             GUILayout.EndArea();
         }
     }
-}
+}
+#endif

+ 31 - 0
Unity/Assets/Scripts/Editor/ComponentViewEditor/TypeDrawer/DictionaryIntLongTypeDrawer.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using UnityEditor;
+
+namespace ET
+{
+    [TypeDrawer]
+    public class DictionaryIntLongTypeDrawer: ITypeDrawer
+    {
+        public bool HandlesType(Type type)
+        {
+            return type == typeof (Dictionary<int, long>);
+        }
+
+        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
+        {
+            Dictionary<int, long> dictionary = value as Dictionary<int, long>;
+
+            EditorGUILayout.LabelField($"{memberName}:");
+            foreach ((int k, long v) in dictionary)
+            {
+                if (v == 0)
+                {
+                    continue;
+                }
+                EditorGUILayout.LongField($"    {k} :", v);
+            }
+            return value;
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Editor/ComponentViewEditor/TypeDrawer/DictionaryIntLongTypeDrawer.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b4f3ad48c3023dd4f9dbe2a6145be126
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Scripts/Editor/Helper/DockDefine.cs

@@ -5,6 +5,6 @@ namespace ET
 {
     public static class DockDefine
     {
-        public static Type[] Types = { typeof (BuildEditor), typeof (ServerCommandLineEditor), typeof (EntityTreeWindow) };
+        public static Type[] Types = { typeof (BuildEditor), typeof (ServerCommandLineEditor) };
     }
 }

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -750,7 +750,7 @@ PlayerSettings:
   scriptingDefineSymbols:
     Android: NETSTANDARD2_0;UNITY
     Server: NETSTANDARD2_0;UNITY
-    Standalone: NETSTANDARD2_0;UNITY
+    Standalone: NETSTANDARD2_0;UNITY;ENABLE_CODES
     WebGL: NETSTANDARD2_0;UNITY
     iPhone: NETSTANDARD2_0;UNITY
   additionalCompilerArguments: {}

Разница между файлами не показана из-за своего большого размера
+ 1 - 2
Unity/Unity.Codes.csproj


Некоторые файлы не были показаны из-за большого количества измененных файлов