Exemplo n.º 1
0
 void Awake()
 {
     currentEditor = this;
 }
Exemplo n.º 2
0
        public override bool Render()
        {
            if (this.team == null)
            {
                return(false);
            }

            bool delete = false;
            bool close  = false;

            EditorGUILayout.ScrollViewScope scrollScope = new EditorGUILayout.ScrollViewScope(scroll);
            using (scrollScope)
            {
                scroll = scrollScope.scrollPosition;

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (GUILayout.Button("X", EditorStyles.toolbarButton, GUILayout.Width(20)))
                {
                    Undo.RecordObject(mission, "Remove Team");
                    mission.Teams.Remove(this.team);
                    mission.RefreshCharacterDictionary();
                    close = true;
                }
                EditorGUILayout.LabelField("Team: " + mission.GetTeamIndex(this.team));
                if (GUILayout.Button("Close", EditorStyles.toolbarButton, GUILayout.Width(55)))
                {
                    close = true;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.BeginHorizontal();
                string _name  = EditorGUILayout.TextField("Team Name: ", team.TeamName);
                Color  tColor = EditorGUILayout.ColorField(team.TeamColor);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(mission, "Modify Team");
                    team.TeamName  = _name;
                    team.TeamColor = tColor;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField("Members", EditorStyles.miniBoldLabel);

                List <Character> characters = team.members;

                if (GUILayout.Button("+", GUILayout.Width(30)))
                {
                    Undo.RecordObject(mission, "Add Character");

                    GenericMenu CreateMenu = new GenericMenu();
                    CreateMenu.AddItem(new GUIContent("Add new"), false, CreateNewCharacter);

                    foreach (Character chara in EditorTools.CharaDatabase.commonCharacters)
                    {
                        CreateMenu.AddItem(new GUIContent("Common/" + chara._Name), false, GetCharacter, chara);
                    }
                    foreach (Character chara in EditorTools.CharaDatabase.uniqueCharacters)
                    {
                        CreateMenu.AddItem(new GUIContent("Unique/" + chara._Name), false, GetCharacter, chara);
                    }

                    CreateMenu.ShowAsContext();
                }

                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel++;


                for (int q = 0; q < characters.Count; q++)
                {
                    Character chara = characters[q];
                    var       v     = new EditorGUILayout.HorizontalScope();
                    using (v)
                    {
                        GUILayout.Space(20 * EditorGUI.indentLevel);
                        if (GUILayout.Button(chara._Name, EditorStyles.label, GUILayout.Width(150)))
                        {
                            CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>();
                            newEditor.Do(chara, mission, mission, false);
                            SessionState.SetInt("CharacterEditor_LastCharacterIndex", q);

                            if (this.parent != null)
                            {
                                this.parent.auxWindow = newEditor;
                                newEditor.SetParent(this.parent);
                            }
                            else
                            {
                                newEditor.Show();
                            }
                        }

                        if (this.parent != null)
                        {
                            if (GUILayout.Button("Pop", EditorStyles.miniButtonLeft))
                            {
                                CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>();
                                newEditor.Do(chara, mission, mission, false);
                                newEditor.Show();
                                parent.auxWindow = null;
                                this.parent      = null;
                            }
                        }
                        if (GUILayout.Button("X", EditorStyles.miniButtonRight))
                        {
                            Undo.RecordObject(mission, "Remove Character");
                            characters.Remove(chara);
                            mission.attatchedObjects.Remove(chara.SpawnCondition);
                            string path = AssetDatabase.GetAssetPath(chara.SpawnCondition);
                            AssetDatabase.DeleteAsset(path);
                            SessionState.EraseInt("CharacterEditor_LastCharacterIndex");
                        }
                    }
                    if (Event.current.button == 1 && v.rect.Contains(Event.current.mousePosition))
                    {
                        CharacterContextMenu(v.rect, chara);
                    }
                    //  EditorGUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();
            }


            return(delete || close);
        }
Exemplo n.º 3
0
 void SetParent(MissionInspector parent)
 {
 }
Exemplo n.º 4
0
 public void SetParent(MissionInspector parent)
 {
     this.parent = parent;
 }
Exemplo n.º 5
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);
        }