Пример #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();
            }
        }
Пример #2
0
    public override void OnInspectorGUI()
    {
        if (!CheckEditComplete())
        {
            EditorGUILayout.HelpBox("该任务存在未补全信息。", MessageType.Warning);
        }
        else
        {
            EditorGUILayout.HelpBox("该任务信息已完整。", MessageType.Info);
        }
        barIndex = GUILayout.Toolbar(barIndex, new string[] { "基本", "条件", "奖励", "对话", "目标" });
        EditorGUILayout.Space();
        serializedObject.UpdateIfRequiredOrScript();
        EditorGUI.BeginChangeCheck();
        switch (barIndex)
        {
        case 0:
            #region case 0 基本
            EditorGUILayout.PropertyField(_ID, new GUIContent("识别码"));
            if (string.IsNullOrEmpty(_ID.stringValue) || Quest.IsIDDuplicate(quest, questCache))
            {
                if (!string.IsNullOrEmpty(_ID.stringValue) && Quest.IsIDDuplicate(quest, questCache))
                {
                    EditorGUILayout.HelpBox("此识别码已存在!", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.HelpBox("识别码为空!", MessageType.Error);
                }
                if (GUILayout.Button("自动生成识别码"))
                {
                    _ID.stringValue = Quest.GetAutoID();
                    EditorGUI.FocusTextInControl(null);
                }
            }
            EditorGUILayout.PropertyField(title, new GUIContent("标题"));
            EditorGUILayout.PropertyField(description, new GUIContent("描述"));
            EditorGUILayout.PropertyField(abandonable, new GUIContent("可放弃"));
            EditorGUILayout.PropertyField(questType, new GUIContent("任务类型"));
            if (questType.enumValueIndex == (int)QuestType.Repeated)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(repeatFrequancy, new GUIContent("重复频率"));
                EditorGUILayout.PropertyField(timeUnit, new GUIContent(string.Empty));
                EditorGUILayout.EndHorizontal();
            }
            groupSelector.DoLayoutDraw();
            npcSelector.DoLayoutDraw();
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();                                //这一步一定要在DoLayoutList()之前做!否则无法修改DoList之前的数据
            }
            if (holder)
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                GUI.enabled = false;
                EditorGUILayout.ObjectField(new GUIContent("持有该任务的NPC"), holder, typeof(TalkerInformation), false);
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }
            #endregion
            break;

        case 1:
            #region case 1 条件
            acceptConditionDrawer.DoLayoutDraw();
            #endregion
            break;

        case 2:
            #region case 2 奖励
            EditorGUILayout.HelpBox("目前只设计10个道具奖励。", MessageType.Info);
            rewardDrawer.DoLayoutDraw();
            rewardDrawer.List.displayAdd = rewardItems.arraySize < 10;
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            #endregion
            break;

        case 3:
            #region case 3 对话
            EditorGUILayout.PropertyField(beginDialogue, new GUIContent("开始时的对话"));
            if (beginDialogue.objectReferenceValue)
            {
                if (GUILayout.Button("编辑"))
                {
                    EditorUtility.OpenPropertyEditor(beginDialogue.objectReferenceValue);
                }
                if (completeDialogue.objectReferenceValue == beginDialogue.objectReferenceValue || beginDialogue.objectReferenceValue == ongoingDialogue.objectReferenceValue)
                {
                    EditorGUILayout.HelpBox("进行时或完成时已使用该对话,游戏中可能会产生逻辑错误。", MessageType.Warning);
                }
                else
                {
                    Quest find = Array.Find(questCache, x => x != quest && (x.BeginDialogue == beginDialogue.objectReferenceValue || x.CompleteDialogue == beginDialogue.objectReferenceValue ||
                                                                            x.OngoingDialogue == beginDialogue.objectReferenceValue));
                    if (find)
                    {
                        EditorGUILayout.HelpBox("已有任务使用该对话,游戏中可能会产生逻辑错误。\n配置路径:\n" + AssetDatabase.GetAssetPath(find), MessageType.Warning);
                    }
                }
                PreviewDialogue(beginDialogue.objectReferenceValue as Dialogue);
            }
            else
            {
                NewDialogueFor(beginDialogue);
            }
            EditorGUILayout.PropertyField(ongoingDialogue, new GUIContent("进行中的对话"));
            if (ongoingDialogue.objectReferenceValue)
            {
                if (GUILayout.Button("编辑"))
                {
                    EditorUtility.OpenPropertyEditor(ongoingDialogue.objectReferenceValue);
                }
                if (ongoingDialogue.objectReferenceValue == beginDialogue.objectReferenceValue || completeDialogue.objectReferenceValue == ongoingDialogue.objectReferenceValue)
                {
                    EditorGUILayout.HelpBox("开始时或完成时已使用该对话,游戏中可能会产生逻辑错误。", MessageType.Warning);
                }
                else
                {
                    Quest find = Array.Find(questCache, x => x != quest && (x.BeginDialogue == ongoingDialogue.objectReferenceValue || x.CompleteDialogue == ongoingDialogue.objectReferenceValue ||
                                                                            x.OngoingDialogue == ongoingDialogue.objectReferenceValue));
                    if (find)
                    {
                        EditorGUILayout.HelpBox("已有任务使用该对话,游戏中可能会产生逻辑错误。\n配置路径:\n" + AssetDatabase.GetAssetPath(find), MessageType.Warning);
                    }
                }
                PreviewDialogue(ongoingDialogue.objectReferenceValue as Dialogue);
            }
            else
            {
                NewDialogueFor(ongoingDialogue);
            }
            EditorGUILayout.PropertyField(completeDialogue, new GUIContent("完成时的对话"));
            if (completeDialogue.objectReferenceValue)
            {
                if (GUILayout.Button("编辑"))
                {
                    EditorUtility.OpenPropertyEditor(completeDialogue.objectReferenceValue);
                }
                if (completeDialogue.objectReferenceValue == beginDialogue.objectReferenceValue || completeDialogue.objectReferenceValue == ongoingDialogue.objectReferenceValue)
                {
                    EditorGUILayout.HelpBox("开始时或进行时已使用该对话,游戏中可能会产生逻辑错误。", MessageType.Warning);
                }
                else
                {
                    Quest find = Array.Find(questCache, x => x != quest && (x.BeginDialogue == completeDialogue.objectReferenceValue || x.CompleteDialogue == completeDialogue.objectReferenceValue ||
                                                                            x.OngoingDialogue == completeDialogue.objectReferenceValue));
                    if (find)
                    {
                        EditorGUILayout.HelpBox("已有任务使用该对话,游戏中可能会产生逻辑错误。\n配置路径:\n" + AssetDatabase.GetAssetPath(find), MessageType.Warning);
                    }
                }
                PreviewDialogue(completeDialogue.objectReferenceValue as Dialogue);
            }
            else
            {
                NewDialogueFor(completeDialogue);
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            #endregion
            break;

        case 4:
            #region case 4 目标
            EditorGUILayout.PropertyField(cmpltObjctvInOrder, new GUIContent("按顺序完成目标"));
            if (quest.CmpltObjctvInOrder)
            {
                EditorGUILayout.HelpBox("勾选此项,则勾选按顺序的目标按执行顺序从小到大的顺序执行,若相同,则表示可以同时进行;" +
                                        "若目标没有勾选按顺序,则表示该目标不受顺序影响。", MessageType.Info);
            }

            showState.target = EditorGUILayout.Foldout(objectives.isExpanded, "任务目标\t\t"
                                                       + (objectives.isExpanded ? string.Empty : (objectives.arraySize > 0 ? "数量:" + objectives.arraySize : "无")), true);
            if (EditorGUILayout.BeginFadeGroup(showState.faded))
            {
                objectiveList.DoLayoutList();
            }
            EditorGUILayout.EndFadeGroup();
            EditorGUILayout.LabelField("目标显示预览");
            GUI.enabled = false;
            EditorGUILayout.TextArea(quest.GetObjectiveString());
            GUI.enabled = true;
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            #endregion
            break;
        }

        void NewDialogueFor(SerializedProperty dialogue)
        {
            if (GUILayout.Button("新建"))
            {
                Dialogue dialogInstance = ZetanUtility.Editor.SaveFilePanel(CreateInstance <Dialogue>, "dialogue", ping: true);
                if (dialogInstance)
                {
                    dialogue.objectReferenceValue = dialogInstance;
                    EditorUtility.OpenPropertyEditor(dialogInstance);
                }
            }
        }

        void PreviewDialogue(Dialogue dialogue)
        {
            string dialoguePreview = string.Empty;

            for (int i = 0; i < dialogue.Words.Count; i++)
            {
                var words = dialogue.Words[i];
                dialoguePreview += "[" + words.TalkerName + "]说:\n-" + MiscFuntion.HandlingKeyWords(words.Content, false, talkerCache);
                for (int j = 0; j < words.Options.Count; j++)
                {
                    dialoguePreview += "\n--(选项" + (j + 1) + ")" + words.Options[j].Title;
                }
                dialoguePreview += i == dialogue.Words.Count - 1 ? string.Empty : "\n";
            }
            GUI.enabled = false;
            EditorGUILayout.TextArea(dialoguePreview);
            GUI.enabled = true;
        }
    }
Пример #3
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();
            }
        }