예제 #1
0
        public void DeselectNode(XNode.INode node)
        {
            List <Object> selection = new List <Object>(Selection.objects);

            selection.Remove(node as UnityEngine.Object);
            Selection.objects = selection.ToArray();
        }
        private bool ShouldBeCulled(XNode.INode node)
        {
            Vector2 nodePos = GridToWindowPositionNoClipped(node.Position);

            if (nodePos.x / _zoom > position.width)
            {
                return(true);                                    // Right
            }
            else if (nodePos.y / _zoom > position.height)
            {
                return(true);                                          // Bottom
            }
            else if (nodeSizes.ContainsKey(node))
            {
                Vector2 size = nodeSizes[node];
                if (nodePos.x + size.x < 0)
                {
                    return(true);                        // Left
                }
                else if (nodePos.y + size.y < 0)
                {
                    return(true);                             // Top
                }
            }
            return(false);
        }
예제 #3
0
 /// <summary> Initiate a rename on the currently selected node </summary>
 public void RenameSelectedNode()
 {
     if (Selection.objects.Length == 1 && Selection.activeObject is XNode.INode)
     {
         XNode.INode node = Selection.activeObject as XNode.INode;
         NodeEditor.GetEditor(node).InitiateRename();
     }
 }
예제 #4
0
        /// <summary> Duplicate selected nodes and select the duplicates </summary>
        public void DuplicateSelectedNodes()
        {
            UnityEngine.Object[] newNodes = new UnityEngine.Object[Selection.objects.Length];
            Dictionary <XNode.INode, XNode.INode> substitutes = new Dictionary <XNode.INode, XNode.INode>();

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                if (Selection.objects[i] is XNode.INode)
                {
                    var srcNode = Selection.objects[i] as XNode.INode;
                    if (srcNode.Graph != graph)
                    {
                        continue;                         // ignore nodes selected in another graph
                    }
                    XNode.INode newNode = graphEditor.CopyNode(srcNode);
                    substitutes.Add(srcNode, newNode);
                    newNode.Position = srcNode.Position + new Vector2(30, 30);
                    newNodes[i]      = newNode as UnityEngine.Object;
                }
            }

            // Walk through the selected nodes again, recreate connections, using the new nodes
            for (int i = 0; i < Selection.objects.Length; i++)
            {
                if (Selection.objects[i] is XNode.INode)
                {
                    XNode.INode srcNode = Selection.objects[i] as XNode.INode;
                    if (srcNode.Graph != graph)
                    {
                        continue;                         // ignore nodes selected in another graph
                    }
                    foreach (XNode.NodePort port in srcNode.Ports)
                    {
                        for (int c = 0; c < port.ConnectionCount; c++)
                        {
                            XNode.NodePort inputPort  = port.direction == XNode.NodePort.IO.Input ? port : port.GetConnection(c);
                            XNode.NodePort outputPort = port.direction == XNode.NodePort.IO.Output ? port : port.GetConnection(c);

                            XNode.INode newNodeIn, newNodeOut;
                            if (substitutes.TryGetValue(inputPort.node, out newNodeIn) && substitutes.TryGetValue(outputPort.node, out newNodeOut))
                            {
                                newNodeIn.UpdateStaticPorts();
                                newNodeOut.UpdateStaticPorts();
                                inputPort  = newNodeIn.GetInputPort(inputPort.fieldName);
                                outputPort = newNodeOut.GetOutputPort(outputPort.fieldName);
                            }
                            if (!inputPort.IsConnectedTo(outputPort))
                            {
                                inputPort.Connect(outputPort);
                            }
                        }
                    }
                }
            }
            Selection.objects = newNodes;
        }
예제 #5
0
 /// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
 public static void PropertyField(SerializedProperty property, GUIContent label, bool includeChildren = true, params GUILayoutOption[] options)
 {
     if (property == null)
     {
         throw new NullReferenceException();
     }
     XNode.INode    node = property.serializedObject.targetObject as XNode.INode;
     XNode.NodePort port = node.GetPort(property.name);
     PropertyField(property, label, port, includeChildren);
 }
