Ejemplo n.º 1
0
        private void DrawNodeInspector()
        {
            GUI.DrawTexture(new Rect(position.width - BtConst.RightInspectWidth - 5, 0,
                                     BtConst.RightInspectWidth + 5, 500), BtNodeStyle.NodeEditorBg);

            EditorGUILayout.BeginHorizontal();
            {
                IsDebug = GUILayout.Toggle(IsDebug, "是否调试", GUILayout.MaxWidth(80));
                //IsAutoAlign = GUILayout.Toggle(IsAutoAlign, "自动对齐", GUILayout.MaxWidth(80));
                //IsLockAxisY = GUILayout.Toggle(IsLockAxisY, "锁定Y轴", GUILayout.MaxWidth(80));
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(SPACE_VALUE);
            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("JsonBT目录"))
                {
                    System.Diagnostics.Process.Start(BtHelper.jsonPath);
                }

                if (GUILayout.Button("LuaBT目录"))
                {
                    System.Diagnostics.Process.Start(BtHelper.behaviorPath);
                }

                if (GUILayout.Button("Node配置"))
                {
                    BTEditorOption.ShowWindow();
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(SPACE_VALUE);
            if (GUILayout.Button("加载行为树"))
            {
                LoadBehaviorTree();
            }

            if (mAllShowJsons != null && mAllShowJsons.Length > 0 && mLastSelectJson != mCurSelectJson)
            {
                mLastSelectJson = mCurSelectJson;
                var fileName = mAllShowJsons[mCurSelectJson];
                var file     = Path.Combine(BtHelper.jsonPath, $"{fileName}.json");
                mBehaviourTree = BtHelper.LoadBehaviorTree(file);
                if (mBehaviourTree == null)
                {
                    Debug.LogErrorFormat("读取行为树失败, {0}", file);
                    mBehaviourTree = new BehaviourTree(DEFAULE_BT_NAME);
                }
            }

            if (GUILayout.Button(DEFAULE_BT_NAME))
            {
                mBehaviourTree = new BehaviourTree(DEFAULE_BT_NAME);
            }

            GUILayout.Space(SPACE_VALUE);
            EditorGUIUtility.labelWidth = 40;
            if (mAllShowJsons != null && mAllShowJsons.Length > 0)
            {
                mCurSelectJson = EditorGUILayout.Popup("行为树:", mCurSelectJson, mAllShowJsons);
            }
            EditorGUIUtility.labelWidth = 60;

            GUILayout.Space(SPACE_VALUE);
            EditorGUILayout.BeginVertical("Box");
            {
                EditorGUILayout.LabelField("行为树数据");
                if (mBehaviourTree != null)
                {
                    mBehaviourTree.Name = EditorGUILayout.TextField("行为树名:", mBehaviourTree.Name);
                }

                GUI.color = Color.green;
                if (GUILayout.Button("保存行为树"))
                {
                    if (mBehaviourTree != null && mBehaviourTree.BrokenNodeDict.Count > 0)
                    {
                        EditorUtility.DisplayDialog("提示", "有节点未连上", "确定");
                    }
                    else
                    {
                        BtHelper.SaveBTData(mBehaviourTree);
                    }
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(SPACE_VALUE);
            var node = Window.CurSelectNode;

            if (node != null)
            {
                var data = node.Data;
                EditorGUILayout.BeginHorizontal();

                if (mIsSettingNode)
                {
                    EditorGUILayout.LabelField("节点说明", GUILayout.MaxWidth(50));
                    data.desc = EditorGUILayout.TextArea(data.desc, GUILayout.MaxWidth(BtConst.RightInspectWidth));
                }
                else
                {
                    EditorGUILayout.HelpBox(data.desc, MessageType.Info);
                }

                if (GUILayout.Button(mIsSettingNode ? "ok" : "set", GUILayout.MaxWidth(30)))
                {
                    mIsSettingNode = !mIsSettingNode;
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(SPACE_VALUE);
                EditorGUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("节点数据");
                    data.displayName = EditorGUILayout.TextField("显示名:", data.displayName);
                    EditorGUILayout.LabelField("节点名:", data.name);
                    if (node.Guid != mLastNodeGuid)
                    {
                        mLastNodeGuid = node.Guid;
                        mChangeDict.Clear();
                    }

                    DrawDataInspector(data);
                }
                EditorGUILayout.EndVertical();
            }
        }