コード例 #1
0
    public void LoadNodeCanvas(string path)
    {
        // Else it will be stuck forever
        NodeEditor.StopTransitioning (canvas);

        // Load the NodeCanvas
        canvas = NodeEditorSaveManager.LoadNodeCanvas (path);
        if (canvas == null)
        {
            NewNodeCanvas ();
            return;
        }

        // Load the associated MainEditorState
        List<NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates (path);
        if (editorStates.Count == 0)
            state = ScriptableObject.CreateInstance<NodeEditorState> ();
        else
        {
            state = editorStates.Find (x => x.name == "MainEditorState");
            if (state == null) state = editorStates[0];
        }
        state.canvas = canvas;

        NodeEditor.RecalculateAll (canvas);
    }
コード例 #2
0
 public void NewNodeCanvas()
 {
     // New NodeCanvas
     canvas = ScriptableObject.CreateInstance<NodeCanvas> ();;
     // New NodeEditorState
     state = ScriptableObject.CreateInstance<NodeEditorState> ();
     state.canvas = canvas;
     state.name = "MainEditorState";
 }
コード例 #3
0
	public void LoadNodeCanvas (string path) 
	{
		// Load the NodeCanvas
		canvas = NodeEditor.LoadNodeCanvas (path);
		if (canvas == null)
			canvas = ScriptableObject.CreateInstance<NodeCanvas> ();
		
		// Load the associated MainEditorState
		List<NodeEditorState> editorStates = NodeEditor.LoadEditorStates (path);
		if (editorStates.Count == 0)
			state = ScriptableObject.CreateInstance<NodeEditorState> ();
		else 
		{
			state = editorStates.Find (x => x.name == "MainEditorState");
			if (state == null)
				state = editorStates[0];
		}
		
		NodeEditor.RecalculateAll (canvas);
	}
コード例 #4
0
    /// <summary>
    /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
    /// </summary>
    public void LoadNodeCanvas(string path)
    {
        // Load the NodeCanvas
        NodeCanvas nodeCanvas = NodeEditor.LoadNodeCanvas (path);
        if (nodeCanvas == null)
            return;
        mainNodeCanvas = nodeCanvas;

        // Load the associated MainEditorState
        List<NodeEditorState> editorStates = NodeEditor.LoadEditorStates (path);
        mainEditorState = editorStates.Find (x => x.name == "MainEditorState");
        if (mainEditorState == null)
            mainEditorState = CreateInstance<NodeEditorState> ();

        // Set some editor properties
        string[] folders = path.Split (new char[] {'/'}, StringSplitOptions.None);
        openedCanvas = folders [folders.Length-1];
        openedCanvasPath = path;

        NodeEditor.RecalculateAll (mainNodeCanvas);
        Repaint ();
    }
コード例 #5
0
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadNodeCanvas(string path)
        {
            // Else it will be stuck forever
            NodeEditor.StopTransitioning(mainNodeCanvas);

            // Load the NodeCanvas
            mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true);
            if (mainNodeCanvas == null)
            {
                Debug.Log("Error loading NodeCanvas from '" + path + "'!");
                NewNodeCanvas();
                return;
            }

            // Load the associated MainEditorState
            List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path, true);

            if (editorStates.Count == 0)
            {
                mainEditorState = ScriptableObject.CreateInstance <NodeEditorState> ();
                Debug.LogError("The save file '" + path + "' did not contain an associated NodeEditorState!");
            }
            else
            {
                mainEditorState = editorStates.Find(x => x.name == "MainEditorState");
                if (mainEditorState == null)
                {
                    mainEditorState = editorStates[0];
                }
            }
            mainEditorState.canvas = mainNodeCanvas;

            openedCanvasPath = path;
            NodeEditor.RecalculateAll(mainNodeCanvas);
            SaveCache();
            Repaint();
        }
コード例 #6
0
        void OnSaveCanvas(NodeCanvas canvas)
        {
            if (canvas != null)
            {
                List <FSMElement> elementlist = new List <FSMElement>();
                List <Node>       nodelist    = new List <Node>();
                for (int i = 0; i < canvas.nodes.Count; ++i)
                {
                    Node nd = canvas.nodes[i];
                    if (nd is FSMElement)
                    {
                        elementlist.Add(nd as FSMElement);
                    }
                    else
                    {
                        nodelist.Add(nd);
                    }
                }

                if (elementlist.Count > 0)
                {
                    elementlist.Sort((a, b) =>
                    {
                        return(a.Priority - b.Priority);
                    });

                    canvas.nodes.Clear();
                    for (int i = 0; i < elementlist.Count; ++i)
                    {
                        canvas.nodes.Add(elementlist[i]);
                    }

                    canvas.nodes.AddRange(nodelist);
                }
            }
        }
コード例 #7
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
    /// <summary>
    /// Context Click selection. Here you'll need to register your own using a string identifier
    /// </summary>
    public static void ContextCallback(object obj)
    {
        callbackObject cbObj = obj as callbackObject;
        curNodeCanvas = cbObj.canvas;
        curEditorState = cbObj.editor;

        switch (cbObj.message)
        {
        case "deleteNode":
            if (cbObj.node != null)
                cbObj.node.Delete ();
            break;

        case "duplicateNode":
            if (cbObj.node != null)
            {
                ContextCallback (new callbackObject (cbObj.node.GetID, curNodeCanvas, curEditorState));
                Node duplicatedNode = curNodeCanvas.nodes [curNodeCanvas.nodes.Count-1];
                curEditorState.activeNode = duplicatedNode;
                curEditorState.dragNode = true;
            }
            break;

        default:
            foreach (Node node in NodeTypes.nodes)
            {
                if (node.GetID == cbObj.message)
                {
                    node.Create (ScreenToGUIPos (mousePos)).InitBase ();
                    break;
                }
            }
            break;
        }
    }
コード例 #8
0
 public CanvasCalculator(NodeCanvas canvas) : base(canvas)
 {
 }
コード例 #9
0
 /// <summary>
 /// Exports the given simplified canvas data to the location specified in the args (usually string[1] containing the path)
 /// </summary>
 public abstract void Export(NodeCanvas canvas, params object[] locationArgs);
