Node PriorLoop(Node n) { List <Node> nodes = new List <Node>(); nodes.Add(n); for (int index = 0; index < nodes.Count; index++) { var node = nodes[index]; foreach (var i in node.Outputs) { if (i != null)// && i.connection!=null) { foreach (var c in i.connections) { Node body = c.connection.body; if (!nodes.Contains(body)) { nodes.Add(body); } if (body is LoopBasic) { return(body); } } } } } return(n); }
public Socket(Node parent, Type type, string label, bool acceptMultiple, Color color) { m_node = parent; m_type = type; m_value = null; m_sockets = new List<Socket>(); m_acceptMultipleConnections = acceptMultiple; m_label = label; m_color = color; }
void Dialogue() { if (currentNode == null) { //find conversation root node System.Collections.Generic.List <NodeEditorFramework.Node> nodes = interactTarget.InteractionTree.nodes; RootNode root = null; for (var i = 0; i < nodes.Count; ++i) { if (nodes[i] is RootNode) { RootNode cur = (RootNode)nodes[i]; if (cur.Name == interactTarget.Root) { root = cur; break; } } } if (root != null) { currentNode = root.Outputs[0].GetNodeAcrossConnection(); done = false; } else { State = States.Explore; Debug.Log(string.Format("Could not find root node \"{0}\" in InteractionTree!")); } } else //if there is a node to be done { if (!done) { DialogueNode d = (DialogueNode)currentNode; Debug.Log(interactTarget.gameObject.name + " says: " + d.DialogueText); done = true; } } if (Input.GetButtonDown("Submit")) { if (currentNode != null) { //get the next node along currentNode = currentNode.Outputs[0].GetNodeAcrossConnection(); done = false; if (currentNode == null) { State = States.Explore; Debug.Log("Conversation over!"); } } } }
public static Transition Create(Node from, Node to) { if (NodeTypes.getNodeData (from).transitions == false || NodeTypes.getNodeData (to).transitions == false) return null; Transition transition = CreateInstance<Transition> (); transition.name = "Transition " + from.name + "-" + to.name; transition.startNode = from; transition.endNode = to; transition.conditions = new List<Func<Transition, bool>> (); return transition; }
private static void KeyDupe(NodeEditorInputInfo inputInfo) { inputInfo.SetAsCurrentEnvironment(); NodeEditorState state = inputInfo.editorState; if (state.focusedNode != null) { // Create new node of same type Node duplicatedNode = Node.Create(state.focusedNode.GetID, NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos), state.connectOutput); state.selectedNode = state.focusedNode = duplicatedNode; state.connectOutput = null; inputInfo.inputEvent.Use(); } }
/* * if (e.alt) * { * Dictionary<Node, int> d = new Dictionary<Node, int>(); * d[curEditorState.selectedNode] = 1; * * MoveChildren(ref d, curEditorState.selectedNode, delta); * } */ static void MoveChildren(ref Dictionary <Node, int> _dic, Node _n, Vector2 _delta) { foreach (var input in _n.Inputs) { Node cn = input.connection.body; if (!_dic.ContainsKey(cn)) { cn.rect.position += _delta; NodeEditorCallbacks.IssueOnMoveNode(cn); MoveChildren(ref _dic, cn, _delta); _dic[cn] = 1; } } }
private void NewNodeCallback(Node node) { if (m_ReplaceNode != null) { for (int index = 0; index < m_ReplaceNode.Inputs.Count; index++) { var oldInput = m_ReplaceNode.Inputs[index]; if (oldInput.connection != null) { for (int indexNewNodesInputs = 0; indexNewNodesInputs < node.Inputs.Count; indexNewNodesInputs++) { var newInput = node.Inputs[indexNewNodesInputs]; if (newInput.connection == null && newInput.typeID == oldInput.typeID) { newInput.ApplyConnection(oldInput.connection); //newInput.connection = oldInput.connection; break; } } } } for (int index = 0; index < m_ReplaceNode.Outputs.Count; index++) { var oldOutput = m_ReplaceNode.Outputs[index]; if (oldOutput.connections != null) { for (int indexNewNodesOutputs = 0; indexNewNodesOutputs < node.Outputs.Count; indexNewNodesOutputs++) { var newOutput = node.Outputs[indexNewNodesOutputs]; if (newOutput.typeID == oldOutput.typeID) { for (int i = oldOutput.connections.Count - 1; i >= 0; i--) { var x = oldOutput.connections[i]; x.ApplyConnection(newOutput); //newOutput.connections = oldOutput.connections; } break; } } } } node.rect = m_ReplaceNode.rect; m_ReplaceNode.Delete(); m_ReplaceNode = null; NodeEditor.RecalculateFrom(node); } }
public static Transition Create (Node fromNode, Node toNode) { if (fromNode.AcceptsTranstitions == false || toNode.AcceptsTranstitions == false || fromNode == toNode) return null; var transition = CreateInstance<Transition> (); transition.name = "Transition " + fromNode.name + "-" + toNode.name; transition.StartNode = fromNode; transition.EndNode = toNode; transition.Conditions = new List<Func<Transition, bool>> (); fromNode.Transitions.Add (transition); toNode.Transitions.Add (transition); return transition; }
/// <summary> /// Creates a Transition between the given Nodes with the given transitioning time in secs /// </summary> public static Transition Create(Node fromNode, Node toNode, float TransitionTimeInSec) { if (fromNode.AcceptsTranstitions == false || toNode.AcceptsTranstitions == false || fromNode == toNode) return null; Transition transition = CreateInstance<Transition> (); transition.name = "Transition " + fromNode.name + "-" + toNode.name; transition.startNode = fromNode; transition.endNode = toNode; transition.transitionTime = TransitionTimeInSec; fromNode.transitions.Add (transition); toNode.transitions.Add (transition); return transition; }
public NodeView(Node node, Vector2 position) { if (m_leftLabel == null || m_rightLabel == null) { m_leftLabel = new GUIStyle(); m_rightLabel = new GUIStyle(); m_leftLabel.alignment = TextAnchor.MiddleLeft; m_rightLabel.alignment = TextAnchor.MiddleRight; } m_size = new Vector2(DEFAULT_WIDTH, DEFAULT_HEIGHT); m_node = node; m_rect = new Rect(position, m_size); m_socketViews = new SocketView[0]; BuildSockets(Node.InputCount, Node.OutputCount, new Vector2(0f, 16f), new Vector2(m_rect.width, 16f)); }
/// <summary> /// Begins to transition the passed nodeCanvas from beginNode /// </summary> public static void BeginTransitioning(NodeCanvas nodeCanvas, Node beginNode) { if (!nodeCanvas.nodes.Contains (beginNode)) throw new UnityException ("Node to begin transitioning from has to be associated with the passed NodeEditorState!"); nodeCanvas.currentNode = beginNode; nodeCanvas.currentTransition = null; if (!transitioningNodeCanvases.Contains (nodeCanvas)) transitioningNodeCanvases.Add (nodeCanvas); RepaintClients (); // Debug.Log ("Beginning transitioning " + nodeCanvas.name + " from Node " + beginNode.name); nodeCanvas.currentNode.OnEnter (null); #if UNITY_EDITOR NEUpdate -= UpdateTransitions; NEUpdate += UpdateTransitions; #endif }
public static void CreateTransition(Node from, Node to) { from.transitions.Add (Transition.Create (from, to)); }
/// <summary> /// Recursively checks whether this node is a child of the other node /// </summary> public bool isChildOf(Node otherNode) { if (otherNode == null || otherNode == this) return false; if (BeginRecursiveSearchLoop ()) return false; for (int cnt = 0; cnt < Inputs.Count; cnt++) { NodeOutput connection = Inputs [cnt].connection; if (connection != null) { if (connection.body != startRecursiveSearchNode) { if (connection.body == otherNode || connection.body.isChildOf (otherNode)) { StopRecursiveSearchLoop (); return true; } } } } EndRecursiveSearchLoop (); return false; }
/// <summary> /// Recursive function which continues calculation on this node and all the child nodes /// Usually does not need to be called manually /// Returns success/failure of this node only /// </summary> public static bool ContinueCalculation(Node node) { if (node.descendantsCalculated () && node.Calculate ()) { // finished Calculating, continue with the children for (int outCnt = 0; outCnt < node.Outputs.Count; outCnt++) { NodeOutput output = node.Outputs [outCnt]; for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) ContinueCalculation (output.connections [conCnt].body); } workList.Remove (node); node.calculated = true; return true; } else if (!workList.Contains (node)) { // failed to calculate, add it to check later workList.Add (node); } return false; }
private void SaveNewNode(Node node) { if (!mainNodeCanvas.nodes.Contains (node)) throw new UnityException ("Cache system: Writing new Node to save file failed as Node is not part of the Cache!"); string path = tempSessionPath + "/LastSession.asset"; if (AssetDatabase.GetAssetPath (mainNodeCanvas) != path) throw new UnityException ("Cache system error: Current Canvas is not saved as the temporary cache!"); NodeEditorSaveManager.AddSubAsset (node, path); foreach (NodeKnob knob in node.nodeKnobs) NodeEditorSaveManager.AddSubAsset (knob, path); AssetDatabase.SaveAssets (); AssetDatabase.Refresh (); }
/// <summary> /// Creates a transition from node to node /// </summary> public static void CreateTransition(Node fromNode, Node toNode) { Transition trans = Transition.Create (fromNode, toNode); if (trans != null) { fromNode.OnAddTransition (trans); toNode.OnAddTransition (trans); NodeEditorCallbacks.IssueOnAddTransition (trans); } }
/// <summary> /// Draws the node. Depends on curEditorState /// </summary> public static void DrawNode(Node node) { // TODO: Node Editor Feature: Custom Windowing System Rect nodeRect = node.rect; nodeRect.position += curEditorState.zoomPanAdjust; float headerHeight = 20; Rect headerRect = new Rect (nodeRect.x, nodeRect.y, nodeRect.width, headerHeight); Rect bodyRect = new Rect (nodeRect.x, nodeRect.y + headerHeight, nodeRect.width, nodeRect.height - headerHeight); GUIStyle headerStyle = new GUIStyle (GUI.skin.box); if (curEditorState.activeNode == node) headerStyle.fontStyle = FontStyle.Bold; GUI.Label (headerRect, new GUIContent (node.name), headerStyle); GUI.changed = false; GUILayout.BeginArea (bodyRect, GUI.skin.box); node.NodeGUI (); GUILayout.EndArea (); }
public static Node MoveNext(Node node) { if (NodeTypes.getNodeData (node).transitions == false) { Debug.LogError ("Node " + node.ToString () + " does not accept Transitions!"); return null; } for (int transCnt = 0; transCnt < node.transitions.Count; transCnt++) { if (node.transitions[transCnt].conditionsMet ()) return node.transitions[transCnt].endNode; } return node; }
/// <summary> /// Ends the recursive search loop if this was the start node /// </summary> internal void EndRecursiveSearchLoop() { if (startRecursiveSearchNode == this) { // End search recursiveSearchSurpassed = null; startRecursiveSearchNode = null; } }
/// <summary> /// Recursive function which continues calculation on this node and all the child nodes /// Usually does not need to be called manually /// Returns success/failure of this node only /// </summary> public static bool ContinueCalculation (Node node) { if (node.calculated) return false; if ((node.descendantsCalculated () || node.isInLoop ()) && node.Calculate ()) { // finished Calculating, continue with the children node.calculated = true; calculationCount++; workList.Remove (node); if (node.ContinueCalculation && calculationCount < 1000) { foreach (NodeOutput output in node.Outputs) { foreach (NodeInput connection in output.connections) ContinueCalculation (connection.body); } } else if (calculationCount >= 1000) Debug.LogError ("Stopped calculation because of suspected Recursion. Maximum calculation iteration is currently at 1000!"); return true; } else if (!workList.Contains (node)) { // failed to calculate, add it to check later workList.Add (node); } return false; }
public static void IssueOnMoveNode (Node node) { if (OnMoveNode != null) OnMoveNode.Invoke (node); for (int cnt = 0; cnt < receiverCount; cnt++) { if (callbackReceiver [cnt] == null) callbackReceiver.RemoveAt (cnt--); else callbackReceiver [cnt].OnMoveNode (node); } }
/// <summary> /// Recalculate from this node. /// Usually does not need to be called manually /// </summary> public static void RecalculateFrom (Node node) { node.ClearCalculation (); workList = new List<Node> { node }; StartCalculation (); }
public static void CreateTransition(Node fromNode, Node toNode) { Transition.Create (fromNode, toNode); }
/// <summary> /// A recursive function to clear all calculations depending on this node. /// Usually does not need to be called manually /// </summary> public void ClearCalculation() { if (startRecursiveSearchNode == null || recursiveSearchSurpassed == null) { // Start search recursiveSearchSurpassed = new List<Node> (); startRecursiveSearchNode = this; } if (recursiveSearchSurpassed.Contains (this)) return; recursiveSearchSurpassed.Add (this); calculated = false; for (int outCnt = 0; outCnt < Outputs.Count; outCnt++) { NodeOutput output = Outputs [outCnt]; for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) output.connections [conCnt].body.ClearCalculation (); } if (startRecursiveSearchNode == this) { // End search recursiveSearchSurpassed = null; startRecursiveSearchNode = null; } }
/// <summary> /// Recursively checks whether any node in the loop to be made allows recursion. /// Other node is the node this node needs connect to in order to fill the loop (other node being the node coming AFTER this node). /// That means isChildOf has to be confirmed before calling this! /// </summary> internal bool allowsLoopRecursion(Node otherNode) { if (AllowRecursion) return true; if (otherNode == null) return false; if (BeginRecursiveSearchLoop ()) return false; for (int cnt = 0; cnt < Inputs.Count; cnt++) { NodeOutput connection = Inputs [cnt].connection; if (connection != null) { if (connection.body != startRecursiveSearchNode) { if (connection.body.allowsLoopRecursion (otherNode)) { StopRecursiveSearchLoop (); return true; } } } } EndRecursiveSearchLoop (); return false; }
public virtual void OnDeleteNode (Node node) {}
/// <summary> /// Begins the recursive search loop and returns whether this node has already been searched /// </summary> internal bool BeginRecursiveSearchLoop() { if (startRecursiveSearchNode == null || recursiveSearchSurpassed == null) { // Start search recursiveSearchSurpassed = new List<Node> (); startRecursiveSearchNode = this; } if (recursiveSearchSurpassed.Contains (this)) return true; recursiveSearchSurpassed.Add (this); return false; }
public virtual void OnMoveNode (Node node) {}
/// <summary> /// Stops the recursive search loop immediately. Call when you found what you needed. /// </summary> internal void StopRecursiveSearchLoop() { recursiveSearchSurpassed = null; startRecursiveSearchNode = null; }
/// <summary> /// Recursively checks whether this node is a child of the other node /// </summary> public bool isChildOf(Node otherNode) { if (otherNode == null || otherNode == this) return false; if (BeginRecursiveSearchLoop ()) return false; foreach (NodeInput input in Inputs) { NodeOutput connection = input.connection; if (connection != null && connection.body != startRecursiveSearchNode) { if (connection.body == otherNode || connection.body.isChildOf (otherNode)) { StopRecursiveSearchLoop (); return true; } } } EndRecursiveSearchLoop (); return false; }
/// <summary> /// Inits the base node and subscribes it in the node body for drawing and requests to load the texture through 'ReloadTexture' /// </summary> protected void InitBase(Node nodeBody, NodeSide nodeSide, float nodeSidePosition, string knobName) { body = nodeBody; side = nodeSide; sidePosition = nodeSidePosition; name = knobName; nodeBody.nodeKnobs.Add (this); ReloadKnobTexture (); }
/// <summary> /// Recursively checks whether any node in the loop to be made allows recursion. /// Other node is the node this node needs connect to in order to fill the loop (other node being the node coming AFTER this node). /// That means isChildOf has to be confirmed before calling this! /// </summary> internal bool allowsLoopRecursion(Node otherNode) { if (AllowRecursion) return true; if (otherNode == null) return false; if (BeginRecursiveSearchLoop ()) return false; foreach (NodeInput input in Inputs) { NodeOutput connection = input.connection; if (connection != null && connection.body != startRecursiveSearchNode) { if (connection.body.allowsLoopRecursion (otherNode)) { StopRecursiveSearchLoop (); return true; } } } EndRecursiveSearchLoop (); return false; }
[EventHandlerAttribute(EventType.DragPerform, 90)] // Priority over hundred to make it call after the GUI private static void HandleDragAndDrop(NodeEditorInputInfo inputInfo) { if (inputInfo.inputEvent.type == EventType.DragUpdated || (inputInfo.inputEvent.type == EventType.DragPerform)) { //Debug.LogError("handle drag " + inputInfo.inputEvent.type); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0 && (DragAndDrop.objectReferences[0] is Texture2D)) { Debug.Log(" drag texture " + DragAndDrop.objectReferences[0]); UnityTextureInput node = (UnityTextureInput) Node.Create("UnityTextureInput", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.m_Input = DragAndDrop.objectReferences[0] as Texture2D; inputInfo.inputEvent.Use(); } else if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.GetGenericData("GenericDragColumnDragging") != null) { DragAndDrop.AcceptDrag(); //Debug.Log("dragged generic data "+ DragAndDrop.GetGenericData("GenericDragColumnDragging")); List <UnityEditor.IMGUI.Controls.TreeViewItem> _data = DragAndDrop.GetGenericData("GenericDragColumnDragging") as List <UnityEditor.IMGUI.Controls.TreeViewItem>; var draggedElements = new List <TreeElement>(); foreach (var x in _data) { draggedElements.Add(((TreeViewItem <MyTreeElement>)x).data); } var srcItem = draggedElements[0] as MyTreeElement; if (srcItem.m_Canvas) { SubTreeNode node = (SubTreeNode) Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.SubCanvas = srcItem.m_Canvas; string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas); // Debug.Log("drag and drop asset canvas path >" + assetPath + "<"); if (assetPath.Length > 0) { node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath); Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<"); string fname = Path.GetFileName(assetPath); fname = Path.ChangeExtension(fname, ""); node.name = "Sub:" + fname; } node.OnLoadCanvas(); } else { Node node = Node.Create(srcItem.m_NodeID, NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); } inputInfo.inputEvent.Use(); } else if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0 && (DragAndDrop.objectReferences[0] is NodeCanvas)) { DragAndDrop.AcceptDrag(); // Debug.Log(" drag and drop " + DragAndDrop.objectReferences[0] + " co ord " + Event.current.mousePosition); SubTreeNode node = (SubTreeNode) Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.SubCanvas = (NodeCanvas)DragAndDrop.objectReferences[0]; string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas); // Debug.Log("drag and drop asset canvas path >" + assetPath + "<"); if (assetPath.Length > 0) { node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath); Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<"); string fname = Path.GetFileName(assetPath); fname = Path.ChangeExtension(fname, ""); node.name = "Sub:" + fname; } inputInfo.inputEvent.Use(); node.OnLoadCanvas(); } } }
/// <summary> /// Recursively checks whether this node is a child of the other node /// </summary> public bool isChildOf(Node otherNode) { if (otherNode == null) return false; for (int cnt = 0; cnt < Inputs.Count; cnt++) { if (Inputs [cnt].connection != null) { if (Inputs [cnt].connection.body == otherNode) return true; else if (Inputs [cnt].connection.body.isChildOf (otherNode)) // Recursively searching return true; } } return false; }
public virtual void OnAddNode (Node node) {}
private void FinishRecursiveSearchLoop() { recursiveSearchSurpassed = null; startRecursiveSearchNode = null; }