/// <summary>
        /// Setup of the base framework. Enough to manage and calculate canvases.
        /// </summary>
        private static void setupBaseFramework()
        {
            CheckEditorPath();

            // Init Resource system. Can be called anywhere else, too, if it's needed before.
            ResourceManager.SetDefaultResourcePath(editorPath + "Resources/");

            // Run fetching algorithms searching the script assemblies for Custom Nodes / Connection Types / NodeCanvas Types
            ConnectionTypes.FetchTypes();
            NodeTypes.FetchNodes();
            NodeCanvasManager.GetAllCanvasTypes();

            // Setup Callback system
            NodeEditorCallbacks.SetupReceivers();
            NodeEditorCallbacks.IssueOnEditorStartUp();

            // Init input
            NodeEditorInputSystem.SetupInput();

                #if UNITY_EDITOR
            UnityEditor.EditorApplication.update -= Update;
            UnityEditor.EditorApplication.update += Update;
                #endif

            initiatedBase = true;
        }
Beispiel #2
0
 private void UpdateCanvasInfo()
 {
     typeData                  = NodeCanvasManager.GetCanvasTypeData(nodeCanvas);
     openedCanvasPath          = nodeCanvas.savePath;
     this.editorState.canvas   = nodeCanvas;
     NodeEditor.curEditorState = this.editorState;
     NodeEditorSaveManager.SetLastCanvasPath(openedCanvasPath);
 }
Beispiel #3
0
        /// <summary>
        /// Creates a node of the specified ID at pos on the specified canvas, optionally auto-connecting the specified output to a matching input
        /// silent disables any events, init specifies whether OnCreate should be called
        /// </summary>
        public static Node Create(string nodeID, Vector2 pos, NodeCanvas hostCanvas, ConnectionPort connectingPort = null, bool silent = false, bool init = true)
        {
            if (string.IsNullOrEmpty(nodeID) || hostCanvas == null)
            {
                throw new ArgumentException();
            }
            if (!NodeCanvasManager.CheckCanvasCompability(nodeID, hostCanvas.GetType()))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' as it is not compatible with the current canavs type (" + hostCanvas.GetType().ToString() + ")!");
            }
            if (!hostCanvas.CanAddNode(nodeID))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' on the current canvas of type (" + hostCanvas.GetType().ToString() + ")!");
            }

            // Create node from data
            NodeTypeData data = NodeTypes.getNodeData(nodeID);
            Node         node = (Node)CreateInstance(data.type);

            if (node == null)
            {
                return(null);
            }

            // Init node state
            node.name     = node.Title;
            node.autoSize = node.DefaultSize;
            node.position = pos;
            node.Canvas   = hostCanvas;
            ConnectionPortManager.UpdateConnectionPorts(node);
            if (init)
            {
                node.OnCreate();
            }

            if (connectingPort != null)
            {             // Handle auto-connection and link the output to the first compatible input
                for (int i = 0; i < node.connectionPorts.Count; i++)
                {
                    if (node.connectionPorts[i].TryApplyConnection(connectingPort, silent))
                    {
                        break;
                    }
                }
            }

            // Add node to host canvas
            hostCanvas.nodes.Add(node);
            if (!silent)
            {             // Callbacks
                hostCanvas.OnNodeChange(connectingPort != null ? connectingPort.body : node);
                NodeEditorCallbacks.IssueOnAddNode(node);
                hostCanvas.Validate();
                NodeEditor.RepaintClients();
            }

            return(node);
        }
        /// <summary>
        /// Creates and loads a new NodeCanvas
        /// </summary>
        public void NewNodeCanvas(Type canvasType = null)
        {
            canvasType = canvasType ?? defaultNodeCanvasType ??             // Pick first canvas in alphabetical order (Calculation usually)
                         NodeCanvasManager.getCanvasDefinitions().OrderBy(c => c.DisplayString).First().CanvasType;
            nodeCanvas = NodeCanvas.CreateCanvas(canvasType);
            NewEditorState();

            openedCanvasPath = "";
            RecreateCache();
            UpdateCanvasInfo();
        }
        private static void FillAddNodes(NodeEditorInputInfo inputInfo, GenericMenu canvasContextMenu)
        {         // Show all nodes, and if a connection is drawn, only compatible nodes to auto-connect
            NodeEditorState state          = inputInfo.editorState;
            List <Node>     displayedNodes = state.connectOutput != null?NodeTypes.getCompatibleNodes(state.connectOutput) : NodeTypes.nodes.Keys.ToList();

            foreach (Node compatibleNode in displayedNodes)
            {
                if (NodeCanvasManager.CheckCanvasCompability(compatibleNode, inputInfo.editorState.canvas.GetType()))
                {
                    canvasContextMenu.AddItem(new GUIContent("Add " + NodeTypes.nodes[compatibleNode].adress), false, CreateNodeCallback, new NodeEditorInputInfo(compatibleNode.GetID, state));
                }
            }
        }
