Exemplo n.º 1
0
    public NodeView(NodeEditor nodeEditor, NodeGraphData.NodeData nodeData)
    {
        this.NodeEditor  = nodeEditor;
        this.nodeData    = nodeData;
        serializedObject = new SerializedObject(nodeData.nodeObject);

        var iterator = serializedObject.GetIterator();

        if (iterator.NextVisible(true))
        {
            FindConnectionsRecursive(iterator);
        }
    }
Exemplo n.º 2
0
    void SetupNodeContextMenuItems(NodeGraphData.NodeData nodeData, GenericMenu genericMenu)
    {
        genericMenu.AddItem(new GUIContent("Delete/Confirm"), false, () =>
        {
            GetNodeGraphData(CurrentTarget).DeleteNode(nodeData.nodeObject);
            nodeViews.Remove(nodeData);
        });

        foreach (var scriptableObject in GetSerializedScriptableObjectFields())
        {
            if (scriptableObject.FieldType.IsAssignableFrom(nodeData.nodeObject.GetType()))
            {
                genericMenu.AddItem(new GUIContent("Set as/" + scriptableObject.Name), false, () =>
                {
                    Undo.RecordObject(CurrentTarget, "Changed exposed node");
                    scriptableObject.SetValue(CurrentTarget, nodeData.nodeObject);
                    EditorUtility.SetDirty(CurrentTarget);
                });
            }
        }
    }
Exemplo n.º 3
0
    // TODO: Allow user, via a menu option, to specify that a specific type of scriptable object should be opened on double click.

    /*[OnOpenAssetAttribute(1)]
     * public static bool OnOpenAsset(int instanceID, int line)
     * {
     *      var targetObject = EditorUtility.InstanceIDToObject(instanceID) as ScriptableObject;
     *      if (targetObject != null)
     *      {
     *              if (targetObject.GetType().GetCustomAttributes(typeof(NodeGraphAttribute), true).Count() == 0)
     *                      return false;
     *
     *              OpenWindow(targetObject);
     *              return true;
     *      }
     *
     *      return false;
     * }*/

    NodeView GetNodeView(NodeGraphData.NodeData nodeData)
    {
        NodeView nodeView;

        if (nodeViews.TryGetValue(nodeData, out nodeView))
        {
            if (nodeView.NodeObject == null)
            {
                nodeViews.Remove(nodeData);
                return(GetNodeView(nodeData));
            }

            return(nodeView);
        }

        var newNodeView = new NodeView(this, nodeData);

        SetupNodeView(newNodeView, nodeData);
        nodeViews[nodeData] = newNodeView;
        return(newNodeView);
    }
Exemplo n.º 4
0
    public Rect GetNodeViewRect(NodeGraphData.NodeData nodeData)
    {
        var view = nodeViews.FirstOrDefault(x => x.Key == nodeData).Value;

        return(view != null?view.GetWindowRect() : default(Rect));
    }
Exemplo n.º 5
0
 void SetupNodeView(NodeView nodeView, NodeGraphData.NodeData nodeData)
 {
     nodeView.OnShowContextMenu += (genericMenu) => SetupNodeContextMenuItems(nodeData, genericMenu);
 }