#pragma warning restore CS0649
    // Start is called before the first frame update
    void Start()
    {
        sceneDataList = SceneListLoader.LoadSceneList();
        GameObject temp = map.interactables[0];

        Component[] c = temp.GetComponentsInChildren(typeof(Image));
        if (c != null && c.Length != 0)
        {
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i].gameObject != temp)
                {
                    ((Image)c[i]).enabled = false;
                }
            }
        }
        map.interactables.RemoveAt(0);
        for (int i = 0; i < sceneDataList.list.Count; i++)
        {
            map.interactables.Add(CreateButton(sceneDataList.list[i], new Vector3(0, -10 * (i + 1), 0)).gameObject);
        }
        map.interactables.Add(temp);

        InteractableList interactableList = ListSingleton.instance;

        interactableList.UpdateMap(map);
        // interactableList.ClearList();
        // interactableList.FindInteractables();
        // interactableList.Next();
        EventSystem.current.SetSelectedGameObject(interactableList.focusedGo);
        DescriptionPlayer dp = interactableList.focusedGo.GetComponent(typeof(DescriptionPlayer)) as DescriptionPlayer;

        dp.OnDescriptorPress(null);
        viewControl.CheckGraphics();
    }
    public override void OnInspectorGUI()
    {
        InteractableList m_target = (InteractableList)target;

        base.OnInspectorGUI();

        int index = 0;

        foreach (InteractableObjects objects in m_target.interactables)
        {
            if (objects.script != null)
            {
                objects.prefab = objects.script.gameObject;
            }
            else if (objects.prefab != null)
            {
                objects.script = objects.prefab.GetComponent <Interactable>();
            }
            objects.name         = objects.prefab.name;
            objects.script.index = index;

            if (GUILayout.Button("Clear List: " + index))
            {
                objects.dialogueTree.Clear();
            }

            index++;
        }

        foreach (InteractableObjects objects in m_target.interactables)
        {
            objects.script.dialogueTree = objects.dialogueTree;
        }
    }
Example #3
0
    static void ShowEditor()
    {
        NodeEditor editor = GetWindow <NodeEditor>();

        editor.Show();
        // Loads in the interactbles database from this file location
        interactableList = AssetDatabase.LoadAssetAtPath <InteractableList>("Assets/InteractableList.asset");
    }
 // Ao iniciar o module é realizada uma busca de objetos interagíveis.
 // TODO Verificar a possibilidade de popular a lista de outros meios
 protected override void Start()
 {
     base.Start();
     interactableList = ListSingleton.instance;
     // interactableList.ClearList();
     //interactableList.FindInteractables();
     if (!interactableList.isEmpty)
     {
         eventSystem.SetSelectedGameObject(interactableList.focusedGo);
         DescriptionPlayer dp = interactableList.focusedGo.GetComponent(typeof(DescriptionPlayer)) as DescriptionPlayer;
         dp.OnDescriptorPress(null);
     }
 }
    bool showElement = false; // Shows element's information

    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        InteractableList interactableList = AssetDatabase.LoadAssetAtPath <InteractableList>("Assets/InteractableList.asset");

        Interactable interactable = (Interactable)target;

        interactable.dialogueTree = interactableList.interactables[interactable.index].dialogueTree;

        SerializedProperty dialogueTree = serializedObject.FindProperty("dialogueTree");
        SerializedProperty notStarted   = serializedObject.FindProperty("dialogueNotStarted");

        EditorGUILayout.PropertyField(notStarted);

        if (GUILayout.Button("Clear Tree"))
        {
            dialogueTree.ClearArray();
        }

        // Shows elements in dialogue tree
        showTree = EditorGUILayout.Foldout(showTree, "Dialogue Tree: " + dialogueTree.arraySize, true);
        if (showTree)
        {
            EditorGUI.indentLevel++;
            for (int i = 0; i < dialogueTree.arraySize; i++)
            {
                // Gets the parts of the node that will be displayed
                SerializedProperty currentDialogueType = dialogueTree.GetArrayElementAtIndex(i);
                SerializedProperty index = currentDialogueType.FindPropertyRelative("index");
                index.intValue = i;
                SerializedProperty dialogueType = currentDialogueType.FindPropertyRelative("dialogueType");
                SerializedProperty inputCount   = currentDialogueType.FindPropertyRelative("inputCount");
                SerializedProperty outputCount  = currentDialogueType.FindPropertyRelative("outputCount");
                SerializedProperty sentences    = currentDialogueType.FindPropertyRelative("sentences");
                SerializedProperty question     = currentDialogueType.FindPropertyRelative("question");
                SerializedProperty choices      = currentDialogueType.FindPropertyRelative("choices");
                SerializedProperty choiceNum    = currentDialogueType.FindPropertyRelative("choiceNum");

                // TODO: Fix ArgumentException error
                // Shows specific element in tree
                showElement = EditorGUILayout.Foldout(showElement, index.intValue + ": " + dialogueType.stringValue, true);
                if (showElement)
                {
                    EditorGUILayout.LabelField("Number of Inputs: " + inputCount.intValue);
                    EditorGUILayout.LabelField("Number of Outputs: " + outputCount.intValue);

                    EditorGUILayout.Separator();

                    // Only shows the parts that are necessary for each dialogue type
                    if (dialogueType.stringValue == "Dialogue")
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(sentences, true);
                        EditorGUI.indentLevel--;
                    }
                    else if (dialogueType.stringValue == "Choice")
                    {
                        EditorGUILayout.PropertyField(question);
                        EditorGUILayout.LabelField("Number of Choices: " + choiceNum.intValue);

                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(choices, true);
                        EditorGUI.indentLevel--;
                    }
                }
            }

            EditorGUI.indentLevel--;
        }
        // Saves dialogue tree
        serializedObject.ApplyModifiedProperties();
    }