Beispiel #6
0
        private static void FillAddNodes(NodeEditorInputInfo inputInfo, GenericMenu canvasContextMenu)
        {         // Fill context menu with nodes to add to the canvas
            NodeEditorState state = inputInfo.editorState;
            List <string>   nodes = NodeTypes.getCompatibleNodes(state.connectKnob);

            foreach (string node in nodes)
            {             // Only add nodes to the context menu that are compatible
                if (NodeCanvasManager.CheckCanvasCompability(node, inputInfo.editorState.canvas.GetType()) && inputInfo.editorState.canvas.CanAddNode(node))
                {
                    canvasContextMenu.AddItem(new GUIContent("Add " + NodeTypes.getNodeData(node).adress), false, CreateNodeCallback, new NodeEditorInputInfo(node, state));
                }
            }
        }
Beispiel #7
0
        public void ConvertCanvasType(Type newType)
        {
            NodeCanvas canvas = NodeCanvasManager.ConvertCanvasType(nodeCanvas, newType);

            if (canvas != nodeCanvas)
            {
                nodeCanvas = canvas;
                RecreateCache();
                UpdateCanvasInfo();
                nodeCanvas.TraverseAll();
                NodeEditor.RepaintClients();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Create the a Node of the type specified by the nodeID at position
        /// Auto-connects the passed connectingOutput if not null to the first compatible input
        /// </summary>
        public static Node Create(string nodeID, Vector2 position, NodeOutput connectingOutput)
        {
            if (!NodeCanvasManager.CheckCanvasCompability(nodeID, NodeEditor.curNodeCanvas))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' as it is not compatible with the current canavs type (" + NodeEditor.curNodeCanvas.GetType().ToString() + ")!");
            }
            if (!NodeEditor.curNodeCanvas.CanAddNode(nodeID))
            {
                throw new UnityException("Cannot create another Node with ID '" + nodeID + "' on the current canvas of type (" + NodeEditor.curNodeCanvas.GetType().ToString() + ")!");
            }
            Node node = NodeTypes.getDefaultNode(nodeID);

            if (node == null)
            {
                throw new UnityException("Cannot create Node as ID '" + nodeID + "' is not registered!");
            }

            node = node.Create(position);

            if (node == null)
            {
                return(null);
            }

            node.InitBase();

            if (connectingOutput != null)
            {             // Handle auto-connection and link the output to the first compatible input
                foreach (NodeInput input in node.Inputs)
                {
                    if (input.TryApplyConnection(connectingOutput))
                    {
                        break;
                    }
                }
            }

            NodeEditorCallbacks.IssueOnAddNode(node);
            NodeEditor.curNodeCanvas.Validate();

            return(node);
        }
Beispiel #9
0
        public static void InitSystem()
        {
            _inst = AssetDatabase.LoadAssetAtPath <NodeSystemSetting>(ASSET_PATH);
            bool hasExist = _inst != null;

            if (!hasExist)
            {
                _inst = CreateInstance <NodeSystemSetting>();
                AssetDatabase.CreateAsset(_inst, ASSET_PATH);
            }

            ConnectionPortStyles.InitSystem(out _inst.portStyles, out _inst.valueTypes);
            NodeTypes.InitSystem(out _inst.nodeDatas);
            NodeCanvasManager.InitSystem(out _inst.canvasDatas);
            ConnectionPortManager.InitSystem(out _inst.nodePortDec);
            ConnectionPortManager.InitSystem(out _inst.nodePortDec);
            ImportExportManager.InitSystem(out _inst.ioFormats);

            NodeEditorInputSystem.InitSystem(out _inst.eventHandlers, out _inst.hotkeyHandlers, out _inst.contextEntries, out _inst.contextFillers);
        }
 public static void ReInit(bool GUIFunction)
 {
     CheckEditorPath();
     ResourceManager.SetDefaultResourcePath(editorPath + "Resources/");
     if (!NodeEditorGUI.Init(GUIFunction))
     {
         InitiationError = true;
     }
     else
     {
         ConnectionTypes.FetchTypes();
         NodeTypes.FetchNodes();
         NodeCanvasManager.GetAllCanvasTypes();
         NodeEditorCallbacks.SetupReceivers();
         NodeEditorCallbacks.IssueOnEditorStartUp();
         GUIScaleUtility.CheckInit();
         NodeEditorInputSystem.SetupInput();
         initiated = GUIFunction;
     }
 }
Beispiel #11
0
        /// <summary>
        /// Re-Inits the NodeCanvas regardless of whetehr it was initiated before
        /// </summary>
        public static void ReInit(bool GUIFunction)
        {
            CheckEditorPath();

            // Init Resource system. Can be called anywhere else, too, if it's needed before.
            ResourceManager.SetDefaultResourcePath(editorPath + "Resources/");

            // Init NE GUI. I may throw an error if a texture was not found.
            if (!NodeEditorGUI.Init(GUIFunction))
            {
                InitiationError = true;
                return;
            }

            // Run fetching algorithms searching the script assemblies for Custom Nodes / Connection Types
            ConnectionTypes.FetchTypes();
            NodeTypes.FetchNodes();


            NodeCanvasManager.GetAllCanvasTypes();

            // Setup Callback system
            NodeEditorCallbacks.SetupReceivers();
            NodeEditorCallbacks.IssueOnEditorStartUp();

            // Init GUIScaleUtility. This fetches reflected calls and my throw a message notifying about incompability.
            GUIScaleUtility.CheckInit();

            // Init input
            NodeEditorInputSystem.SetupInput();

        #if UNITY_EDITOR
            UnityEditor.EditorApplication.update -= Update;
            UnityEditor.EditorApplication.update += Update;
            RepaintClients();
        #endif
            initiated = GUIFunction;
        }
Beispiel #12
0
 private void UpdateCanvasInfo()
 {
     typeData = NodeCanvasManager.getCanvasTypeData(nodeCanvas);
 }
Beispiel #13
0
        /// <summary>
        /// Creates a copy of the specified node at pos on the specified canvas, optionally auto-connecting the specified output to a matching input
        /// silent disables any events
        /// </summary>
        public static Node CreateCopy(Node toCopy, Vector2 pos, NodeCanvas hostCanvas, ConnectionPort connectingPort = null, bool silent = false)
        {
            if (toCopy == null || hostCanvas == null)
            {
                throw new ArgumentException();
            }
            if (!NodeCanvasManager.CheckCanvasCompability(toCopy.GetID, hostCanvas.GetType()))
            {
                throw new UnityException("Cannot create Node with ID '" + toCopy.GetID + "' as it is not compatible with the current canvas type (" + hostCanvas.GetType().ToString() + ")!");
            }
            if (!hostCanvas.CanAddNode(toCopy.GetID))
            {
                throw new UnityException("Cannot create Node with ID '" + toCopy.GetID + "' on the current canvas of type (" + hostCanvas.GetType().ToString() + ")!");
            }
            Node node = ScriptableObject.Instantiate(toCopy);

            //Clone static connection ports
            foreach (ConnectionPortDeclaration portDecl in ConnectionPortManager.GetPortDeclarationEnumerator(node, true))
            {
                ConnectionPort port = (ConnectionPort)portDecl.portField.GetValue(node);
                port = portDecl.portInfo.CreateNew(node);
                portDecl.portField.SetValue(node, port);
            }
            //Clone dynamic connection ports
            for (int i = 0; i < node.dynamicConnectionPorts.Count; ++i)
            {
                node.dynamicConnectionPorts[i]      = ScriptableObject.Instantiate(node.dynamicConnectionPorts[i]);
                node.dynamicConnectionPorts[i].body = node;
                node.dynamicConnectionPorts[i].ClearConnections();
            }
            ConnectionPortManager.UpdateRepresentativePortLists(node);
            //Clone child SOs
            System.Func <ScriptableObject, ScriptableObject> copySOs = (ScriptableObject so) => ScriptableObject.Instantiate(so);;
            node.CopyScriptableObjects(copySOs);
            if (node == null)
            {
                return(null);
            }

            // Init node state
            node.name     = node.Title;
            node.autoSize = node.DefaultSize;
            node.position = pos;
            ConnectionPortManager.UpdateConnectionPorts(node);

            if (connectingPort != null)
            { // Handle auto-connection and link the output to the first compatible input
                for (int i = 0; i < node.connectionPorts.Count; i++)
                {
                    if (node.connectionPorts[i].TryApplyConnection(connectingPort, silent))
                    {
                        break;
                    }
                }
            }

            // Add node to host canvas
            hostCanvas.nodes.Add(node);
            if (!silent)
            { // Callbacks
                hostCanvas.OnNodeChange(connectingPort != null ? connectingPort.body : node);
                NodeEditorCallbacks.IssueOnAddNode(node);
                hostCanvas.Validate();
                NodeEditor.RepaintClients();
            }

            return(node);
        }
Beispiel #14
0
        /// <summary>
        /// Creates a node of the specified ID at pos on the specified canvas, optionally auto-connecting the specified output to a matching input
        /// silent disables any events, init specifies whether OnCreate should be called
        /// </summary>
        public static Node Create(string nodeID, Vector2 pos, NodeCanvas hostCanvas, ConnectionPort connectingPort = null, bool silent = false, bool init = true)
        {
            if (string.IsNullOrEmpty(nodeID) || hostCanvas == null)
            {
                throw new ArgumentException();
            }
            if (!NodeCanvasManager.CheckCanvasCompability(nodeID, hostCanvas.GetType()))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' as it is not compatible with the current canavs type (" + hostCanvas.GetType().ToString() + ")!");
            }
            if (!hostCanvas.CanAddNode(nodeID))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' on the current canvas of type (" + hostCanvas.GetType().ToString() + ")!");
            }

            // Create node from data
            NodeTypeData data = NodeTypes.getNodeData(nodeID);
            Node         node = (Node)CreateInstance(data.type);

            if (node == null)
            {
                return(null);
            }

            // Init node state
            node.canvas   = hostCanvas;
            node.name     = node.Title;
            node.autoSize = node.DefaultSize;
            node.position = pos;
            ConnectionPortManager.UpdateConnectionPorts(node);
            if (init)
            {
                node.OnCreate();
            }

            if (connectingPort != null)
            {             // Handle auto-connection and link the output to the first compatible input
                for (int i = 0; i < node.connectionPorts.Count; i++)
                {
                    if (node.connectionPorts[i].TryApplyConnection(connectingPort, true))
                    {
                        break;
                    }
                }
            }

            // Add node to host canvas
            hostCanvas.nodes.Add(node);
            if (!silent)
            {             // Callbacks
                hostCanvas.OnNodeChange(connectingPort != null ? connectingPort.body : node);
                NodeEditorCallbacks.IssueOnAddNode(node);
                hostCanvas.Validate();
                NodeEditor.RepaintClients();
            }

#if UNITY_EDITOR
            if (!silent)
            {
                List <ConnectionPort> connectedPorts = new List <ConnectionPort>();
                foreach (ConnectionPort port in node.connectionPorts)
                {                 // 'Encode' connected ports in one list (double level cannot be serialized)
                    foreach (ConnectionPort conn in port.connections)
                    {
                        connectedPorts.Add(conn);
                    }
                    connectedPorts.Add(null);
                }
                Node createdNode = node;
                UndoPro.UndoProManager.RecordOperation(
                    () => NodeEditorUndoActions.ReinstateNode(createdNode, connectedPorts),
                    () => NodeEditorUndoActions.RemoveNode(createdNode),
                    "Create Node");
                // Make sure the new node is in the memory dump
                NodeEditorUndoActions.CompleteSOMemoryDump(hostCanvas);
            }
#endif

            return(node);
        }