public static void AddElement(DatabaseQuestsEditor databaseQuestsEditor) { List <int> selections = new List <int> { databaseQuestsEditor.editorRoot.target.GetInstanceID() }; List <int> nextSelections = new List <int>(); if (databaseQuestsEditor.questsTree.HasSelection()) { selections = new List <int>(databaseQuestsEditor.questsTree.GetSelection()); } for (int i = 0; i < selections.Count; ++i) { int selectionID = selections[i]; IQuest instance = databaseQuestsEditor.InstanceIDToObject(selectionID); Task itemInstance = databaseQuestsEditor.CreateItem <Task>(); nextSelections.Add(itemInstance.GetInstanceID()); if (instance != null && instance.GetType() == typeof(Quest) && databaseQuestsEditor.questsEditors.ContainsKey(instance.GetInstanceID())) { databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddChild( itemInstance, (IQuest)instance ); } else if (instance != null && instance.GetType() == typeof(Task) && databaseQuestsEditor.questsEditors.ContainsKey(instance.GetInstanceID())) { databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddChild( itemInstance, (IQuest)instance ); } else { Debug.LogError("Unknown type: " + instance.GetType()); } databaseQuestsEditor.questsEditors.Add( itemInstance.GetInstanceID(), IQuestEditor.CreateEditor(itemInstance) ); databaseQuestsEditor.questsTree.Reload(); databaseQuestsEditor.serializedObject.ApplyModifiedProperties(); databaseQuestsEditor.serializedObject.Update(); } databaseQuestsEditor.questsTree.SetFocusAndEnsureSelectedItem(); databaseQuestsEditor.questsTree.SetSelection(nextSelections, TreeViewSelectionOptions.RevealAndFrame); }
public override bool CanHaveParent(IQuest parent) { if (parent.GetType() == typeof(Quest)) { return(true); } if (parent.GetType() == typeof(Task)) { return(true); } return(false); }
public static void AddElement(DatabaseQuestsEditor databaseQuestsEditor) { List <int> selections = new List <int> { databaseQuestsEditor.editorRoot.target.GetInstanceID() }; List <int> nextSelections = new List <int>(); if (databaseQuestsEditor.questsTree.HasSelection()) { selections = new List <int>(databaseQuestsEditor.questsTree.GetSelection()); } int selectionID = QuestsTreeView.ROOT_ID; if (selections.Count == 1) { selectionID = selections[0]; } IQuest instance = databaseQuestsEditor.InstanceIDToObject(selectionID); Quest itemInstance = databaseQuestsEditor.CreateItem <Quest>(); nextSelections = new List <int>() { itemInstance.GetInstanceID() }; if (instance != null && instance.GetType() == typeof(Quest)) { databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddSibling( itemInstance, (IQuest)instance, selectionID ); } else { Quests rootInstance = databaseQuestsEditor.databaseQuests.quests; databaseQuestsEditor.editorRoot.AddChild( itemInstance, rootInstance ); } databaseQuestsEditor.questsEditors.Add( itemInstance.GetInstanceID(), IQuestEditor.CreateEditor(itemInstance) ); databaseQuestsEditor.questsTree.Reload(); databaseQuestsEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo(); databaseQuestsEditor.serializedObject.Update(); databaseQuestsEditor.questsTree.SetFocusAndEnsureSelectedItem(); databaseQuestsEditor.questsTree.SetSelection( nextSelections, TreeViewSelectionOptions.RevealAndFrame ); }
public override bool CanHaveParent(IQuest parent) { return(parent.GetType() == typeof(Quests)); }
private void PaintQuestToolbar() { bool hasSelection = this.questsTree.HasSelection(); int selectionCount = (hasSelection ? this.questsTree.GetSelection().Count : 0); bool selectionRoot = ( selectionCount > 0 && this.questsTree.GetSelection().Contains(QuestsTreeView.ROOT_ID) ); System.Type selectionType = null; if (selectionCount == 1) { int instanceID = this.questsTree.GetSelection()[0]; IQuest instance = this.InstanceIDToObject(instanceID); selectionType = (instance != null ? instance.GetType() : null); } QuestToolbarUtils.ContentStyle contentStyle = QuestToolbarUtils.ContentStyle.IconOnly; GUIContent gcQuest = QuestToolbarUtils.GetContent(QuestToolbarUtils.ContentType.Quest, contentStyle); GUIContent gcTask = QuestToolbarUtils.GetContent(QuestToolbarUtils.ContentType.Task, contentStyle); GUIContent gcDelete = QuestToolbarUtils.GetContent(QuestToolbarUtils.ContentType.Delete, contentStyle); EditorGUILayout.BeginHorizontal(); GUILayoutOption height = GUILayout.Height(18f); EditorGUI.BeginDisabledGroup(!QuestEditor.CanAddElement(selectionCount, selectionType)); if (GUILayout.Button(gcQuest, this.styleBtnLeft, height)) { QuestEditor.AddElement(this); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!TaskEditor.CanAddElement(selectionCount, selectionType)); if (GUILayout.Button(gcTask, this.styleBtnMid, height)) { TaskEditor.AddElement(this); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!hasSelection || selectionRoot); if (GUILayout.Button(gcDelete, this.styleBtnRight, height) && this.questsTree.HasSelection()) { List <int> items = new List <int>(this.questsTree.GetSelection()); this.DeleteItems(items); AssetDatabase.ImportAsset(QuestUtilities.GetQuestsRootPath()); this.questsTree.Reload(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); this.questsTree.searchString = this.searchField.OnGUI(this.questsTree.searchString); EditorGUILayout.Space(); if (GUILayout.Button(SETTINGS, this.styleBtn)) { QuestsSettingsWindow settings = new QuestsSettingsWindow(this.spSettings); PopupWindow.Show(this.settingsRect, settings); } if (UnityEngine.Event.current.type == EventType.Repaint) { this.settingsRect = GUILayoutUtility.GetLastRect(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); }