Example #6
0
    /// <summary>
    /// What the Node Editor window shows
    /// </summary>
    private void OnGUI()
    {
        if (interactableList == null)
        {
            interactableList = AssetDatabase.LoadAssetAtPath <InteractableList>("Assets/InteractableList.asset");
        }

        if (windows.Count == 0)
        {
            box.center = new Vector2(position.width / 2, position.height / 2);
            GUI.Box(box, "No Dialogue Yet");
        }

        Event e = Event.current;

        mousePos = e.mousePosition;

        DisplayInteractables(position);

        // If right clicked and not making a node connection
        if (e.button == 1 && !makeTransitionMode)
        {
            if (e.type == EventType.MouseDown)
            {
                bool clickedOnWindow = false; // Clicked on any node
                int  selectedIndex   = -1;    // Selected Node

                // Checks if clicked on any node
                for (int i = 0; i < windows.Count; i++)
                {
                    if (windows[i].windowRect.Contains(mousePos))
                    {
                        selectedIndex   = i;
                        clickedOnWindow = true;
                        break;
                    }
                }

                // Clicked on area outside of node
                if (!clickedOnWindow)
                {
                    GenericMenu menu = new GenericMenu(); // Right-click menu

                    // Adds elements to the right-click menu
                    menu.AddItem(new GUIContent("Add Dialogue Node"), false, ContextCallback, "dialogueNode");
                    menu.AddItem(new GUIContent("Add Choice Node"), false, ContextCallback, "choiceNode");

                    menu.ShowAsContext();
                    e.Use();
                }
                // Clicked inside of a node
                else
                {
                    rightClickPos = e.mousePosition;

                    GenericMenu menu = new GenericMenu(); // Right-click menu

                    // Adds elements to the right-click menu
                    menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition");
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode");

                    menu.ShowAsContext();
                    e.Use();
                }
            }
        }
        // Left mouse button pressed while in transition mode
        else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode)
        {
            bool clickedOnWindow = false; // Clicked on any node
            int  selectedIndex   = -1;    // Selected Node

            // Checks if clicked on any node
            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].windowRect.Contains(mousePos))
                {
                    selectedIndex   = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            // When clicked on another node it connects them
            if (clickedOnWindow && !windows[selectedIndex].Equals(selectedNode))
            {
                windows[selectedIndex].SetInput(selectedNode, mousePos);
                windows[windows.IndexOf(selectedNode)].SetOutput(windows[selectedIndex], rightClickPos);
                makeTransitionMode = false;

                //EditorUtility.SetDirty(selectedNode); // Meant to allow saves

                selectedNode = null;
            }

            // If clicked anywhere outside of a node, transition mode ends
            if (!clickedOnWindow)
            {
                makeTransitionMode = false;
                selectedNode       = null;
            }

            e.Use();
        }
        // Left-click and not in transition mode
        else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode)
        {
            bool clickedOnWindow = false; // Clicked on any node
            int  selectedIndex   = -1;    // Selected Node

            // Checks if clicked on any node
            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].windowRect.Contains(mousePos))
                {
                    selectedIndex   = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            //TODO: MAKE WINDOWS RESIZABLE
            if (clickedOnWindow)
            {
                // Used to resize node windows
                Rect    originalSize = windows[selectedIndex].windowRect;
                Vector2 prevMousePos = mousePos;

                if (mousePos.x >= (windows[selectedIndex].windowRect.width + windows[selectedIndex].windowRect.x) - 10)
                //|| mousePos.x <= windows[selectedIndex].windowRect.x + 5)
                {
                    EditorGUIUtility.AddCursorRect(windows[selectedIndex].windowRect, MouseCursor.ResizeHorizontal);
                    Debug.Log("in X");
                    if (e.type == EventType.MouseDrag)
                    {
                        if (mousePos.x < prevMousePos.x)
                        {
                            Debug.Log("entered");
                            windows[selectedIndex].windowRect.width -= Mathf.Abs(prevMousePos.x - mousePos.x);
                        }
                        else if (mousePos.x > prevMousePos.x)
                        {
                            windows[selectedIndex].windowRect.width += Mathf.Abs(prevMousePos.x - mousePos.x);
                        }
                    }
                }

                if (mousePos.y >= (windows[selectedIndex].windowRect.height + windows[selectedIndex].windowRect.y) - 10)
                //|| mousePos.y <= windows[selectedIndex].windowRect.y + 5)
                {
                    EditorGUIUtility.AddCursorRect(windows[selectedIndex].windowRect, MouseCursor.ResizeVertical);
                    Debug.Log("in Y");
                    if (e.type == EventType.MouseDrag)
                    {
                        Debug.Log("entered");
                        if (mousePos.y < prevMousePos.y)
                        {
                            windows[selectedIndex].windowRect.height -= Mathf.Abs(prevMousePos.y - mousePos.y);
                        }
                        else if (mousePos.y > prevMousePos.y)
                        {
                            windows[selectedIndex].windowRect.height += Mathf.Abs(prevMousePos.y - mousePos.y);
                        }
                    }
                }
            }
        }

        // Draws curve between two connected nodes
        if (makeTransitionMode && selectedNode != null)
        {
            Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 10, 10);

            DrawNodeCurve(selectedNode.windowRect, mouseRect);

            Repaint();
        }

        // If node editors open with Unity n.DrawCurves would give an error.
        // This catches that error and instead tries to display an object's dialogue tree
        try
        {
            // Draws curves
            foreach (BaseNode n in windows)
            {
                n.DrawCurves();
            }
        }
        catch (System.Exception)
        {
            ConvertTreeToNodes(SelectedInteractable);
        }

        // Draws node windows
        BeginWindows();

        for (int i = 0; i < windows.Count; i++)
        {
            windows[i].windowRect = GUI.Window(i, windows[i].windowRect, DrawNodeWindow, windows[i].windowTitle);
        }

        EndWindows();
    }