コード例 #10
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            BehaviourTreeAgent agent = target as BehaviourTreeAgent;

            if (agent.tree == null)
            {
                return;
            }
            if (NodeEditor.curNodeCanvas == null || NodeEditor.curNodeCanvas.savePath != agent.tree.savePath)
            {
                BehaviourTree.selectedAgent = agent;
                NodeEditor.ReInit(false);
                NodeCanvas c = NodeEditorSaveManager.CreateWorkingCopy(agent.tree);
                NodeEditor.curNodeCanvas = c;
                NodeEditorWindow.editor.canvasCache.SetCanvas(c);
            }
            if (agent.gameObjectParameters != null)
            {
                objectFold = EditorGUILayout.Foldout(objectFold, "Game Objects");
                if (objectFold)
                {
                    List <string> keys = new List <string>(agent.gameObjectParameters.Keys);
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.gameObjectParameters[key] = EditorGUILayout.ObjectField(agent.gameObjectParameters[key], typeof(GameObject), true) as GameObject;
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.floatParameters != null)
            {
                floatFold = EditorGUILayout.Foldout(floatFold, "Floats");
                List <string> keys = new List <string>(agent.floatParameters.Keys);
                if (floatFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.floatParameters[key] = EditorGUILayout.FloatField(agent.floatParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.integerParameters != null)
            {
                integerFold = EditorGUILayout.Foldout(integerFold, "Integers");
                List <string> keys = new List <string>(agent.integerParameters.Keys);
                if (integerFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.integerParameters[key] = EditorGUILayout.IntField(agent.integerParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            if (agent.boolParameters != null)
            {
                boolFold = EditorGUILayout.Foldout(boolFold, "Booleans");
                List <string> keys = new List <string>(agent.boolParameters.Keys);
                if (boolFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(key);
                        agent.boolParameters[key] = EditorGUILayout.Toggle(agent.boolParameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            if (agent.vector3Parameters != null)
            {
                vectorFold = EditorGUILayout.Foldout(vectorFold, "Vectors");
                List <string> keys = new List <string>(agent.vector3Parameters.Keys);
                if (vectorFold)
                {
                    foreach (string key in keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        agent.vector3Parameters[key] = EditorGUILayout.Vector3Field(key, agent.vector3Parameters[key]);
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Converts the simplified CanvasData back to a proper NodeCanvas
        /// </summary>
        internal static NodeCanvas ConvertToNodeCanvas(CanvasData canvasData)
        {
            if (canvasData == null)
            {
                return(null);
            }
            NodeCanvas nodeCanvas = NodeCanvas.CreateCanvas(canvasData.type);

            nodeCanvas.name = nodeCanvas.saveName = canvasData.name;
            nodeCanvas.nodes.Clear();
            NodeEditor.BeginEditingCanvas(nodeCanvas);

            foreach (NodeData nodeData in canvasData.nodes.Values)
            {             // Read all nodes
                Node node = Node.Create(nodeData.typeID, nodeData.nodePos, null, true, false);
                if (!string.IsNullOrEmpty(nodeData.name))
                {
                    node.name = nodeData.name;
                }
                if (node == null)
                {
                    continue;
                }

                foreach (ConnectionPortDeclaration portDecl in ConnectionPortManager.GetPortDeclarationEnumerator(node))
                {                         // Find stored ports for each node port declaration
                    PortData portData = nodeData.connectionPorts.Find((PortData data) => data.name == portDecl.portField.Name);
                    if (portData != null) // Stored port has been found, record
                    {
                        portData.port = (ConnectionPort)portDecl.portField.GetValue(node);
                    }
                }

                foreach (PortData portData in nodeData.connectionPorts.Where(port => port.dynamic))
                {                              // Find stored dynamic connection ports
                    if (portData.port != null) // Stored port has been recreated
                    {
                        portData.port.body = node;
                        node.dynamicConnectionPorts.Add(portData.port);
                    }
                }

                foreach (VariableData varData in nodeData.variables)
                {                 // Restore stored variable to node
                    FieldInfo field = node.GetType().GetField(varData.name);
                    if (field != null)
                    {
                        field.SetValue(node, varData.refObject != null ? varData.refObject.data : varData.value);
                    }
                }
            }

            foreach (ConnectionData conData in canvasData.connections)
            {             // Restore all connections
                if (conData.port1.port == null || conData.port2.port == null)
                {         // Not all ports where saved in canvasData
                    LogMgr.Log("Incomplete connection " + conData.port1.name + " and " + conData.port2.name + "!");
                    continue;
                }
                conData.port1.port.TryApplyConnection(conData.port2.port, true);
            }

            foreach (GroupData groupData in canvasData.groups)
            {             // Recreate groups
                NodeGroup group = new NodeGroup();
                group.title = groupData.name;
                group.rect  = groupData.rect;
                group.color = groupData.color;
                nodeCanvas.groups.Add(group);
            }

            nodeCanvas.editorStates = new NodeEditorState[canvasData.editorStates.Length];
            for (int i = 0; i < canvasData.editorStates.Length; i++)
            {             // Read all editorStates
                EditorStateData stateData = canvasData.editorStates[i];
                NodeEditorState state     = ScriptableObject.CreateInstance <NodeEditorState>();
                state.selectedNode         = stateData.selectedNode == null ? null : canvasData.FindNode(stateData.selectedNode.nodeID).node;
                state.panOffset            = stateData.panOffset;
                state.zoom                 = stateData.zoom;
                state.canvas               = nodeCanvas;
                state.name                 = "EditorState";
                nodeCanvas.editorStates[i] = state;
            }

            NodeEditor.EndEditingCanvas();
            return(nodeCanvas);
        }
コード例 #12
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
 public callbackObject(string Message, NodeCanvas nodecanvas, NodeEditorState editorState, Node Node)
 {
     message = Message;
     canvas = nodecanvas;
     editor = editorState;
     node = Node;
 }
コード例 #13
0
ファイル: GroupNode.cs プロジェクト: zhangf911/Node_Editor
	public override void NodeGUI () 
	{
		GUILayout.BeginHorizontal ();
#if UNITY_EDITOR
		if (GUILayout.Button (new GUIContent ("Load", "Loads the group from an extern Canvas Asset File.")))
		{
			string path = UnityEditor.EditorUtility.OpenFilePanel ("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
			if (!path.Contains (Application.dataPath)) 
			{
				// TODO: Generic Notification
				//if (path != String.Empty)
					//ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
				return;
			}
			path = path.Replace (Application.dataPath, "Assets");

			nodeGroupCanvas = NodeEditor.LoadNodeCanvas (path);

			editorState = NodeEditor.LoadEditorStates (path) [0];
			editorState.drawing = edit;

			if (nodeGroupCanvas != null) 
			{ // Set the name
				string[] folders = path.Split (new char[] {'/'}, StringSplitOptions.None);
				string canvasName = folders [folders.Length-1];
				if (canvasName.EndsWith (".asset"))
					canvasName = canvasName.Remove (canvasName.Length-6);
				name = canvasName;
			}
			else 
				name = "Node Group";

			//AdoptInputsOutputs ();
		}
		if (GUILayout.Button (new GUIContent ("Save", "Saves the group as a new Canvas Asset File"))) 
		{
			NodeEditor.SaveNodeCanvas (nodeGroupCanvas, UnityEditor.EditorUtility.SaveFilePanelInProject ("Save Group Node Canvas", "Group Canvas", "asset", 
			                                                                                              "Saving to a file is only needed once.", NodeEditor.editorPath + "Saves/"));
		}
#endif
		if (GUILayout.Button (new GUIContent ("New Group Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)"))) 
		{
			nodeGroupCanvas = CreateInstance<NodeCanvas> ();

			editorState = CreateInstance<NodeEditorState> ();
			editorState.drawing = edit;
			editorState.name = "GroupNode_EditorState";
		}
		GUILayout.EndHorizontal ();

		foreach (NodeInput input in Inputs)
			input.DisplayLayout ();

		foreach (NodeOutput output in Outputs)
			output.DisplayLayout ();

		if (!edit && nodeGroupCanvas != null)
		{
			if (GUILayout.Button ("Edit Node Canvas"))
			{
				rect = openedRect;
				edit = true;
				editorState.canvasRect = GUILayoutUtility.GetRect (canvasSize.x, canvasSize.y, GUIStyle.none);
				editorState.drawing = true;
			}
		}
		else if (nodeGroupCanvas != null)
		{
			if (GUILayout.Button ("Stop editing Node Canvas"))
			{
				nodeRect.position = openedRect.position + new Vector2 (canvasSize.x/2 - nodeRect.width/2, 0);
				rect = nodeRect;
				edit = false;
				editorState.drawing = false;
			}

			editorState.canvasRect = GUILayoutUtility.GetRect (canvasSize.x - 200, canvasSize.y, new GUILayoutOption[] { GUILayout.ExpandWidth (false) });
			NodeEditor.curEditorState.ignoreInput.Add (NodeEditor.GUIToScreenRect (editorState.canvasRect));
			NodeEditor.DrawSubCanvas (nodeGroupCanvas, editorState);

			GUILayout.BeginArea (new Rect (canvasSize.x - 200 + 2, editorState.canvasRect.y + 42, 200, canvasSize.y), GUI.skin.box);

			GUILayout.Label (new GUIContent ("Node Editor (" + nodeGroupCanvas.name + ")", "The currently opened canvas in the Node Editor"));

			GUILayout.EndArea ();


			// Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
		}
	}
コード例 #14
0
 //Invoke by DialogHolder only
 public void setConvo(NodeCanvas canvas, Node root)
 {
     conversation = canvas;
     currentNode  = root;
 }
コード例 #15
0
 public NodeCanvasRenderer(NodeCanvas canvas)
 {
     this.canvas = canvas;
 }
コード例 #16
0
 public CanvasInputHandler(NodeCanvas nodeCanvas)
 {
     _nodeCanvas = nodeCanvas;
 }
コード例 #17
0
        bool FixupForSubCanvas()
        {
            if (!string.IsNullOrEmpty(m_CanvasGuid) && m_SubCanvas == null)
            {
                string nodeCanvasPath = AssetDatabase.GUIDToAssetPath(m_CanvasGuid);

                m_SubCanvas = NodeEditorSaveManager.LoadNodeCanvas(nodeCanvasPath, false);
                m_WasCloned = false;
            }

            if (m_SubCanvas != null)
            {
                if (!m_WasCloned)
                {
                    m_SubCanvas = NodeEditorSaveManager.CreateWorkingCopy(m_SubCanvas, false); //miked remove ref
                    m_WasCloned = true;

/* test its making unique nodes
 *                  foreach (Node n in m_SubCanvas.nodes)
 *                  {
 *                      if (n is TextureNode)
 *                      {
 *                          var tnIn = n as TextureNode;
 *                          var was = tnIn.m_TexHeight;
 *                          tnIn.m_TexHeight = Random.Range(1000, 1500);
 *                          Debug.Log("Change sub routines node" + tnIn + "  tex height to  " + tnIn.m_TexHeight + " was " + was);
 *
 *                      }
 *                  }
 */
                }

                List <NodeInput>   needsInput  = new List <NodeInput>();
                List <TextureNode> needsOutput = new List <TextureNode>();
                foreach (Node n in m_SubCanvas.nodes)
                {
                    if (n.Inputs.Count > 0)
                    {
                        if (n is UnityTextureOutput && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        if (n is UnityTextureOutputMetalicAndRoughness && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        for (int i = 0; i < n.Inputs.Count; i++)
                        {
                            if (n.Inputs[i].connection == null)
                            {
                                //this node has no input so we will wire it up to ours
                                needsInput.Add(n.Inputs[i]);
                                //                            Debug.Log(" missing input for node "+n+" name "+n.name);
                            }
                        }
                    }
                }
                if (needsOutput.Count > Outputs.Count)
                {
                    while (needsOutput.Count > Outputs.Count)
                    {
                        //                    Debug.Log(" create input "+Inputs.Count);

                        string nname = GetNodeOutputName(needsOutput[Outputs.Count]);

                        CreateOutput("Texture" + Outputs.Count + " " + nname, needsOutput[Outputs.Count].Inputs[0].connection.typeID, NodeSide.Right, 50 + Outputs.Count * 20);
                    }
                }
                if (needsOutput.Count > 0)
                {
                    Outputs[0].name = "Texture0" + " " + GetNodeOutputName(needsOutput[0]);
                }

                if (needsInput.Count > Inputs.Count)
                {
                    int added = 0;



                    for (int index = Inputs.Count; index < needsInput.Count; index++)
                    {
                        string needInputname = needsInput[index].name;
                        //                    Debug.Log(" create input "+Inputs.Count);
                        NodeInput newInput = CreateInput(needInputname, needsInput[index].typeID, NodeSide.Left, 30 + Inputs.Count * 20);
                        if (newInput.typeID == "Float")
                        {
                            var n = Node.Create("inputNode", rect.position - new Vector2(100, 50 - added * 60));
                            added++;
                            InputNode inode = n as InputNode;
                            if (inode != null)
                            {
                                newInput.ApplyConnection(inode.Outputs[0], false);
                                InputNode ip = (InputNode)n;
                                Node      nodeThatNeedsInput = needsInput[index].body;
                                //Use reflection to find the float remap member var that matches the input
                                FieldInfo[] myField = nodeThatNeedsInput.GetType().GetFields();
                                foreach (var x in myField)
                                {
                                    // if(x.FieldType is FloatRemap)
                                    if (x.GetValue(nodeThatNeedsInput) is FloatRemap)
                                    {
                                        FloatRemap fr = (FloatRemap)x.GetValue(nodeThatNeedsInput); //its a struct this makes a copy
                                        //                Debug.Log(x + " " + x.FieldType + " " + x.GetType() + " " + x.ReflectedType+" fr val:"+fr.m_Value);
                                        if (fr.m_ReplaceWithInput && fr.m_Replacement == null)
                                        {
                                            Debug.LogError(" wants to be replaced but isnt linked ");
                                        }
                                        else if (fr.m_Replacement != null)
                                        {
                                            NodeKnob  knob    = fr.m_Replacement;
                                            NodeInput replace = knob as NodeInput;
                                            if (replace != null)
                                            {
                                                if (replace == needsInput[index])
                                                {
                                                    ip.m_Value.Set(fr.m_Value);
                                                    ip.m_Value.m_Min = fr.m_Min;
                                                    ip.m_Value.m_Max = fr.m_Max;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    m_InputsCreated = true;
                    //CreateNewFloatInputs();
                    return(false);
                }
            }
            return(true);
        }
コード例 #18
0
ファイル: GroupNode.cs プロジェクト: suimisu/Node_Editor
    public override void NodeGUI()
    {
        GUILayout.BeginHorizontal ();
        if (GUILayout.Button (new GUIContent ("Load", "Loads the group from an extern Canvas Asset File.")))
        {
        #if UNITY_EDITOR
            string path = UnityEditor.EditorUtility.OpenFilePanel ("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
            if (!path.Contains (Application.dataPath))
            {
                if (path != String.Empty)
                    NodeEditorWindow.editor.ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
                return;
            }
            path = path.Replace (Application.dataPath, "Assets");

            if (nodeGroupCanvas != null)
                NodeEditor.curNodeCanvas.childs.Remove (nodeGroupCanvas);
            nodeGroupCanvas = NodeEditor.LoadNodeCanvas (path);
            nodeGroupCanvas.parent = NodeEditor.curNodeCanvas;
            NodeEditor.curNodeCanvas.childs.Add (nodeGroupCanvas);

            if (editorState != null)
                NodeEditor.curEditorState.childs.Remove (editorState);
            editorState = NodeEditor.LoadEditorStates (path) [0];
            editorState.parent = NodeEditor.curEditorState;
            editorState.drawing = edit;
            NodeEditor.curEditorState.childs.Add (editorState);

            if (nodeGroupCanvas != null)
            { // Set the name
                string[] folders = path.Split (new char[] {'/'}, StringSplitOptions.None);
                string canvasName = folders [folders.Length-1];
                if (canvasName.EndsWith (".asset"))
                    canvasName = canvasName.Remove (canvasName.Length-6);
                name = canvasName;
            }
            else
                name = "Node Group";
            //AdoptInputsOutputs ();
        #endif
        }
        if (GUILayout.Button (new GUIContent ("Save", "Saves the group as a new Canvas Asset File")))
        {
        #if UNITY_EDITOR
            NodeEditor.SaveNodeCanvas (nodeGroupCanvas, UnityEditor.EditorUtility.SaveFilePanelInProject ("Save Group Node Canvas", "Group Canvas", "asset",
                                                                                                          "Saving to a file is only needed once.", NodeEditor.editorPath + "Saves/"));
        #endif
        }
        if (GUILayout.Button (new GUIContent ("New Group Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)")))
        {
            if (nodeGroupCanvas != null)
                NodeEditor.curNodeCanvas.childs.Remove (nodeGroupCanvas);
            nodeGroupCanvas = CreateInstance<NodeCanvas> ();
            nodeGroupCanvas.parent = NodeEditor.curNodeCanvas;
            NodeEditor.curNodeCanvas.childs.Add (nodeGroupCanvas);

            if (editorState != null)
                NodeEditor.curEditorState.childs.Remove (editorState);
            editorState = CreateInstance<NodeEditorState> ();
            editorState.parent = NodeEditor.curEditorState;
            editorState.drawing = edit;
            NodeEditor.curEditorState.childs.Add (editorState);
            editorState.name = "GroupNode_EditorState";
        }
        GUILayout.EndHorizontal ();

        foreach (NodeInput input in Inputs)
            input.DisplayLayout ();

        foreach (NodeOutput output in Outputs)
            output.DisplayLayout ();

        if (!edit && nodeGroupCanvas != null)
        {
            if (GUILayout.Button ("Edit Node Canvas"))
            {
                rect = openedRect;
                edit = true;
                editorState.canvasRect = canvasRect;
                editorState.drawing = true;
            }
        }
        else if (nodeGroupCanvas != null)
        {
            editorState.canvasRect = canvasRect;
            if (GUILayout.Button ("Stop editing Node Canvas"))
            {
                nodeRect.position = openedRect.position + new Vector2 (canvasSize.x/2 - nodeRect.width/2, 0);
                rect = nodeRect;
                edit = false;
                editorState.drawing = false;
            }
            // Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
        }
    }
コード例 #19
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
    /// <summary>
    /// Returns the node at the position in specified canvas space.
    /// </summary>
    public static Node NodeAtPosition(NodeEditorState editorState, NodeCanvas nodecanvas, Vector2 pos)
    {
        if (!editorState.canvasRect.Contains (pos))
            return null;

        // Check if we clicked inside a window (or knobSize pixels left or right of it at outputs, for faster knob recognition)
        float KnobSize = (float)NodeEditor.knobSize/editorState.zoom;
        if (editorState.activeNode != null)
        { // active Node is drawn ontop, so we check it first
            Rect NodeRect = new Rect (GUIToScreenRect (editorState.activeNode.rect));
            NodeRect = new Rect (NodeRect.x - KnobSize, NodeRect.y, NodeRect.width + KnobSize*2, NodeRect.height);
            if (NodeRect.Contains (pos))
                return editorState.activeNode;
        }
        for (int nodeCnt = nodecanvas.nodes.Count-1; nodeCnt >= 0; nodeCnt--)
        { // checked from top to bottom because of the render order
            Rect NodeRect = new Rect (GUIToScreenRect (nodecanvas.nodes [nodeCnt].rect));
            NodeRect = new Rect (NodeRect.x - KnobSize, NodeRect.y, NodeRect.width + KnobSize*2, NodeRect.height);
            if (NodeRect.Contains (pos))
                return nodecanvas.nodes [nodeCnt];
        }
        return null;
    }
コード例 #20
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
 /// <summary>
 /// Recalculate from every Input Node.
 /// Usually does not need to be called at all, the smart calculation system is doing the job just fine.
 /// Option to not recalculate the inputs, when they are already set manually
 /// </summary>
 public static void RecalculateAll(NodeCanvas nodeCanvas, bool calculateInputs)
 {
     workList = new List<Node> ();
     foreach (Node node in nodeCanvas.nodes)
     {
         if (node.Inputs.Count == 0)
         { // Add all Inputs
             if (calculateInputs)
             {
                 ClearCalculation (node);
                 workList.Add (node);
             }
             else
             {
                 foreach (NodeOutput output in node.Outputs)
                 {
                     for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
                     {
                         ClearCalculation (output.connections [conCnt].body);
                         workList.Add (output.connections [conCnt].body);
                     }
                 }
             }
         }
     }
     StartCalculation ();
 }
コード例 #21
0
 public CanvasData(NodeCanvas nodeCanvas)
 {
     canvas = nodeCanvas;
     name   = nodeCanvas.name;
     type   = nodeCanvas.GetType();
 }
コード例 #22
0
ファイル: FSMRunner.cs プロジェクト: zwwl0801/RvoProject
            internal void UpdateInFrame(long cnt)
            {
                if (runners.Count == 0)
                {
                    return;
                }

                List <NodeCanvas> values = GetAllFSM();

                for (int i = 0; i < values.Count; ++i)
                {
                    NodeCanvas nodecanvas = values[i];
                    if (nodestates.ContainsKey(nodecanvas))
                    {
                        FSMRunerState runningstate = nodestates[nodecanvas];
                        if (runningstate.isRunning && runningstate.current != null)
                        {
                            FSMElement current   = runningstate.current;
                            FSMElement laststate = runningstate.laststate;

                            if (laststate != null)
                            {
                                if (laststate != current)
                                {
                                    // LogMgr.LogError("this is  " + nodecanvas);
                                    ScriptCommand exitcmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallExit);
                                    exitcmd.CallParams.WriteObject(laststate);
                                    exitcmd.ExcuteAndRelease();

                                    ScriptCommand entercmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallEnter);
                                    entercmd.CallParams.WriteObject(current);
                                    entercmd.ExcuteAndRelease();
                                }
                            }
                            else
                            {
                                // LogMgr.LogError("this is  " + nodecanvas);
                                ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallEnter);
                                cmd.CallParams.WriteObject(current);
                                cmd.ExcuteAndRelease();
                            }

                            runningstate.laststate = current;

                            bool ret = current.UpdateFrameInFSM(cnt);
                            if (!ret && runningstate.isRunning)
                            {
                                FSMElement next = current.SelectForNext();
                                if (next != null)
                                {
                                    runningstate.current = next;
                                }
                                else
                                {
                                    ScriptCommand exitcmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallExit);
                                    exitcmd.CallParams.WriteObject(current);
                                    exitcmd.ExcuteAndRelease();

                                    runningstate.isRunning = false;
                                    this.CallFinishCanvas(nodecanvas);
                                }
                            }
                        }
                    }
                }

                ListPool.TryDespawn(values);
            }
コード例 #23
0
ファイル: GroupNode.cs プロジェクト: Zeloder/Node_Editor
	public override void NodeGUI () 
	{
		GUILayout.BeginHorizontal ();
#if UNITY_EDITOR
		if (GUILayout.Button (new GUIContent ("Load", "Loads the group from an extern Canvas Asset File.")))
		{
			string path = UnityEditor.EditorUtility.OpenFilePanel ("Load Node Canvas", NodeEditor.EditorPath + "Saves/", "asset");
			if (!path.Contains (Application.dataPath)) 
			{
				// TODO: Generic Notification
				//if (path != String.Empty)
					//ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
				return;
			}
			path = path.Replace (Application.dataPath, "Assets");
			LoadNodeCanvas (path);
			//AdoptInputsOutputs ();
		}
		if (GUILayout.Button (new GUIContent ("Save", "Saves the group as a new Canvas Asset File"))) 
		{
			NodeEditor.SaveNodeCanvas (NodeGroupCanvas, UnityEditor.EditorUtility.SaveFilePanelInProject ("Save Group Node Canvas", "Group Canvas", "asset", "", NodeEditor.EditorPath + "Saves/"));
		}
#endif
		if (GUILayout.Button (new GUIContent ("New Group Canvas", "Creates a new Canvas"))) 
		{
			NodeGroupCanvas = CreateInstance<NodeCanvas> ();

			EditorState = CreateInstance<NodeEditorState> ();
			EditorState.Drawing = Edit;
			EditorState.name = "GroupNode_EditorState";

			Node node = NodeTypes.GetDefaultNode ("exampleNode");
			if (node != null)
			{
				NodeCanvas prevNodeCanvas = NodeEditor.CurNodeCanvas;
				NodeEditor.CurNodeCanvas = NodeGroupCanvas;
				node = node.Create (Vector2.zero);
				node.InitBase ();
				NodeEditor.CurNodeCanvas = prevNodeCanvas;
			}
		}
		GUILayout.EndHorizontal ();

		if (NodeGroupCanvas != null)
		{
			foreach (NodeInput input in Inputs)
				input.DisplayLayout ();

			foreach (NodeOutput output in Outputs)
				output.DisplayLayout ();

			if (!Edit)
			{
				if (GUILayout.Button ("Edit Node Canvas"))
				{
					Rect = OpenedRect;
					Edit = true;
					EditorState.CanvasRect = GUILayoutUtility.GetRect (canvasSize.x, canvasSize.y, GUIStyle.none);
					EditorState.Drawing = true;
				}
			}
			else
			{
				if (GUILayout.Button ("Stop editing Node Canvas"))
				{
					NodeRect.position = OpenedRect.position + new Vector2 (canvasSize.x/2 - NodeRect.width/2, 0);
					Rect = NodeRect;
					Edit = false;
					EditorState.Drawing = false;
				}

				Rect canvasRect = GUILayoutUtility.GetRect (canvasSize.x, canvasSize.y, new GUILayoutOption[] { GUILayout.ExpandWidth (false) });
				if (Event.current.type != EventType.Layout) 
				{
					EditorState.CanvasRect = canvasRect;
					Rect canvasControlRect = EditorState.CanvasRect;
					canvasControlRect.position += Rect.position + ContentOffset;
					NodeEditor.CurEditorState.IgnoreInput.Add (NodeEditor.CanvasGUIToScreenRect (canvasControlRect));	
				}

				NodeEditor.DrawSubCanvas (NodeGroupCanvas, EditorState);


				GUILayout.BeginArea (new Rect (canvasSize.x + 8, 45, 200, canvasSize.y), GUI.skin.box);
				GUILayout.Label (new GUIContent ("Node Editor (" + NodeGroupCanvas.name + ")", "The currently opened canvas in the Node Editor"));
				#if UNITY_EDITOR
				EditorState.Zoom = UnityEditor.EditorGUILayout.Slider (new GUIContent ("Zoom", "Use the Mousewheel. Seriously."), EditorState.Zoom, 0.6f, 2);
				#endif
				GUILayout.EndArea ();


				// Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
			}
		}
	}
コード例 #24
0
 NoiseNodeEditor()
 {
     canvasDelegate = c => canvas = c;
 }
コード例 #25
0
        public override void OnInspectorGUI()
        {
            if (canvas == null)
            {
                canvas = (NodeCanvas)target;
            }
            if (canvas == null)
            {
                return;
            }
            if (titleStyle == null)
            {
                titleStyle           = new GUIStyle(GUI.skin.label);
                titleStyle.fontStyle = FontStyle.Bold;
                titleStyle.alignment = TextAnchor.MiddleCenter;
                titleStyle.fontSize  = 16;
            }
            if (subTitleStyle == null)
            {
                subTitleStyle           = new GUIStyle(GUI.skin.label);
                subTitleStyle.fontStyle = FontStyle.Bold;
                subTitleStyle.alignment = TextAnchor.MiddleCenter;
                subTitleStyle.fontSize  = 12;
            }
            if (boldLabelStyle == null)
            {
                boldLabelStyle           = new GUIStyle(GUI.skin.label);
                boldLabelStyle.fontStyle = FontStyle.Bold;
            }

            EditorGUI.BeginChangeCheck();

            GUILayout.Space(10);

            GUILayout.Label(new GUIContent(canvas.saveName, canvas.savePath), titleStyle);
            GUILayout.Label(canvas.livesInScene? "Scene Save" : "Asset Save", subTitleStyle);
            GUILayout.Label("Type: " + canvas.canvasName, subTitleStyle);

            GUILayout.Space(10);

            EditorGUI.BeginDisabledGroup(NodeEditor.curNodeCanvas != null && NodeEditor.curNodeCanvas.savePath == canvas.savePath);
            if (GUILayout.Button("Open"))
            {
                string NodeCanvasPath = AssetDatabase.GetAssetPath(canvas);
                NodeEditorWindow.OpenNodeEditor().canvasCache.LoadNodeCanvas(NodeCanvasPath);
            }
            EditorGUI.EndDisabledGroup();

            GUILayout.Space(10);

            GUILayout.Label("Nodes", boldLabelStyle);
            foreach (Node node in canvas.nodes)
            {
                string label = node.Title;
                EditorGUILayout.ObjectField(label, node, node.GetType(), true);
            }

            GUILayout.Space(10);

            canvas.DrawCanvasPropertyEditor();

            if (EditorGUI.EndChangeCheck())
            {
                NodeEditor.RepaintClients();
            }
        }
コード例 #26
0
ファイル: GroupNode.cs プロジェクト: Zeloder/Node_Editor
	public void LoadNodeCanvas (string path) 
	{
		NodeGroupCanvas = NodeEditor.LoadNodeCanvas (path);
		if (NodeGroupCanvas != null) 
		{
			List<NodeEditorState> editorStates = NodeEditor.LoadEditorStates (path);
			EditorState = editorStates.Count == 0? CreateInstance<NodeEditorState> () : editorStates[0];
			EditorState.Canvas = NodeGroupCanvas;
			EditorState.ParentEditor = NodeEditor.CurEditorState;
			EditorState.Drawing = Edit;
			EditorState.name = "GroupNode_EditorState";

			string[] folders = path.Split (new char[] {'/'}, StringSplitOptions.None);
			string canvasName = folders [folders.Length-1];
			if (canvasName.EndsWith (".asset"))
				canvasName = canvasName.Remove (canvasName.Length-6);
			name = canvasName;
		}
		else 
			name = "Node Group";
	} 
コード例 #27
0
    public void NewNodeCanvas()
    {
        // Else it will be stuck forever
        NodeEditor.StopTransitioning (canvas);

        canvas = ScriptableObject.CreateInstance<NodeCanvas> ();
        state = ScriptableObject.CreateInstance<NodeEditorState> ();
        state.canvas = canvas;
        state.name = "MainEditorState";
    }
コード例 #28
0
 public void OnEnable()
 {
     canvas = (NodeCanvas)target;
     canvas.Validate();
 }
コード例 #29
0
 public NodePanelInputHandler(NodeCanvas nodeCanvas) : base(nodeCanvas)
 {
 }
コード例 #30
0
 public NoiseTraversal(NodeCanvas canvas) : base(canvas)
 {
 }
コード例 #31
0
ファイル: NodeEditor.cs プロジェクト: Hyunkell/Node_Editor
    /// <summary>
    /// Context Click selection. Here you'll need to register your own using a string identifier
    /// </summary>
    public static void ContextCallback(object obj)
    {
        callbackObject cbObj = obj as callbackObject;
        curNodeCanvas = cbObj.canvas;
        curEditorState = cbObj.editor;

        switch (cbObj.message)
        {
        case "deleteNode":
            if (cbObj.node != null)
                cbObj.node.Delete ();
            break;

        case "duplicateNode":
            if (cbObj.node != null)
            {
                ContextCallback (new callbackObject (cbObj.node.GetID, curNodeCanvas, curEditorState));
                Node duplicatedNode = curNodeCanvas.nodes [curNodeCanvas.nodes.Count-1];
                curEditorState.activeNode = duplicatedNode;
                curEditorState.dragNode = true;
            }
            break;

        default:
            foreach (Node node in NodeTypes.nodes.Keys)
            {
                if (node.GetID == cbObj.message)
                {
                    var newNode = node.Create (ScreenToGUIPos (mousePos));
                    newNode.InitBase();
                    // If nodeOutput is defined, link it to the first input of the same type
                    if(cbObj.nodeOutput != null)
                    {
                        foreach (var input in newNode.Inputs)
                        {
                            if (input.type == cbObj.nodeOutput.type)
                            {
                                if (Node.CanApplyConnection (cbObj.nodeOutput, input))
                                { // If it can connect (type is equals, it does not cause recursion, ...)
                                    Node.ApplyConnection (cbObj.nodeOutput, input);
                                    break;
                                }
                            }
                        }
                    }

                    break;
                }
            }
            break;
        }
    }
コード例 #32
0
        public override void Export(NodeCanvas canvas, params object[] locationArgs)
        {
            CanvasData data = ImportExportManager.ConvertToCanvasData(canvas);

            ExportData(data, locationArgs);
        }
コード例 #33
0
ファイル: NodeEditor.cs プロジェクト: Hyunkell/Node_Editor
 public callbackObject(string Message, NodeCanvas nodecanvas, NodeEditorState editorState)
 {
     message = Message;
     canvas = nodecanvas;
     editor = editorState;
     node = null;
     nodeOutput = null;
 }
コード例 #34
0
 public TextureCanvasCalculator(NodeCanvas canvas) : base(canvas)
 {
     _lastTick = Time.realtimeSinceStartup;
     EditorApplication.update += OnUpdate;
 }
コード例 #35
0
 public DefaultCanvasCalculator(NodeCanvas canvas) : base(canvas)
 {
 }
コード例 #36
0
    bool FixupForSubCanvas()
    {
        if (!string.IsNullOrEmpty(m_CanvasGuid) && m_SubCanvas == null)
        {
            string NodeCanvasPath = AssetDatabase.GUIDToAssetPath(m_CanvasGuid);

            m_SubCanvas = NodeEditorSaveManager.LoadNodeCanvas(NodeCanvasPath, false);
            m_WasCloned = true;
        }

        if (m_SubCanvas != null)
        {
            if (!m_WasCloned)
            {
                NodeEditorSaveManager.CreateWorkingCopy(m_SubCanvas, false);//miked remove ref
                m_WasCloned = true;
            }

            List <NodeInput>          needsInput  = new List <NodeInput>();
            List <UnityTextureOutput> needsOutput = new List <UnityTextureOutput>();
            foreach (Node n in m_SubCanvas.nodes)
            {
                if (n.Inputs.Count > 0)
                {
                    if (n is UnityTextureOutput && n.Inputs[0].connection != null)
                    {
                        needsOutput.Add(n as UnityTextureOutput);
                    }
                    for (int i = 0; i < n.Inputs.Count; i++)
                    {
                        if (n.Inputs[i].connection == null)
                        {
                            //this node has no input so we will wire it up to ours
                            needsInput.Add(n.Inputs[i]);
                            //                            Debug.Log(" missing input for node "+n+" name "+n.name);
                        }
                    }
                }
            }
            if (needsOutput.Count > Outputs.Count)
            {
                while (needsOutput.Count > Outputs.Count)
                {
                    //                    Debug.Log(" create input "+Inputs.Count);
                    CreateOutput("Texture" + Outputs.Count + " " + needsOutput[needsOutput.Count - 1].m_TexName, needsOutput[needsOutput.Count - 1].Inputs[0].connection.typeID, NodeSide.Right, 50 + Outputs.Count * 20);
                }
            }
            if (needsOutput.Count > 0)
            {
                Outputs[0].name = "Texture0" + " " + needsOutput[0].m_TexName;
            }

            if (needsInput.Count > Inputs.Count)
            {
                //  while (needsInput.Count > Inputs.Count)
                int startInputCount = Inputs.Count;
//                for(int index= needsInput.Count-1;index>= startInputCount; index--)
                for (int index = Inputs.Count; index < needsInput.Count; index++)
                {
                    string name = needsInput[index].name;
                    //                    Debug.Log(" create input "+Inputs.Count);
                    CreateInput(name, needsInput[index].typeID, NodeSide.Left, 30 + Inputs.Count * 20);
                }

                return(false);
            }
        }
        return(true);
    }
コード例 #37
0
ファイル: GroupNode.cs プロジェクト: ipud2/csg-toolkit
    public override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent("Load", "Loads the group from an extern Canvas Asset File.")))
        {
#if UNITY_EDITOR
            string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
            if (!path.Contains(Application.dataPath))
            {
                if (path != String.Empty)
                {
                    NodeEditorWindow.editor.ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                }
                return;
            }
            path = path.Replace(Application.dataPath, "Assets");

            if (nodeGroupCanvas != null)
            {
                NodeEditor.curNodeCanvas.childs.Remove(nodeGroupCanvas);
            }
            nodeGroupCanvas        = NodeEditor.LoadNodeCanvas(path);
            nodeGroupCanvas.parent = NodeEditor.curNodeCanvas;
            NodeEditor.curNodeCanvas.childs.Add(nodeGroupCanvas);

            if (editorState != null)
            {
                NodeEditor.curEditorState.childs.Remove(editorState);
            }
            editorState         = NodeEditor.LoadEditorStates(path) [0];
            editorState.parent  = NodeEditor.curEditorState;
            editorState.drawing = edit;
            NodeEditor.curEditorState.childs.Add(editorState);

            if (nodeGroupCanvas != null)
            {             // Set the name
                string[] folders    = path.Split(new char[] { '/' }, StringSplitOptions.None);
                string   canvasName = folders [folders.Length - 1];
                if (canvasName.EndsWith(".asset"))
                {
                    canvasName = canvasName.Remove(canvasName.Length - 6);
                }
                name = canvasName;
            }
            else
            {
                name = "Node Group";
            }
            //AdoptInputsOutputs ();
#endif
        }
        if (GUILayout.Button(new GUIContent("Save", "Saves the group as a new Canvas Asset File")))
        {
#if UNITY_EDITOR
            NodeEditor.SaveNodeCanvas(nodeGroupCanvas, UnityEditor.EditorUtility.SaveFilePanelInProject("Save Group Node Canvas", "Group Canvas", "asset",
                                                                                                        "Saving to a file is only needed once.", NodeEditor.editorPath + "Saves/"));
#endif
        }
        if (GUILayout.Button(new GUIContent("New Group Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)")))
        {
            if (nodeGroupCanvas != null)
            {
                NodeEditor.curNodeCanvas.childs.Remove(nodeGroupCanvas);
            }
            nodeGroupCanvas        = CreateInstance <NodeCanvas> ();
            nodeGroupCanvas.parent = NodeEditor.curNodeCanvas;
            NodeEditor.curNodeCanvas.childs.Add(nodeGroupCanvas);

            if (editorState != null)
            {
                NodeEditor.curEditorState.childs.Remove(editorState);
            }
            editorState         = CreateInstance <NodeEditorState> ();
            editorState.parent  = NodeEditor.curEditorState;
            editorState.drawing = edit;
            NodeEditor.curEditorState.childs.Add(editorState);
            editorState.name = "GroupNode_EditorState";
        }
        GUILayout.EndHorizontal();

        foreach (NodeInput input in Inputs)
        {
            input.DisplayLayout();
        }

        foreach (NodeOutput output in Outputs)
        {
            output.DisplayLayout();
        }

        if (!edit && nodeGroupCanvas != null)
        {
            if (GUILayout.Button("Edit Node Canvas"))
            {
                rect = openedRect;
                edit = true;
                editorState.canvasRect = canvasRect;
                editorState.drawing    = true;
            }
        }
        else if (nodeGroupCanvas != null)
        {
            editorState.canvasRect = canvasRect;
            if (GUILayout.Button("Stop editing Node Canvas"))
            {
                nodeRect.position = openedRect.position + new Vector2(canvasSize.x / 2 - nodeRect.width / 2, 0);
                rect = nodeRect;
                edit = false;
                editorState.drawing = false;
            }
            // Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
        }
    }
コード例 #38
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
    /// <summary>
    /// Draws the Node Canvas on the screen in the rect specified by editorState. Has to be called out of any GUI Group or area because of zooming.
    /// </summary>
    public static void DrawCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
    {
        if (!editorState.drawing)
            return;

        curNodeCanvas = nodeCanvas;
        curEditorState = editorState;

        //		if (curEditorState.parent != null)
        //			curEditorState.canvasRect.position += curEditorState.parent.zoomPanAdjust;

        if (Event.current.type == EventType.Repaint)
        { // Draw Background when Repainting
            GUI.BeginClip (curEditorState.canvasRect);

            float width = Background.width / curEditorState.zoom;
            float height = Background.height / curEditorState.zoom;
            Vector2 offset = new Vector2 ((curEditorState.panOffset.x / curEditorState.zoom)%width - width,
                                          (curEditorState.panOffset.y / curEditorState.zoom)%height - height);
            int tileX = Mathf.CeilToInt ((curEditorState.canvasRect.width + (width - offset.x)) / width);
            int tileY = Mathf.CeilToInt ((curEditorState.canvasRect.height + (height - offset.y)) / height);

            for (int x = 0; x < tileX; x++)
            {
                for (int y = 0; y < tileY; y++)
                {
                    Rect texRect = new Rect (offset.x + x*width,
                                             offset.y + y*height,
                                             width, height);

                    GUI.DrawTexture (texRect, Background);
                }
            }
            GUI.EndClip ();
        }

        //		if (curEditorState.parent != null)
        //			curEditorState.canvasRect.position -= curEditorState.parent.zoomPanAdjust - curEditorState.parent.zoomPos;

        // Fetch all nested nodeEditors and set their canvasRects to be ignored by input,
        // so it can be handled later, and note it down, as it will be drawn later ontop
        List<Rect> ignoreInput = new List<Rect> ();
        for (int childCnt = 0; childCnt < curEditorState.childs.Count; childCnt++)
        {
            if (curEditorState.childs [childCnt].drawing)
            {
                NodeEditorState nestedEditor = curEditorState.childs [childCnt];
                ignoreInput.Add (GUIToScreenRect (nestedEditor.canvasRect));
            }
        }

        // Check the inputs
        InputEvents (ignoreInput);

        // We want to scale our nodes, but as GUI.matrix also scales our widnow's clipping group,
        // we have to scale it up first to receive a correct one as a result
        #region Scale Setup

        // End the default clipping group
        GUI.EndGroup ();

        // The Rect of the new clipping group to draw our nodes in
        Rect ScaledCanvasRect = ScaleRect (curEditorState.canvasRect, curEditorState.zoomPos + curEditorState.canvasRect.position, new Vector2 (curEditorState.zoom, curEditorState.zoom));
        ScaledCanvasRect.y += 23; // Header tab height

        if (curNodeCanvas != NodeEditorWindow.mainNodeCanvas)
            GUI.DrawTexture (ScaledCanvasRect, Background);

        // Now continue drawing using the new clipping group
        GUI.BeginGroup (ScaledCanvasRect);
        ScaledCanvasRect.position = Vector2.zero; // Adjust because we entered the new group

        // Because I currently found no way to actually scale to the center of the window rather than (0, 0),
        // I'm going to cheat and just pan it accordingly to let it appear as if it would scroll to the center
        // Note, due to that, other controls are still scaled to (0, 0)
        curEditorState.zoomPanAdjust = ScaledCanvasRect.center - curEditorState.canvasRect.size/2 + curEditorState.zoomPos;

        // Take a matrix backup to restore back later on
        Matrix4x4 GUIMatrix = GUI.matrix;

        // Scale GUI.matrix. After that we have the correct clipping group again.
        GUIUtility.ScaleAroundPivot (new Vector2 (1/curEditorState.zoom, 1/curEditorState.zoom), curEditorState.zoomPanAdjust);

        #endregion

        // Some features which require drawing (zoomed)
        if (curEditorState.navigate)
        { // Draw a curve to the origin/active node for orientation purposes
            DrawNodeCurve ((curEditorState.activeNode != null? curEditorState.activeNode.rect.center : curEditorState.panOffset), ScreenToGUIPos (mousePos) + curEditorState.zoomPos * curEditorState.zoom, Color.black);
            NodeEditorWindow.editor.Repaint ();
        }
        if (curEditorState.connectOutput != null)
        { // Draw the currently drawn connection
            DrawNodeCurve (curEditorState.connectOutput.GetGUIKnob ().center, ScreenToGUIPos (mousePos) + curEditorState.zoomPos * curEditorState.zoom, ConnectionTypes.types [curEditorState.connectOutput.type].col);
            NodeEditorWindow.editor.Repaint ();
        }
        if (curNodeCanvas != NodeEditorWindow.mainNodeCanvas)
            return;
        // Draw the nodes
        for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
        {
            Node node = curNodeCanvas.nodes [nodeCnt];
            //if (node != curEditorState.activeNode)
            NodeEditor.DrawNode (node);
        }

        // Draw their connectors; Seperated because of render order
        for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            curNodeCanvas.nodes [nodeCnt].DrawConnections ();
        for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            curNodeCanvas.nodes [nodeCnt].DrawKnobs ();

        // Draw the active Node ontop
        //		if (editorState.activeNode != null)
        //			NodeEditor.DrawNode (curEditorState.activeNode);

        // Draw any node groups out there. Has to be drawn here, because they still need to scale according to their parents, but they mustn't be drawn inside a GUI group
        for (int editorCnt = 0; editorCnt < curEditorState.childs.Count; editorCnt++)
        {
            if (curEditorState.childs [editorCnt].drawing)
            {
                NodeEditorState nestedEditor = curEditorState.childs [editorCnt];
                nestedEditor.canvasRect.position += curEditorState.zoomPanAdjust;
                //GUI.DrawTexture (nestedEditor.canvasRect, Background);
                DrawCanvas (nestedEditor.canvas, nestedEditor);
                nestedEditor.canvasRect.position -= curEditorState.zoomPanAdjust;
            }
        }
        curNodeCanvas = nodeCanvas;
        curEditorState = editorState;

        // End scaling group
        // Set default matrix and clipping group for the rest
        GUI.matrix = GUIMatrix;
        GUI.EndGroup ();
        if (curNodeCanvas.parent == null)
            GUI.BeginGroup (new Rect (0, 23, NodeEditorWindow.editor.position.width, NodeEditorWindow.editor.position.height));
        else
        {
            Rect parentGroupRect = ScaleRect (curEditorState.parent.canvasRect, curEditorState.parent.zoomPos + curEditorState.parent.canvasRect.position, new Vector2 (curEditorState.parent.zoom, curEditorState.parent.zoom));
            parentGroupRect.y += 23; // Header tab height
            GUI.BeginGroup (parentGroupRect);
        }
        // Check events with less priority than node GUI controls
        LateEvents (ignoreInput);
    }
コード例 #39
0
    public override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
#if UNITY_EDITOR
        if (GUILayout.Button(new GUIContent("Load", "Loads the group from an extern Canvas Asset File.")))
        {
            string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
            if (!path.Contains(Application.dataPath))
            {
                // TODO: Generic Notification
                //if (path != String.Empty)
                //ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
                return;
            }
            path = path.Replace(Application.dataPath, "Assets");

            nodeGroupCanvas = NodeEditor.LoadNodeCanvas(path);

            editorState         = NodeEditor.LoadEditorStates(path) [0];
            editorState.drawing = edit;

            if (nodeGroupCanvas != null)
            {             // Set the name
                string[] folders    = path.Split(new char[] { '/' }, StringSplitOptions.None);
                string   canvasName = folders [folders.Length - 1];
                if (canvasName.EndsWith(".asset"))
                {
                    canvasName = canvasName.Remove(canvasName.Length - 6);
                }
                name = canvasName;
            }
            else
            {
                name = "Node Group";
            }

            //AdoptInputsOutputs ();
        }
        if (GUILayout.Button(new GUIContent("Save", "Saves the group as a new Canvas Asset File")))
        {
            NodeEditor.SaveNodeCanvas(nodeGroupCanvas, UnityEditor.EditorUtility.SaveFilePanelInProject("Save Group Node Canvas", "Group Canvas", "asset",
                                                                                                        "Saving to a file is only needed once.", NodeEditor.editorPath + "Saves/"));
        }
#endif
        if (GUILayout.Button(new GUIContent("New Group Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)")))
        {
            nodeGroupCanvas = CreateInstance <NodeCanvas> ();

            editorState         = CreateInstance <NodeEditorState> ();
            editorState.drawing = edit;
            editorState.name    = "GroupNode_EditorState";
        }
        GUILayout.EndHorizontal();

        foreach (NodeInput input in Inputs)
        {
            input.DisplayLayout();
        }

        foreach (NodeOutput output in Outputs)
        {
            output.DisplayLayout();
        }

        if (!edit && nodeGroupCanvas != null)
        {
            if (GUILayout.Button("Edit Node Canvas"))
            {
                rect = openedRect;
                edit = true;
                editorState.canvasRect = GUILayoutUtility.GetRect(canvasSize.x, canvasSize.y, GUIStyle.none);
                editorState.drawing    = true;
            }
        }
        else if (nodeGroupCanvas != null)
        {
            if (GUILayout.Button("Stop editing Node Canvas"))
            {
                nodeRect.position = openedRect.position + new Vector2(canvasSize.x / 2 - nodeRect.width / 2, 0);
                rect = nodeRect;
                edit = false;
                editorState.drawing = false;
            }

            editorState.canvasRect = GUILayoutUtility.GetRect(canvasSize.x - 200, canvasSize.y, new GUILayoutOption[] { GUILayout.ExpandWidth(false) });
            NodeEditor.curEditorState.ignoreInput.Add(NodeEditor.GUIToScreenRect(editorState.canvasRect));
            NodeEditor.DrawSubCanvas(nodeGroupCanvas, editorState);

            GUILayout.BeginArea(new Rect(canvasSize.x - 200 + 2, editorState.canvasRect.y + 42, 200, canvasSize.y), GUI.skin.box);

            GUILayout.Label(new GUIContent("Node Editor (" + nodeGroupCanvas.name + ")", "The currently opened canvas in the Node Editor"));

            GUILayout.EndArea();


            // Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
        }
    }
コード例 #40
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
 /// <summary>
 /// Recalculate from every Input Node.
 /// Usually does not need to be called at all, the smart calculation system is doing the job just fine
 /// </summary>
 public static void RecalculateAll(NodeCanvas nodeCanvas)
 {
     RecalculateAll (nodeCanvas, true);
 }
コード例 #41
0
    protected internal override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
#if UNITY_EDITOR
        if (GUILayout.Button(new GUIContent("Load", "Loads the group from an extern Canvas Asset File.")))
        {
            string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
            if (!path.Contains(Application.dataPath))
            {
                // TODO: Generic Notification
                //if (path != String.Empty)
                //ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
                return;
            }
            path = path.Replace(Application.dataPath, "Assets");
            LoadNodeCanvas(path);
            //AdoptInputsOutputs ();
        }
        if (GUILayout.Button(new GUIContent("Save", "Saves the group as a new Canvas Asset File")))
        {
            NodeEditorSaveManager.SaveNodeCanvas(UnityEditor.EditorUtility.SaveFilePanelInProject("Save Group Node Canvas", "Group Canvas", "asset", "", NodeEditor.editorPath + "Saves/"), nodeGroupCanvas);
        }
#endif
        if (GUILayout.Button(new GUIContent("New Group Canvas", "Creates a new Canvas")))
        {
            nodeGroupCanvas = CreateInstance <NodeCanvas> ();

            editorState         = CreateInstance <NodeEditorState> ();
            editorState.drawing = edit;
            editorState.name    = "GroupNode_EditorState";

            Node node = NodeTypes.getDefaultNode("exampleNode");
            if (node != null)
            {
                NodeCanvas prevNodeCanvas = NodeEditor.curNodeCanvas;
                NodeEditor.curNodeCanvas = nodeGroupCanvas;
                node = node.Create(Vector2.zero);
                node.InitBase();
                NodeEditor.curNodeCanvas = prevNodeCanvas;
            }
        }
        GUILayout.EndHorizontal();

        if (nodeGroupCanvas != null)
        {
            foreach (NodeInput input in Inputs)
            {
                input.DisplayLayout();
            }

            foreach (NodeOutput output in Outputs)
            {
                output.DisplayLayout();
            }

            if (!edit)
            {
                if (GUILayout.Button("Edit Node Canvas"))
                {
                    rect = openedRect;
                    edit = true;
                    editorState.canvasRect = GUILayoutUtility.GetRect(canvasSize.x, canvasSize.y, GUIStyle.none);
                    editorState.drawing    = true;
                }
            }
            else
            {
                if (GUILayout.Button("Stop editing Node Canvas"))
                {
                    nodeRect.position = openedRect.position + new Vector2(canvasSize.x / 2 - nodeRect.width / 2, 0);
                    rect = nodeRect;
                    edit = false;
                    editorState.drawing = false;
                }

                Rect canvasRect = GUILayoutUtility.GetRect(canvasSize.x, canvasSize.y, new GUILayoutOption[] { GUILayout.ExpandWidth(false) });
                if (Event.current.type != EventType.Layout)
                {
                    editorState.canvasRect = canvasRect;
                    Rect canvasControlRect = editorState.canvasRect;
                    canvasControlRect.position += rect.position + contentOffset;
                    NodeEditor.curEditorState.ignoreInput.Add(NodeEditorFramework.NodeEditor.CanvasGUIToScreenRect(canvasControlRect));
                }

                NodeEditor.DrawSubCanvas(nodeGroupCanvas, editorState);


                GUILayout.BeginArea(new Rect(canvasSize.x + 8, 45, 200, canvasSize.y), GUI.skin.box);
                GUILayout.Label(new GUIContent("Node Editor (" + nodeGroupCanvas.name + ")", "The currently opened canvas in the Node Editor"));
                                #if UNITY_EDITOR
                editorState.zoom = UnityEditor.EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), editorState.zoom, 0.6f, 2);
                                #endif
                GUILayout.EndArea();


                // Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
            }
        }
    }
コード例 #42
0
ファイル: NodeEditor.cs プロジェクト: dannisliang/Node_Editor
 /// <summary>
 /// Saves the current node canvas as a new asset and links optional editorStates with it
 /// </summary>
 public static void SaveNodeCanvas(NodeCanvas nodeCanvas, string path, params NodeEditorState[] editorStates)
 {
     #if UNITY_EDITOR
     if (String.IsNullOrEmpty (path))
         return;
     string existingPath = UnityEditor.AssetDatabase.GetAssetPath (nodeCanvas);
     if (!String.IsNullOrEmpty (existingPath))
     {
         if (existingPath != path)
         {
             UnityEditor.AssetDatabase.CopyAsset (existingPath, path);
             UnityEditor.AssetDatabase.SaveAssets ();
             UnityEditor.AssetDatabase.Refresh ();
         }
         return;
     }
     UnityEditor.AssetDatabase.CreateAsset (nodeCanvas, path);
     foreach (NodeEditorState editorState in editorStates)
         UnityEditor.AssetDatabase.AddObjectToAsset (editorState, nodeCanvas);
     for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
     { // Add every node and every of it's inputs/outputs into the file.
         // Results in a big mess but there's no other way (like a hierarchy)
         Node node = nodeCanvas.nodes [nodeCnt];
         UnityEditor.AssetDatabase.AddObjectToAsset (node, nodeCanvas);
         for (int inCnt = 0; inCnt < node.Inputs.Count; inCnt++)
             UnityEditor.AssetDatabase.AddObjectToAsset (node.Inputs [inCnt], node);
         for (int outCnt = 0; outCnt < node.Outputs.Count; outCnt++)
             UnityEditor.AssetDatabase.AddObjectToAsset (node.Outputs [outCnt], node);
     }
     UnityEditor.AssetDatabase.SaveAssets ();
     UnityEditor.AssetDatabase.Refresh ();
     #endif
 }
コード例 #43
0
 private static StartSequenceNode GetStartNode(NodeCanvas canvas)
 {
     return(canvas.nodes.OfType <StartSequenceNode>().FirstOrDefault());
 }
コード例 #44
0
 /// <summary>
 /// Creates and opens a new empty node canvas
 /// </summary>
 public void NewNodeCanvas()
 {
     // New NodeCanvas
     mainNodeCanvas = CreateInstance<NodeCanvas> ();
     mainNodeCanvas.nodes = new List<Node> ();
     // New NodeEditorState
     mainEditorState = CreateInstance<NodeEditorState> ();
     mainEditorState.canvas = mainNodeCanvas;
     mainEditorState.name = "MainEditorState";
     // Set some properties
     openedCanvas = "New Canvas";
     openedCanvasPath = "";
 }
コード例 #45
0
    AnimationPlayableBaseNode FindNode(NodeCanvas canvas)
    {
        var result = canvas.nodes.Where(n => n.GetType() == typeof(AnimationMixerPlayableNode)).FirstOrDefault();

        return((AnimationPlayableBaseNode)result);
    }
コード例 #46
0
        /// <summary>
        /// Converts the NodeCanvas to a simplified CanvasData
        /// </summary>
        internal static CanvasData ConvertToCanvasData(NodeCanvas canvas)
        {
            if (canvas == null)
            {
                return(null);
            }

            // Validate canvas and create canvas data for it
            canvas.Validate();
            CanvasData canvasData = new CanvasData(canvas);

            // Store Lookup-Table for all ports
            Dictionary <ConnectionPort, PortData> portDatas = new Dictionary <ConnectionPort, PortData>();

            foreach (Node node in canvas.nodes)
            {
                // Create node data
                NodeData nodeData = new NodeData(node);
                canvasData.nodes.Add(nodeData.nodeID, nodeData);

                foreach (ConnectionPortDeclaration portDecl in ConnectionPortManager.GetPortDeclarationEnumerator(node))
                {                 // Fetch all static connection port declarations and record them
                    ConnectionPort port     = (ConnectionPort)portDecl.portField.GetValue(node);
                    PortData       portData = new PortData(nodeData, port, portDecl.portField.Name);
                    nodeData.connectionPorts.Add(portData);
                    portDatas.Add(port, portData);
                }

                foreach (ConnectionPort port in node.dynamicConnectionPorts)
                {                 // Fetch all dynamic connection ports and record them
                    PortData portData = new PortData(nodeData, port);
                    nodeData.connectionPorts.Add(portData);
                    portDatas.Add(port, portData);
                }

                // Fetch all serialized node variables specific to each node's implementation
                FieldInfo[] serializedFields = ReflectionUtility.getSerializedFields(node.GetType(), typeof(Node));
                foreach (FieldInfo field in serializedFields)
                {                 // Create variable data and enter the
                    if (field.FieldType.IsSubclassOf(typeof(ConnectionPort)))
                    {
                        continue;
                    }
                    VariableData varData = new VariableData(field);
                    nodeData.variables.Add(varData);
                    object varValue = field.GetValue(node);
                    if (field.FieldType.IsValueType)                     // Store value of the object
                    {
                        varData.value = varValue;
                    }
                    else                     // Store reference to the object
                    {
                        varData.refObject = canvasData.ReferenceObject(varValue);
                    }
                }
            }

            foreach (PortData portData in portDatas.Values)
            {             // Record the connections of this port
                foreach (ConnectionPort conPort in portData.port.connections)
                {
                    PortData conPortData;                     // Get portData associated with the connection port
                    if (portDatas.TryGetValue(conPort, out conPortData))
                    {
                        canvasData.RecordConnection(portData, conPortData);
                    }
                }
            }

            foreach (NodeGroup group in canvas.groups)
            {             // Record all groups
                canvasData.groups.Add(new GroupData(group));
            }

            canvasData.editorStates = new EditorStateData[canvas.editorStates.Length];
            for (int i = 0; i < canvas.editorStates.Length; i++)
            {             // Record all editorStates
                NodeEditorState state    = canvas.editorStates[i];
                NodeData        selected = state.selectedNode == null ? null : canvasData.FindNode(state.selectedNode);
                canvasData.editorStates[i] = new EditorStateData(selected, state.panOffset, state.zoom);
            }

            return(canvasData);
        }
コード例 #47
0
ファイル: RuntimeNodeEditor.cs プロジェクト: leeeennyy/ETSM
 public void NewNodeCanvas()
 {
     canvas      = ScriptableObject.CreateInstance <NodeCanvas> ();
     canvas.name = "New Canvas";
     NewEditorState();
 }
コード例 #48
0
 /// <summary>
 /// Exports the given canvas with the given formatter to the location specified in the args
 /// </summary>
 public static void ExportCanvas(NodeCanvas canvas, ImportExportFormat formatter, params object[] args)
 {
     formatter.Export(canvas, args);
 }
コード例 #49
0
 public NodeHandleInputHandler(NodeCanvas nodeCanvas) : base(nodeCanvas)
 {
 }