Exemple #1
0
    private void DrawPlusButtonsOnNode(VisualNodeBase node, int i)
    {
        var   childIndex     = i;
        var   butLabel       = i < node.ChildrenLabelsInEditor().Length ? node.ChildrenLabelsInEditor()[i] : "+";
        float windowFraction = node.windowPosition.height / node.ChildMax();
        var   butRect        = new Rect(
            node.windowPosition.xMax,
            node.windowPosition.y + (i) * (windowFraction) + windowFraction / 2 - 10,
            Mathf.Min(10 * butLabel.Length + 10, 50),
            20);

        if (GUI.Button(butRect, butLabel))
        {
            new VisualNodeEditorContextMenu((nodeType) =>
            {
                var newNode            = new VisualNodeAssetHelper().CreateNodeAsset(_currentRoot, nodeType);
                newNode.windowPosition = new Rect(node.windowPosition.xMax + 20, node.windowPosition.y, 150, 0);
                newNode.parent         = node;
                node.children.RemoveAt(childIndex);
                node.children.Insert(childIndex, newNode);
                _currentRoot.nodes.Add(newNode);
                SaveRootAsset();
                SetNodeForSaving(node);
                SetNodeForSaving(newNode);
            }).ShowMenu();
        }
    }
Exemple #2
0
    private void DrawNodeWindows()
    {
        _nodeIndex = 0;
        BeginWindows();
        for (int i = 0; i < _currentRoot.nodes.Count(); i++)
        {
            var node = _currentRoot.nodes[i];
            DrawNodeDecorations(node);
            if (node.parent == null && _currentRoot.root != node && !_isConnecting)
            {
                if (GUI.Button(new Rect(node.windowPosition.x - 18, node.windowPosition.center.y - 10, 20, 20), "P"))
                {
                    _isConnecting   = true;
                    _parentlessNode = node;
                }
            }
            if (node.parent != null)
            {
                if (GUI.Button(new Rect(node.windowPosition.x - 18, node.windowPosition.center.y - 10, 20, 16), "×"))
                {
                    var index = node.parent.children.IndexOf(node);
                    node.parent.children.RemoveAt(index);
                    node.parent.children.Insert(index, null);
                    node.parent = null;
                }
            }

            fullEditorSize.xMax = Mathf.Max(fullEditorSize.xMax, node.windowPosition.xMax);
            fullEditorSize.yMax = Mathf.Max(fullEditorSize.yMax, node.windowPosition.yMax);
        }
        EndWindows();
    }
Exemple #3
0
    public void DeleteNodes(VisualNodeBase node, VisualNodeRoot root)
    {
        if (node == root.root)
        {
            root.root = null;
        }

        //enter on children
        var childCount = node.children.Count();

        for (int i = childCount - 1; i >= 0; i--)
        {
            if (node.children[i] != null)
            {
                node.children[i].parent = null;
                //DeleteNodesRecursive(node.children[i], root);
            }
        }
        //remove from parent
        if (node.parent != null)
        {
            var index = node.parent.children.IndexOf(node);
            node.parent.children.RemoveAt(index);
            node.parent.children.Insert(index, null);
        }

        root.nodes.Remove(node);
        EditorUtility.SetDirty(root);

        //delete asset
        UnityEngine.Object.DestroyImmediate(node, true);
        AssetDatabase.SaveAssets();
    }
Exemple #4
0
    private void DrawDeleteButton(VisualNodeBase node)
    {
        if (_isConnecting)
        {
            return;
        }
        if (GUI.Button(new Rect(0, 0, 25, 16), "×"))
        {
            new VisualNodeAssetHelper().DeleteNodes(node, _currentRoot);
            AssetDatabase.SaveAssets();
        }

        if (GUI.Button(new Rect(node.windowPosition.width - 50, 0, 50, 16), "×Rec"))
        {
            if (EditorUtility.DisplayDialog("Recursive delete", "This will delete nodes recurssively. Are you sure you want to continue?", "Yes", "Cancel"))
            {
                new VisualNodeAssetHelper().DeleteNodesRecursive(node, _currentRoot);
                AssetDatabase.SaveAssets();
            }
        }
    }
Exemple #5
0
    private void DrawNodeWindow(int id)
    {
        VisualNodeBase node = null;

        _nodeWindowDictionary.TryGetValue(id, out node);
        if (node != null)
        {
            DrawDeleteButton(node);
            EditorGUI.BeginChangeCheck();
            try{
                Editor.CreateEditor(node).OnInspectorGUI();
            }catch (Exception e)
            {
                return;
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(node);
            }
        }
        GUI.DragWindow();
    }
Exemple #6
0
    void DrawNodeDecorations(VisualNodeBase node)
    {
        _nodeIndex++;
        _nodeWindowDictionary[_nodeIndex] = node;
        var newPos = GUILayout.Window(_nodeIndex, node.windowPosition, DrawNodeWindow, node.GetType().Name);

        if (newPos != node.windowPosition)
        {
            EditorUtility.SetDirty(node);
        }
        node.windowPosition   = newPos;
        node.windowPosition.x = Mathf.Clamp(node.windowPosition.x, 0f, node.windowPosition.x);
        node.windowPosition.y = Mathf.Clamp(node.windowPosition.y, 0F, node.windowPosition.y);
        node.VerifyChildrenVectorSize();
        for (int i = 0; i < node.ChildMax(); i++)
        {
            if (node.children[i] == null)
            {
                DrawPlusButtonsOnNode(node, i);
            }
        }
    }
Exemple #7
0
 private void SetNodeForSaving(VisualNodeBase node)
 {
     EditorUtility.SetDirty(node);
 }