소스 검색

修复行为树编辑器一些错误

tanghai 9 년 전
부모
커밋
1e01128793

+ 16 - 6
Unity/Assets/Editor/BehaviorTreeEditor/BehaviorDesignerUtility.cs

@@ -1,4 +1,6 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using Base;
 using UnityEditor;
 using UnityEngine;
 
@@ -12,15 +14,23 @@ namespace MyEditor
 
 		public static Texture2D GetTexture(string imageName)
 		{
-			if (!mTextureDict.ContainsKey(imageName))
+			try
 			{
-				Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(ImagePathName + imageName + ".png");
-				if (tex != null)
+				if (!mTextureDict.ContainsKey(imageName))
 				{
-					mTextureDict.Add(imageName, tex);
+					Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(ImagePathName + imageName + ".png");
+					if (tex != null)
+					{
+						mTextureDict.Add(imageName, tex);
+					}
 				}
+				return mTextureDict[imageName];
 			}
-			return mTextureDict[imageName];
+			catch (Exception e)
+			{
+				throw new Exception($"无法找到资源: {imageName}", e);
+			}
+
 		}
 
 		public static void DrawConnection(Vector2 src, Vector2 dst)

+ 2 - 1
Unity/Assets/Editor/BehaviorTreeEditor/BehaviorDesignerWindow.cs

@@ -48,9 +48,10 @@ namespace MyEditor
         }
 		public static void ShowWindow()
 		{
-            BehaviorDesignerWindow target = GetWindow<BehaviorDesignerWindow>("行为树编辑器", false);
+			BehaviorDesignerWindow target = GetWindow<BehaviorDesignerWindow>("行为树编辑器", false);
             target.minSize = new Vector2(600f, 500f);
         }
+
         public void ShowSubWin(Vector2 pos,SubWinType subWinType)
         {
             mShowSubWin = true;

+ 3 - 2
Unity/Assets/Editor/BehaviorTreeEditor/BehaviorManager.cs

@@ -101,7 +101,9 @@ namespace MyEditor
          
         public void NewLoadData()
         {
-            LoadNodeTypeProto();
+			Game.EntityEventManager.Register("Controller", DllHelper.GetController());
+
+			LoadNodeTypeProto();
             NewLoadPrefabTree();
             FilterClassify();
         }
@@ -426,7 +428,6 @@ namespace MyEditor
                 return;
             }
             selectNodeName = "";
-            ExportNodeTypeConfig.LoadAssembly();
             CurTreeGO = go;
             NewLoadData();
             BehaviorDesignerWindow.ShowWindow();

+ 2 - 3
Unity/Assets/Editor/BehaviorTreeEditor/BehaviorTreeConfigExtension.cs

@@ -34,14 +34,13 @@ namespace Model
         }
         private static BehaviorNodeConfig CreateNodeConfig(this BehaviorTreeConfig treeConfig, string name)
         {
-            ExportNodeTypeConfig.LoadAssembly();
             ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);
             GameObject go = new GameObject();
             go.name = name;
             go.transform.parent = treeConfig.gameObject.transform;
             BehaviorNodeConfig node = go.AddComponent<BehaviorNodeConfig>();
