Пример #1
0
        void OnEnable()
        {
            if (!target)
            {
                return;
            }
            OnSceneGUIHelper.Register(OnSceneGUI);
            Mission     selectedMission = target as Mission;
            List <Team> teams           = selectedMission.Teams;
            int         last            = SessionState.GetInt("MissionEditor_LastTeamIndex", 0);

            if (teams.Count == 0 && last < teams.Count)
            {
                return;
            }

            if (auxWindow == null)
            {
                TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();
                if (teams.Count > SessionState.GetInt("MissionEditor_LastTeamIndex", 0))
                {
                    teamEdit.Do(teams[SessionState.GetInt("MissionEditor_LastTeamIndex", 0)], selectedMission);
                    teamEdit.SetParent(this);
                    auxWindow = teamEdit;
                }
            }
            MissionCondition.ConditionType a = selectedMission.WinDondition == null ? MissionCondition.ConditionType.Custom : selectedMission.WinDondition.conditionType;
            MissionCondition.ConditionType b = selectedMission.LoseCondition == null ? MissionCondition.ConditionType.Custom : selectedMission.LoseCondition.conditionType;

            ConditionTypes = new MissionCondition.ConditionType[] { a, b };
            UpdateDictionaries();
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            Mission selectedMission = target as Mission;

            if (auxWindow == null)
            {
                TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();
                if (selectedMission.Teams.Count > SessionState.GetInt("MissionEditor_LastTeamIndex", 0))
                {
                    teamEdit.Do(selectedMission.Teams[SessionState.GetInt("MissionEditor_LastTeamIndex", 0)], selectedMission);
                    teamEdit.SetParent(this);
                    auxWindow = teamEdit;
                }
            }

            EditorGUI.BeginChangeCheck();
            Loadable next = EditorGUILayout.ObjectField("Next Mission", selectedMission.NextLoadable, typeof(Loadable), false) as Loadable;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(selectedMission, "Modify Mission");
                selectedMission.NextLoadable = next;
            }
            List <Team> teams = selectedMission.Teams;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Teams", EditorStyles.boldLabel, GUILayout.Width(50));

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)))
            {
                Undo.RecordObject(selectedMission, "Add Team");
                teams.Add(new Team());
            }
            EditorGUILayout.EndHorizontal();
            int i = 0;

            for (i = 0; i < teams.Count; i++)
            {
                int  _i   = i;
                Team team = teams[_i];


                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);
                if (GUILayout.Button("Team: " + _i + "    Members: " + team.members.Count.ToString(), EditorStyles.miniButtonLeft))
                {
                    TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();
                    teamEdit.Do(team, selectedMission);
                    teamEdit.SetParent(this);
                    auxWindow = teamEdit;
                    SessionState.SetInt("MissionEditor_LastTeamIndex", _i);
                }
                if (GUILayout.Button("Pop", EditorStyles.miniButtonRight, GUILayout.Width(35)))
                {
                    TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();
                    teamEdit.Do(team, selectedMission);
                    teamEdit.Show();
                    auxWindow = null;
                }

                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.LabelField("End Conditions", EditorStyles.boldLabel);
            selectedMission.ConditionSelector("Victory", ref ShowdCondition[0], ref selectedMission.WinDondition, ref ConditionTypes[0]);
            selectedMission.ConditionSelector("Defeat", ref ShowdCondition[1], ref selectedMission.LoseCondition, ref ConditionTypes[1]);
            GUILayout.Space(10);
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Intro Text", EditorStyles.boldLabel);

            string introText = EditorGUILayout.TextArea(selectedMission.MissionIntroText);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(selectedMission, "Modify Mission");
                selectedMission.MissionIntroText = introText;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Events", EditorStyles.boldLabel);
            if (GUILayout.Button("+"))
            {
                Undo.RegisterCompleteObjectUndo(selectedMission, "Add Event Group");
                selectedMission.events.Add(new MissionEventContainer());
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel++;

            for (int q = 0; q < selectedMission.events.Count; q++)
            {
                for (int z = 0; z < selectedMission.events[q].allEvents.Count; z++)
                {
                    if (!eventEditors.ContainsKey(selectedMission.events[q].allEvents[z]))
                    {
                        UpdateDictionaries();
                        break;
                    }
                }
            }

            int deleteindex = -1;

            for (int q = 0; q < selectedMission.events.Count; q++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                selectedMission.events[q].OnGUI(eventEditors, selectedMission);
                EditorGUILayout.EndVertical();
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    deleteindex = q;
                }

                EditorGUILayout.EndHorizontal();
            }
            if (deleteindex != -1)
            {
                MissionEventContainer cont = selectedMission.events[deleteindex];
                selectedMission.events.RemoveAt(deleteindex);

                if (cont.cond != null && AssetDatabase.GetAssetPath(cont.cond) == AssetDatabase.GetAssetPath(selectedMission))
                {
                    DestroyImmediate(cont.cond, true);
                }
            }
            EditorGUI.indentLevel--;

            GUILayout.Space(10);
            if (auxWindow != null)
            {
                if (auxWindow.Render())
                {
                    Editor.DestroyImmediate(auxWindow as EditorWindow);
                    auxWindow = null;
                }
            }

            if (GUI.changed && !Application.isPlaying && selectedMission != null)
            {
                EditorUtility.SetDirty(selectedMission);
            }
        }
