Exemplo n.º 1
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);
        }
Exemplo n.º 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);
            }
        }
        public static void OnGUI(this MissionEventContainer cont, Dictionary <MissionEvent, MissionEventEditor> editors, Mission miss = null)
        {
            EditorGUILayout.BeginHorizontal();
            cont.MainFold = EditorGUILayout.Foldout(cont.MainFold, cont.editorName, true);
            EditorGUI.BeginChangeCheck();

            if (GUILayout.Button("+", GUILayout.Width(25)))
            {
                GenericMenu CreateMenu = new GenericMenu();
                CreateMenu.AddItem(new GUIContent("Kill Character"), false, AddEventMenu, new object[] { cont, typeof(ME_KillCharacter), miss });
                CreateMenu.AddItem(new GUIContent("Give Item"), false, AddEventMenu, new object[] { cont, typeof(ME_GiveItem), miss });
                CreateMenu.AddItem(new GUIContent("Visu 16"), false, AddEventMenu, new object[] { cont, typeof(ME_Visu16), miss });

                CreateMenu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();



            if (cont.MainFold)
            {
                EditorGUI.indentLevel++;
                MissionCondition.ConditionType t = cont.cond == null ? MissionCondition.ConditionType.Custom : cont.cond.conditionType;
                miss.ConditionSelector("Trigger when", ref cont.conditionFold, ref cont.cond, ref t);

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Events", EditorStyles.boldLabel);
                for (int i = 0; i < cont.allEvents.Count; i++)
                {
                    if (!cont.EditorFolds.ContainsKey(cont.allEvents[i]))
                    {
                        cont.UpdateDictionary();
                    }
                }

                int deleteIndex = -1;
                for (int i = 0; i < cont.allEvents.Count; i++)
                {
                    if (cont.allEvents[i] != null)
                    {
                        EditorGUILayout.BeginHorizontal();

                        cont.EditorFolds[cont.allEvents[i]] = EditorGUILayout.Foldout(cont.EditorFolds[cont.allEvents[i]], cont.allEvents[i].editorName + " (" + (cont.allEvents[i]).GetType().Name + ")");
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("X", GUILayout.Width(20)))
                        {
                            deleteIndex = i;
                        }

                        EditorGUI.BeginDisabledGroup(i == 0);
                        if (GUILayout.Button("^", GUILayout.Width(20)))
                        {
                            cont.allEvents[i].listIndex--;
                            cont.allEvents[i - 1].listIndex++;
                            MissionEvent evt = cont.allEvents[i];
                            cont.allEvents[i]     = cont.allEvents[i - 1];
                            cont.allEvents[i - 1] = evt;
                        }
                        EditorGUI.EndDisabledGroup();
                        EditorGUI.BeginDisabledGroup(i == cont.allEvents.Count - 1);
                        if (GUILayout.Button("v", GUILayout.Width(20)))
                        {
                            cont.allEvents[i].listIndex++;
                            cont.allEvents[i + 1].listIndex--;
                            MissionEvent evt = cont.allEvents[i];
                            cont.allEvents[i]     = cont.allEvents[i + 1];
                            cont.allEvents[i + 1] = evt;
                        }
                        EditorGUI.EndDisabledGroup();


                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUI.indentLevel++;
                        GUILayout.Space(20 * EditorGUI.indentLevel);

                        if (cont.EditorFolds[cont.allEvents[i]])
                        {
                            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                            editors[cont.allEvents[i]].OnGUI();
                            EditorGUILayout.EndVertical();
                        }

                        EditorGUI.indentLevel--;
                        EditorGUILayout.EndHorizontal();
                    }
                }
                if (deleteIndex != -1)
                {
                    cont.EditorFolds.Remove(cont.allEvents[deleteIndex]);
                    cont.allEvents.RemoveAt(deleteIndex);

                    cont.Save();
                }
                EditorGUI.indentLevel--;
            }
        }