-            ((UnityEngine.Object) node).name = name;
-            //node.describe = proto.describe;
+            node.name = name;
+            node.describe = proto.describe;
 
             foreach (var args in proto.new_args_desc)
             {

+ 3 - 1
Unity/Assets/Editor/BehaviorTreeEditor/BehaviorTreeOperateUtility.cs

@@ -103,7 +103,9 @@ namespace MyEditor
             GameObject prefab = null;
             try
             {
-                GameObject go = new GameObject();
+				Game.EntityEventManager.Register("Controller", DllHelper.GetController());
+
+				GameObject go = new GameObject();
                 BehaviorTreeConfig newConfig = go.AddComponent<BehaviorTreeConfig>();
                 BehaviorNodeConfig root = newConfig.AddRootNode(rootNodeName);
 

+ 1 - 10
Unity/Assets/Editor/BehaviorTreeEditor/ExportNodeTypeConfig.cs

@@ -51,15 +51,6 @@ namespace MyEditor
 			return Game.EntityEventManager.GetAssembly("Controller");
 		}
 
-
-		public static Assembly LoadAssembly()
-		{
-			AssetDatabase.Refresh();
-			Assembly assembly = DllHelper.GetController();
-			Game.EntityEventManager.Register("Controller", assembly);
-			return assembly;
-		}
-
 		public static ClientNodeTypeProto GetNodeTypeProtoFromDll(string name)
 		{
 			Type type = GetNodeType(name);
@@ -281,7 +272,7 @@ namespace MyEditor
 			Type nodeType = assembly.GetType("Controller." + nodeName);
 			if (nodeType == null)
 			{
-				Log.Error(string.Format("不存在此节点:{0}", nodeName));
+				Log.Error($"不存在此节点:{nodeName}");
 				return null;
 			}
 			return nodeType;

+ 2 - 0
Unity/Assets/Editor/EditorInit.cs

@@ -11,6 +11,8 @@ namespace MyEditor
 	{
 		static EditorInit()
 		{
+			Game.EntityEventManager.Register("Model", typeof(Game).Assembly);
+			Game.EntityEventManager.Register("Editor", typeof(EditorInit).Assembly);
 		}
 	}
 }

+ 13 - 12
Unity/Assets/Scripts/Entity/Game.cs

@@ -12,22 +12,15 @@ namespace Model
 
 		private static Scene scene;
 
-		static Game()
-		{
-			disposers = new HashSet<Disposer>();
-
-			entityEventManager = new EntityEventManager();
-			entityEventManager.Register("Model", typeof(Game).Assembly);
-			entityEventManager.Register("Controller", DllHelper.GetController());
-
-			scene = new Scene();
-			scene.AddComponent<EventComponent>();
-		}
-
 		public static Scene Scene
 		{
 			get
 			{
+				if (scene == null)
+				{
+					scene = new Scene();
+					scene.AddComponent<EventComponent>();
+				}
 				return scene;
 			}
 		}
@@ -36,6 +29,10 @@ namespace Model
 		{
 			get
 			{
+				if (disposers == null)
+				{
+					disposers = new HashSet<Disposer>();
+				}
 				return disposers;
 			}
 		}
@@ -60,6 +57,10 @@ namespace Model
 		{
 			get
 			{
+				if (entityEventManager == null)
+				{
+					entityEventManager = new EntityEventManager();
+				}
 				return entityEventManager;
 			}
 			set

+ 1 - 0
Unity/Assets/Scripts/Helper/DllHelper.cs

@@ -1,4 +1,5 @@
 using System.Reflection;
+using Base;
 using UnityEngine;
 
 namespace Model

+ 0 - 9
Unity/Assets/Scripts/ReferenceCollector.cs

@@ -106,15 +106,6 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
         {
             return null;
         }
-        if (typeof(T) == typeof(GameObject))
-        {
-            return dictGo as T;
-        }
-        var go = dictGo as GameObject;
-        if (go != null)
-        {
-            return (dictGo as GameObject).GetComponent<T>();
-        }
         return dictGo as T;
     }
 

+ 9 - 4
Unity/Unity.Editor.csproj

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -13,11 +13,13 @@
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
-    <CompilerResponseFile></CompilerResponseFile>
+    <CompilerResponseFile>
+    </CompilerResponseFile>
     <UnityProjectType>Editor:5</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
     <UnityVersion>5.4.3f1</UnityVersion>
-    <RootNamespace></RootNamespace>
+    <RootNamespace>
+    </RootNamespace>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -157,6 +159,9 @@
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml" />
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Assets\Editor\MenuEditor\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
-</Project>
+</Project>