Пример #3
0
        public override bool Render()
        {
            if (this.character == null)
            {
                return(false);
            }


            scroll = EditorGUILayout.BeginScrollView(scroll);
            bool delete = false;
            bool close  = false;

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.VerticalScope clickArea = new EditorGUILayout.VerticalScope();
            using (clickArea)
            {
                EditorGUILayout.BeginHorizontal();
                if (showUniqueControls)
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("user");
                    GUIStyle style         = GUI.GetNameOfFocusedControl() == "user" ? EditorStyles.textField : EditorStyles.label;
                    string   charactername = EditorGUILayout.TextField(GUIContent.none, this.character._Name, style);

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(UndoObject, "Modify Character");
                        this.character._Name = charactername;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(this.character._Name, EditorStyles.label);
                }

                if (this.parent != null)
                {
                    if (GUILayout.Button("Pop"))
                    {
                        this.Show();
                        TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();

                        teamEdit.Do(mission.FindTeam(character), mission);
                        teamEdit.SetParent(this.parent);
                        this.parent.auxWindow = teamEdit;
                        this.parent           = null;
                    }
                }

                if (GUILayout.Button("X"))
                {
                    Undo.RecordObject(UndoObject, "Remove Character");
                    if (this.parent != null)
                    {
                        TeamEditor teamEdit = Editor.CreateInstance <TeamEditor>();
                        teamEdit.Do(mission.FindTeam(this.character), mission);
                        teamEdit.SetParent(this.parent);
                        this.parent.auxWindow = teamEdit;
                        this.parent           = null;
                    }
                    else
                    {
                        this.Close();
                    }


                    DestroyImmediate(character.SpawnCondition, true);
                    mission.FindTeam(this.character).members.Remove(this.character);
                    mission.RefreshCharacterDictionary();
                }

                if (GUILayout.Button("Close", GUILayout.Width(55)))
                {
                    close = true;
                }

                EditorGUILayout.EndHorizontal();


                EditorGUI.BeginDisabledGroup(!showUniqueControls);
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.BeginHorizontal();
                Sprite spr = EditorGUILayout.ObjectField(GUIContent.none, this.character.UIIcon, typeof(Sprite), false, GUILayout.Width(75)) as Sprite;
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                if (EditorGUI.EndChangeCheck())
                {
                    this.character.UIIcon = spr;
                }
                EditorGUI.EndDisabledGroup();
                this.character.prefab = EditorGUILayout.ObjectField("Prefab", this.character.prefab, typeof(CharacterBody), false) as CharacterBody;
                GUILayout.Space(10);
                EditorGUILayout.LabelField("AI", EditorStyles.boldLabel);

                EditorGUI.indentLevel++;



                EditorGUI.BeginChangeCheck();
                AIBehaviour _behav = EditorGUILayout.ObjectField("Ai Behaviour", this.character.aiBehaviour, typeof(AIBehaviour), false) as AIBehaviour;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(UndoObject, "Modify AI"); this.character.aiBehaviour = _behav;
                }


                if (this.character.aiBehaviour && mission != null)
                {
                    if (character.onStartPath.Count != 0)
                    {
                        if (GUILayout.Button("Modify Path"))
                        {
                            PathMaker.Begin(SetStartPath, character.onStartPath);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Create Path"))
                        {
                            PathMaker.Begin(SetStartPath, new List <GridPosition>());
                        }
                    }
                }
                GUILayout.Space(10);
                EditorGUI.indentLevel--;
                if (mission != null)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    Folds[0] = EditorGUILayout.Foldout(Folds[0], GUIContent.none);
                    GUILayout.Space(-40);
                    EditorGUILayout.LabelField("Spawning", EditorStyles.boldLabel);
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    if (Folds[0])
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(18);
                        this.character.SpawnPositon.EditorField(mission, EditorTools.CurrentInspectedGrid, new GUIContent("Position"));
                        EditorGUILayout.EndHorizontal();


                        mission.ConditionSelector("Spawn Condition", ref ShowSpanwCondFold, ref character.SpawnCondition, ref currentSelectedCtype);

                        EditorGUI.BeginChangeCheck();
                        GameGrid.BlockDirections.FaceDirections dir = (GameGrid.BlockDirections.FaceDirections)EditorGUILayout.EnumPopup("Face direction:", character.SpawnDirection);

                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(UndoObject, "Change Direction"); character.SpawnDirection = dir;
                        }
                        EditorGUI.indentLevel--;
                    }
                }
            }

            Event e = Event.current;

            if (e.isMouse && e.button == 1 && clickArea.rect.Contains(e.mousePosition))
            {
                GenericMenu CreateMenu = new GenericMenu();
                if (CopyCharacter != null)
                {
                    CreateMenu.AddItem(new GUIContent("Paste Character Values"), false, Paste);
                }
                else
                {
                    CreateMenu.AddDisabledItem(new GUIContent("Paste Character Values"));
                }
                CreateMenu.AddItem(new GUIContent("Copy Character Values"), false, Copy);
                CreateMenu.ShowAsContext();
            }

            EditorGUI.BeginDisabledGroup(!showUniqueControls);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            Folds[1] = EditorGUILayout.Foldout(Folds[1], GUIContent.none);
            GUILayout.Space(-40);
            EditorGUILayout.LabelField("Stats", EditorStyles.boldLabel);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (Folds[1])
            {
                EditorGUI.indentLevel++;
                if (statsEditor == null)
                {
                    statsEditor = new StatsEditor(character.stats, mission, UndoObject);
                }
                statsEditor.OnGUI();

                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            Folds[2] = EditorGUILayout.Foldout(Folds[2], GUIContent.none);
            GUILayout.Space(-40);
            EditorGUILayout.LabelField("Inventory", EditorStyles.boldLabel);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (Folds[2])
            {
                EditorGUI.BeginChangeCheck();

                for (int i = 0; i < character.inventroy.Items.Count; i++)
                {
                    if (!itemFolds.ContainsKey(character.inventroy.Items[i]))
                    {
                        RefreshDictionaries();
                        break;
                    }
                }

                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                int addItem = EditorGUILayout.Popup("Add Item", 0, EditorTools.ItemDatabase.ItemNames);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(UndoObject, "Modify Inventory");
                    int index = character.inventroy.Items.FindIndex(a => a.item == EditorTools.ItemDatabase.items[addItem]);
                    if (index == -1)
                    {
                        character.inventroy.Items.Add(new ItemStack(EditorTools.ItemDatabase.items[addItem]));
                    }
                    else
                    {
                        character.inventroy.Items[index].amount++;
                    }
                }
                EditorGUI.BeginDisabledGroup(ItemEditor.CopiedItem == null);
                if (GUILayout.Button("Paste"))
                {
                    int index = character.inventroy.Items.FindIndex(a => a.item == ItemEditor.CopiedItem);
                    Undo.RecordObject(UndoObject, "Modify Inventory");
                    if (index == -1)
                    {
                        character.inventroy.Items.Add(new ItemStack(ItemEditor.CopiedItem));
                    }
                    else
                    {
                        character.inventroy.Items[index].amount++;
                    }
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();

                int deleteIndex = -1;
                for (int i = 0; i < character.inventroy.Items.Count; i++)
                {
                    if (itemFolds.ContainsKey(character.inventroy.Items[i]))
                    {
                        if (character.inventroy.Items[i].item == null)
                        {
                            character.inventroy.Items.RemoveAt(i);
                            continue;
                        }
                        EditorGUILayout.BeginHorizontal();
                        itemFolds[character.inventroy.Items[i]] = EditorGUILayout.Foldout(itemFolds[character.inventroy.Items[i]], character.inventroy.Items[i].item.ItemName);
                        character.inventroy.Items[i].amount     = EditorGUILayout.IntField(character.inventroy.Items[i].amount);

                        if (GUILayout.Button("X", GUILayout.Width(20)) || character.inventroy.Items[i].amount <= 0)
                        {
                            deleteIndex = i;
                        }

                        EditorGUILayout.EndHorizontal();
                        if (itemFolds[character.inventroy.Items[i]])
                        {
                            EditorGUI.indentLevel++;
                            cachedEditors[character.inventroy.Items[i]].OnInspectorGUI();
                            EditorGUI.indentLevel--;
                        }
                    }
                    else
                    {
                        RefreshDictionaries();
                    }
                }
                if (deleteIndex != -1)
                {
                    Undo.RecordObject(UndoObject, "Modify Inventory");
                    character.inventroy.Items.RemoveAt(deleteIndex);
                }
                EditorGUI.EndDisabledGroup();
                EditorGUI.indentLevel--;
            }
            if (GUI.changed && !Application.isPlaying)
            {
                EditorUtility.SetDirty(UndoObject);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
            return(delete || close);
        }