예제 #6
0
 public void SelectNode(XNode.INode node, bool add)
 {
     if (add)
     {
         List <Object> selection = new List <Object>(Selection.objects);
         selection.Add(node as UnityEngine.Object);
         Selection.objects = selection.ToArray();
     }
     else
     {
         Selection.objects = new Object[] { node as UnityEngine.Object }
     };
 }
예제 #7
0
 /// <summary> Remove nodes in the graph in Selection.objects</summary>
 public void RemoveSelectedNodes()
 {
     // We need to delete reroutes starting at the highest point index to avoid shifting indices
     selectedReroutes = selectedReroutes.OrderByDescending(x => x.pointIndex).ToList();
     for (int i = 0; i < selectedReroutes.Count; i++)
     {
         selectedReroutes[i].RemovePoint();
     }
     selectedReroutes.Clear();
     foreach (UnityEngine.Object item in Selection.objects)
     {
         if (item is XNode.INode)
         {
             XNode.INode node = item as XNode.INode;
             graphEditor.RemoveNode(node);
         }
     }
 }
예제 #8
0
        private void RecalculateDragOffsets(Event current)
        {
            dragOffset = new Vector2[Selection.objects.Length + selectedReroutes.Count];
            // Selected nodes
            for (int i = 0; i < Selection.objects.Length; i++)
            {
                if (Selection.objects[i] is XNode.INode)
                {
                    XNode.INode node = Selection.objects[i] as XNode.INode;
                    dragOffset[i] = node.Position - WindowToGridPosition(current.mousePosition);
                }
            }

            // Selected reroutes
            for (int i = 0; i < selectedReroutes.Count; i++)
            {
                dragOffset[Selection.objects.Length + i] = selectedReroutes[i].GetPoint() - WindowToGridPosition(current.mousePosition);
            }
        }
예제 #9
0
        /// <summary> Automatically delete Node sub-assets before deleting their script.
        /// <para/> This is important to do, because you can't delete null sub assets. </summary>
        private static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions options)
        {
            // Get the object that is requested for deletion
            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object> (path);

            // If we aren't deleting a script, return
            if (!(obj is UnityEditor.MonoScript))
            {
                return(AssetDeleteResult.DidNotDelete);
            }

            // Check script type. Return if deleting a non-node script
            UnityEditor.MonoScript script     = obj as UnityEditor.MonoScript;
            System.Type            scriptType = script.GetClass();
            if (scriptType == null || (scriptType != typeof(XNode.INode) && !scriptType.IsSubclassOf(typeof(XNode.INode))))
            {
                return(AssetDeleteResult.DidNotDelete);
            }

            // Find all ScriptableObjects using this script
            string[] guids = AssetDatabase.FindAssets("t:" + scriptType);
            for (int i = 0; i < guids.Length; i++)
            {
                string   assetpath = AssetDatabase.GUIDToAssetPath(guids[i]);
                Object[] objs      = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetpath);
                for (int k = 0; k < objs.Length; k++)
                {
                    XNode.INode node = objs[k] as XNode.INode;
                    if (node.GetType() == scriptType)
                    {
                        if (node != null && node.Graph != null)
                        {
                            // Delete the node and notify the user
                            Debug.LogWarning(node.Name + " of " + node.Graph + " depended on deleted script and has been removed automatically.", node.Graph as UnityEngine.Object);
                            node.Graph.RemoveNode(node);
                        }
                    }
                }
            }
            // We didn't actually delete the script. Tell the internal system to carry on with normal deletion procedure
            return(AssetDeleteResult.DidNotDelete);
        }
예제 #10
0
        bool IsHoveringTitle(XNode.INode node)
        {
            Vector2 mousePos = Event.current.mousePosition;
            //Get node position
            Vector2 nodePos = GridToWindowPosition(node.Position);
            float   width;
            Vector2 size;

            if (nodeSizes.TryGetValue(node, out size))
            {
                width = size.x;
            }
            else
            {
                width = 200;
            }
            Rect windowRect = new Rect(nodePos, new Vector2(width / zoom, 30 / zoom));

            return(windowRect.Contains(mousePos));
        }
예제 #11
0
 /// <summary> Draw this node on top of other nodes by placing it last in the graph.nodes list </summary>
 public void MoveNodeToTop(XNode.INode node)
 {
     graph.MoveNodeToTop(node);
 }