Пример #1
0
        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
                );
        }
Пример #2
0
        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);
        }