Esempio n. 1
0
        private void BuildTree(ref TreeViewItem parentTree, IDialogueItem parentAsset)
        {
            this.treeItems.Add(parentAsset.GetInstanceID(), parentTree);

            IDialogueItemEditor editor = this.dialogueEditor.itemsEditors[parentAsset.GetInstanceID()];

            parentTree.displayName = editor.UpdateContent();
            parentTree.icon        = editor.UpdateIcon();

            List <IDialogueItem> childrenAssets = parentAsset.children;
            int childrenAssetsCount             = childrenAssets.Count;

            for (int i = 0; i < childrenAssetsCount; ++i)
            {
                IDialogueItem childAsset = childrenAssets[i];
                if (childAsset == null)
                {
                    continue;
                }

                int          childAssetID = childAsset.GetInstanceID();
                int          depth        = parentTree.depth + 1;
                TreeViewItem childTree    = new TreeViewItem(childAssetID, depth, "Loading...");

                if (!this.dialogueEditor.itemsEditors.ContainsKey(childAssetID))
                {
                    Debug.LogError("No IDialogueItem Editor found with instanceID: " + childAssetID);
                    continue;
                }

                this.BuildTree(ref childTree, childAsset);
                parentTree.AddChild(childTree);
            }
        }
        public static void AddElement(DialogueEditor dialogueEditor)
        {
            List <int> selections = new List <int> {
                dialogueEditor.editorRoot.target.GetInstanceID()
            };
            List <int> nextSelections = new List <int>();

            if (dialogueEditor.dialogueTree.HasSelection())
            {
                selections = new List <int>(dialogueEditor.dialogueTree.GetSelection());
            }

            for (int i = 0; i < selections.Count; ++i)
            {
                int selectionID             = selections[i];
                UnityEngine.Object instance = dialogueEditor.InstanceIDToObject(selectionID);
                dialogueEditor.dialogueTree.SetExpandedRecursive(selectionID, true);

                IDialogueItem itemInstance = dialogueEditor.CreateDialogueItem <DialogueItemChoice>();
                nextSelections.Add(itemInstance.GetInstanceID());

                if (instance != null && instance.GetType() == typeof(DialogueItemChoiceGroup))
                {
                    dialogueEditor.itemsEditors[selectionID].AddChild(
                        itemInstance,
                        (IDialogueItem)instance,
                        dialogueEditor.targetDialogue
                        );
                }
                else if (instance != null && instance.GetType() == typeof(DialogueItemChoice))
                {
                    dialogueEditor.itemsEditors[selectionID].AddSibling(
                        itemInstance,
                        (IDialogueItem)instance,
                        dialogueEditor.targetDialogue,
                        selectionID
                        );
                }
                else
                {
                    Debug.LogError("Forbidden or Unknown type: " + instance.GetType());
                }

                dialogueEditor.itemsEditors.Add(
                    itemInstance.GetInstanceID(),
                    IDialogueItemEditor.CreateEditor(itemInstance)
                    );

                dialogueEditor.dialogueTree.Reload();

                dialogueEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                dialogueEditor.serializedObject.Update();
            }

            dialogueEditor.dialogueTree.SetFocusAndEnsureSelectedItem();
            dialogueEditor.dialogueTree.SetSelection(nextSelections, TreeViewSelectionOptions.RevealAndFrame);
        }