public void Release() { if (mCurrent != null) { mCurrent.Release(); mCurrent = null; } }
public void ReLoadFlow() { Release(); if (mCurrent != null && mCurrent.name.Length > 0) { mCurrent = NodeFlowEditorLoader.Load(mCurrent.name); } }
public bool IsNewNodeFlow() { if (mCurrent != mLastNodeFlow) { mLastNodeFlow = mCurrent; return(true); } return(false); }
public void LoadFlowByPath(string path) { Release(); mCurrent = NodeFlowEditorLoader.Load(path); if (mCurrent != null) { mCurrent.name = path; } }
//----------------------------load flow---------------------------------- public virtual NodeFlow ParseFlow(string path) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode editorNode = doc.SelectSingleNode("editor"); if (editorNode == null) { UnityEngine.Debug.LogError("xml config load error! " + path); return(null); } if (!editorNode.HasChildNodes) { return(null); } NodeFlow flow = new NodeFlow(); //1 node XmlNode cfgNode = editorNode.FirstChild; while (cfgNode != null) { XmlElement cfgElm = cfgNode as XmlElement; string cfgElmName = cfgElm.Name; if (cfgElmName.Equals("node")) { ParseNode(cfgElm, flow); } else if (cfgElmName.Equals("connection")) { } else { UnityEngine.Debug.LogError("can not parse element :" + cfgElmName); } cfgNode = cfgNode.NextSibling; } //2 connection cfgNode = editorNode.FirstChild; while (cfgNode != null) { XmlElement cfgElm = cfgNode as XmlElement; string cfgElmName = cfgElm.Name; if (cfgElmName.Equals("connection")) { ParseConnection(cfgElm, flow); } cfgNode = cfgNode.NextSibling; } doc = null; return(flow); }
protected virtual void SerializeConnect(XmlElement root, Connection connect, NodeFlow flow) { XmlElement connectElm = root.OwnerDocument.CreateElement("connection"); root.AppendChild(connectElm); connectElm.SetAttribute("name", connect.name); connectElm.SetAttribute("from_node", connect.outId.ToString()); Node node = flow.GetNodeByID(connect.outId); connectElm.SetAttribute("from_output", node.GetNextNodeNameByIdx(connect.outIdx)); connectElm.SetAttribute("to_node", connect.inId.ToString()); node = flow.GetNodeByID(connect.inId); connectElm.SetAttribute("to_input", node.GetPreNodeNameByIdx(connect.inIndex)); }
protected virtual void ParseNode(XmlElement elm, NodeFlow flow) { string defName = elm.GetAttribute("name"); NodeDef def = editor.GetNodeDef(defName); if (def == null) { UnityEngine.Debug.LogError("can not prase node:" + defName); return; } int id = int.Parse(elm.GetAttribute("id")); Vector2 pos = new Vector2(100, 100); pos.x = float.Parse(elm.GetAttribute("pos_x")); pos.y = float.Parse(elm.GetAttribute("pos_y")); Node node = flow.CreateNode(def, pos, id); //parse param XmlNode paramNode = elm.FirstChild; while (paramNode != null) { XmlElement cfgElm = paramNode as XmlElement; string cfgElmName = cfgElm.Name; if (cfgElmName.Equals("param")) { ParseParamValue(cfgElm, node); } else if (cfgElmName.Equals("event")) { ParseEventValue(cfgElm, node); } paramNode = paramNode.NextSibling; } paramNode = elm.FirstChild; while (paramNode != null) { XmlElement cfgElm = paramNode as XmlElement; string cfgElmName = cfgElm.Name; if (cfgElmName.Equals("event_param")) { ParseEventParamValue(cfgElm, node); } paramNode = paramNode.NextSibling; } }
public static void DrawFlow(NodeFlow flow) { curFlow = flow; if (flow == null) { return; } Dictionary <int, Node> nodes = flow.GetNodes(); foreach (KeyValuePair <int, Node> kv in nodes) { DrawNode(kv.Value); } List <Connection> connections = flow.GetConnections(); for (int i = 0; i < connections.Count; ++i) { DrawConnection(connections[i]); } }
protected virtual void SerializeFlow(XmlElement root, NodeFlow flow) { //node { Dictionary <int, Node> nodes = flow.GetNodes(); foreach (KeyValuePair <int, Node> kv in nodes) { SerializeNode(root, kv.Value); } } //connection { List <Connection> connects = flow.GetConnections(); foreach (Connection connect in connects) { SerializeConnect(root, connect, flow); } } }
protected virtual void ParseConnection(XmlElement elm, NodeFlow flow) { string connectName = elm.GetAttribute("name"); ConnectionDef def = editor.GetConnectionDef(connectName); if (def == null) { UnityEngine.Debug.LogError("can not prase connect:" + connectName); return; } int fromNode = int.Parse(elm.GetAttribute("from_node")); string fromOutput = elm.GetAttribute("from_output"); Node outNode = flow.GetNodeByID(fromNode); int fromOutputIdx = outNode.GetNextNodeIdxByName(fromOutput); NextNode nextNode = outNode.nextNodeList[fromOutputIdx]; int toNode = int.Parse(elm.GetAttribute("to_node")); string toInput = elm.GetAttribute("to_input"); Node inNode = flow.GetNodeByID(toNode); int toInputIdx = inNode.GetPreNodeIdxByName(toInput); PreNode preNode = inNode.preNodeList[toInputIdx]; flow.BindConnection(nextNode, preNode, def); }
public virtual void SaveToXml(NodeFlowEditorWindow editor, string path, NodeFlow flow) { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("editor"); doc.AppendChild(root); root.SetAttribute("name", editor.edtorName); root.SetAttribute("version", editor.version); SerializeFlow(root, flow); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = new System.Text.UTF8Encoding(false); settings.Indent = true; XmlWriter xmlWriter = XmlWriter.Create(path, settings); doc.Save(xmlWriter); xmlWriter.Flush(); xmlWriter.Close(); doc = null; xmlWriter = null; }
public void CreateNewFlow() { Release(); mCurrent = new NodeFlow(); mCurrent.name = ""; }
public Node(NodeFlow parent) { this.parent = parent; }
public static void SaveToXml(NodeFlowEditorWindow editor, string path, NodeFlow flow) { editor.serialize.SaveToXml(editor, path, flow); }