private void ClearSelected(DialogueGraphNodeWindow windowNode)
 {
     if (windowNode == _nodeSelected)
     {
         _nodeSelected = null;
     }
 }
    private void DrawNodeProperties(DialogueGraphNodeWindow windowNode)
    {
        var node = windowNode.Node;

        EditorGUI.BeginDisabledGroup(true);
        EditorGUILayout.Toggle("Is root", node.IsRoot);
        EditorGUILayout.IntField("Number of neighbors", node.NumberOfNeighbors);
        EditorGUI.EndDisabledGroup();

        var graphSerializedObject = new SerializedObject(_graph.PartOfComponent);
        var nodesProperty         = graphSerializedObject.GetIterator();

        while (nodesProperty.Next(true))
        {
            if (nodesProperty.name == "_nodesSerialized")
            {
                break;
            }
        }

        int length = nodesProperty.arraySize;

        for (int i = 0; i < length; ++i)
        {
            var nodeProperty = nodesProperty.GetArrayElementAtIndex(i);
            if (nodeProperty.FindPropertyRelative("_id").intValue == node.ID)
            {
                nodeProperty.Next(true);
                nodeProperty.Next(false);
                EditorGUI.BeginChangeCheck();
                nodeProperty.DrawProperty();

                if (EditorGUI.EndChangeCheck() || windowNode.FirstTime)
                {
                    windowNode.FirstTime   = false;
                    windowNode.Rect.height = nodeProperty.GetHeight() + 150f;

                    graphSerializedObject.ApplyModifiedProperties();
                    PrefabUtility.RecordPrefabInstancePropertyModifications(_graph.PartOfComponent);
                }
                return;
            }
        }
    }
    private DialogueGraphNodeWindow GetNodeWindow(DialogueGraph.Node node)
    {
        DialogueGraphNodeWindow.GetNodeWindow(node);

        var temp = DialogueGraphNodeWindow.GetNodeWindow(node);

        if (temp == null)
        {
            temp = _windows.Find(x => x.Node == node);
            if (temp == null)
            {
                _windows.Add(temp = new DialogueGraphNodeWindow(node, _WINDOW_RECT));
            }
            else
            {
                _windows.Remove(temp);
                _windows.Add(temp = new DialogueGraphNodeWindow(temp.Node, temp.Rect));
            }
        }
        return(temp);
    }
 private void DisconnectNodes(DialogueGraphNodeWindow start, DialogueGraphNodeWindow end)
 {
     start.Node.RemoveNeighbor(end.Node);
 }
 private bool ConnectNodes(DialogueGraphNodeWindow start, DialogueGraphNodeWindow end)
 {
     return(start.Node.AddNeighbor(end.Node));
 }
    private void DrawNodeWindowPropertiesAndOptions(DialogueGraphNodeWindow windowNode)
    {
        if (windowNode == _nodeSelected)
        {
            GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), _selectedNodeBackground, ScaleMode.StretchToFill);
            if (GUILayout.Button("Unselect"))
            {
                _nodeSelected = null;
            }
        }
        else
        {
            if (windowNode.Node.IsRoot)
            {
                GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), _rootNodeBackground, ScaleMode.StretchToFill);
            }
            else
            {
                GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), _normalNodeBackground, ScaleMode.StretchToFill);
            }
            if (GUILayout.Button("Select"))
            {
                _nodeSelected = windowNode;
            }
            if (_nodeSelected != null)
            {
                if (GUILayout.Button("Attach", _attachButtonStyle))
                {
                    if (ConnectNodes(_nodeSelected, windowNode))
                    {
                        _nodeSelected = null;
                    }
                }
                if (GUILayout.Button("Detach", _detachButtonStyle))
                {
                    DisconnectNodes(_nodeSelected, windowNode);
                    _nodeSelected = null;
                }
            }
        }
        try
        {
            if (GUILayout.Button("Set as root", _setAsRootButtonStyle))
            {
                windowNode.Node.SetAsRoot();
            }

            DrawNodeProperties(windowNode);

            if (GUILayout.Button("Delete", _deleteButtonStyle))
            {
                if (windowNode.Node.RemoveFromGraph())
                {
                    _windows.Remove(windowNode);
                    ClearSelected(windowNode);
                }
            }


            GUI.DragWindow();
        }
        catch (Exception e)
        {
            Debug.Log("Error:\n" + e);
            if (windowNode.Node.RemoveFromGraph())
            {
                _windows.Remove(windowNode);
                ClearSelected(windowNode);
            }
        }
    }