示例#1
0
        public override void OnInspectorGUI()
        {
            if (FindObjectsOfType <BehaviourManager>().Length > 1)
            {
                EditorGUILayout.HelpBox("存在多个激活的BehaviourManager,请删除或失活其它", MessageType.Error);
                return;
            }
            serializedObject.UpdateIfRequiredOrScript();
            EditorGUI.BeginChangeCheck();
            bool shouldDisable = Application.isPlaying && !PrefabUtility.IsPartOfAnyPrefab(target);

            EditorGUI.BeginDisabledGroup(shouldDisable);
            var globalBef = globalVariables.objectReferenceValue;

            if (shouldDisable)
            {
                EditorGUILayout.PropertyField(globalVariables, new GUIContent("全局变量"));
            }
            else
            {
                globalDrawer.DoLayoutDraw();
            }
            if (!globalVariables.objectReferenceValue && ZetanUtility.Editor.LoadAsset <GlobalVariables>() == null)
            {
                if (GUILayout.Button("新建"))
                {
                    globalVariables.objectReferenceValue = ZetanUtility.Editor.SaveFilePanel(CreateInstance <GlobalVariables>, "global variables");
                }
            }
            EditorGUI.EndDisabledGroup();
            if (globalVariables.objectReferenceValue != globalBef)
            {
                InitGlobal();
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            if (globalVariables.objectReferenceValue)
            {
                serializedObject.UpdateIfRequiredOrScript();

                showGlobal.target = EditorGUILayout.Foldout(serializedVariables.isExpanded, "全局变量列表", true);;
                if (EditorGUILayout.BeginFadeGroup(showGlobal.faded))
                {
                    variableList.DoLayoutList();
                }
                EditorGUILayout.EndFadeGroup();
                if (!Application.isPlaying && !ZetanUtility.IsPrefab((target as BehaviourManager).gameObject))
                {
                    showPreset.target = EditorGUILayout.Foldout(presetVariables.isExpanded, "变量预设列表", true);
                    if (EditorGUILayout.BeginFadeGroup(showPreset.faded))
                    {
                        presetVariableList.DoLayoutList();
                    }
                    EditorGUILayout.EndFadeGroup();
                }
                serializedObject.ApplyModifiedProperties();
            }
        }
 public override void OnInspectorGUI()
 {
     serializedObject.UpdateIfRequiredOrScript();
     EditorGUI.BeginChangeCheck();
     EditorGUILayout.PropertyField(_name);
     EditorGUILayout.PropertyField(description);
     if (EditorGUI.EndChangeCheck())
     {
         serializedObject.ApplyModifiedProperties();
     }
     serializedObject.UpdateIfRequiredOrScript();
     variableList.DoLayoutList();
     serializedObject.ApplyModifiedProperties();
 }
示例#3
0
 private void DrawVariables()
 {
     if (serializedObject == null || serializedObject.targetObject == null)
     {
         if (!showShared)
         {
             if (GUILayout.Button("新建"))
             {
                 CreateGlobalVariables("global variables");
             }
         }
         else
         {
             EditorGUILayout.HelpBox("没有编辑中的行为树", MessageType.Info);
         }
         return;
     }
     if (serializedObject.targetObject)
     {
         serializedObject.UpdateIfRequiredOrScript();
         variableList?.DoLayoutList();
         serializedObject.ApplyModifiedProperties();
     }
 }
 public override void OnInspectorGUI()
 {
     serializedObject.UpdateIfRequiredOrScript();
     variableList.DoLayoutList();
     serializedObject.ApplyModifiedProperties();
 }
示例#5
0
        public override void OnInspectorGUI()
        {
            if (target is RuntimeBehaviourExecutor exe)
            {
                if (PrefabUtility.IsPartOfAnyPrefab(exe))
                {
                    EditorGUILayout.HelpBox("不能在预制件使用RuntimeBehaviourExecutor", MessageType.Error);
                    return;
                }
                else
                {
                    EditorGUILayout.HelpBox("只在本场景生效,若要制作预制件,请使用BehaviourExecutor", MessageType.Info);
                }
            }
            serializedObject.UpdateIfRequiredOrScript();
            EditorGUI.BeginChangeCheck();
            var hasTreeBef = behaviour.objectReferenceValue;

            if (target is not RuntimeBehaviourExecutor)
            {
                bool shouldDisable = Application.isPlaying && !PrefabUtility.IsPartOfAnyPrefab(target);
                EditorGUI.BeginDisabledGroup(shouldDisable);
                if (shouldDisable)
                {
                    EditorGUILayout.PropertyField(behaviour, new GUIContent("行为树"));
                }
                else
                {
                    treeDrawer.DoLayoutDraw();
                }
                EditorGUI.EndDisabledGroup();
            }
            if (behaviour.objectReferenceValue != hasTreeBef)
            {
                InitTree();
            }
            if (behaviour.objectReferenceValue)
            {
                if (GUILayout.Button("编辑"))
                {
                    BehaviourTreeEditor.CreateWindow(target as BehaviourExecutor);
                }
                serializedTree.UpdateIfRequiredOrScript();
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(serializedTree.FindProperty("_name"));
                EditorGUILayout.PropertyField(serializedTree.FindProperty("description"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedTree.ApplyModifiedProperties();
                }
            }
            else
            {
                if (GUILayout.Button("新建"))
                {
                    BehaviourTree tree = ZetanUtility.Editor.SaveFilePanel(CreateInstance <BehaviourTree>, "new behaviour tree");
                    if (tree)
                    {
                        behaviour.objectReferenceValue = tree;
                        InitTree();
                        treeDrawer = new ObjectSelectionDrawer <BehaviourTree>(behaviour, string.Empty, string.Empty, "行为树");
                        EditorApplication.delayCall += delegate { BehaviourTreeEditor.CreateWindow(target as BehaviourExecutor); };
                    }
                }
            }
            EditorGUILayout.PropertyField(frequency, new GUIContent("执行频率"));
            if (frequency.enumValueIndex == (int)BehaviourExecutor.Frequency.FixedTime)
            {
                EditorGUILayout.PropertyField(interval, new GUIContent("间隔(秒)"));
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(startOnStart, new GUIContent("开始时执行"));
            EditorGUILayout.PropertyField(restartOnComplete, new GUIContent("完成时重启"));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(resetOnRestart, new GUIContent("重启时重置"));
            EditorGUILayout.PropertyField(gizmos, new GUIContent("显示Gizmos"));
            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            if (behaviour.objectReferenceValue)
            {
                serializedTree.UpdateIfRequiredOrScript();
                showList.target = EditorGUILayout.Foldout(serializedVariables.isExpanded, "行为树共享变量", true);
                if (EditorGUILayout.BeginFadeGroup(showList.faded))
                {
                    variableList.DoLayoutList();
                }
                EditorGUILayout.EndFadeGroup();
                if (target is not RuntimeBehaviourExecutor && !Application.isPlaying && !ZetanUtility.IsPrefab((target as BehaviourExecutor).gameObject))
                {
                    showPreset.target = EditorGUILayout.Foldout(presetVariables.isExpanded, "变量预设列表", true);
                    if (EditorGUILayout.BeginFadeGroup(showPreset.faded))
                    {
                        presetVariableList.DoLayoutList();
                    }
                    EditorGUILayout.EndFadeGroup();
                }
                serializedTree.ApplyModifiedProperties();
            }
        }