static void Init() { root = EditorWindow.GetWindow(typeof(FSMGraphEditor)) as FSMGraphEditor; nodeList = new List <FSMNodeEditor>(); lineList = new List <FSMConditionLineEditor> (); rootNode = new FSMNodeEditor("Root", 50f, 50f, root, FSMNodeEditor.ENodeType.Root); anyState = new FSMNodeEditor("AnyState", 50f, 300f, root, FSMNodeEditor.ENodeType.AnyNode); m_Map = new Dictionary <string, FSMNodeEditor> (); nodeTotalCount = 0; }
private void CreateNewNode(object obj) { nodeTotalCount++; var node = new FSMNodeEditor("FSMState" + nodeTotalCount, 300f + (20f * nodeList.Count), 200f + (20f * nodeList.Count), root); nodeList.Add(node); if (nodeList.Count == 1) { var isRootCondition = new FSMConditionLineEditor("IsRoot", rootNode, node); rootNode.conditionLines.Add(isRootCondition); rootNode.OnDrawCondition = false; rootNode.conditionLines[0].haveDraw = true; } }
public virtual string GenerateJson(string json, FSMNodeEditor node) { for (int i = 0; i < node.conditionLines.Count; i++) { var condition = node.conditionLines [i]; json += GetJsonText(condition.targetNode, condition.GetName(), condition.targetNode.GetName()); json += (i == node.conditionLines.Count - 1) ? "" : ","; if (m_Map.ContainsKey(condition.targetNode.GetName())) { continue; } m_Map.Add(condition.targetNode.GetName(), condition.targetNode); json = json.Replace("<<0>>", GenerateJson(string.Empty, condition.targetNode)); } return(json); }
public virtual void OnDraw(FSMNodeEditor node, Event currentEvent) { var pos = currentEvent.mousePosition; var startTangent = new Vector2(node.nodeRect.xMax, node.nodeRect.center.y); Handles.BeginGUI(); Handles.DrawBezier(node.nodeRect.center, pos, startTangent, new Vector2(pos.x, pos.y), Color.red, null, 5f); var center = (startTangent + pos) / 2f; Handles.Label(center, conditionName); sourceNode = node; targetNode = null; Handles.EndGUI(); }
public virtual void DeleteNode(FSMNodeEditor node) { for (int i = 0; i < nodeList.Count; i++) { for (int x = 0; x < nodeList[i].conditionLines.Count; x++) { var line = nodeList [i].conditionLines [x]; var source = line.sourceNode; var target = line.targetNode; if (node == source || node == target) { nodeList [i].conditionLines.Remove(line); } } } if (node.IsNodeType == FSMNodeEditor.ENodeType.Node && nodeList.Contains(node)) { nodeList.Remove(node); } }
public virtual string GetJsonText(FSMNodeEditor node, string condition, string name) { return("{\"condition_name\":\"" + condition + "\",\"state_name\":\"" + name + "\",\"states\": [<<0>>]}"); }
public virtual void OnDraw(FSMNodeEditor node1, FSMNodeEditor node2, Event currentEvent) { OnDraw(node1.nodeRect, node2.nodeRect); sourceNode = node1; targetNode = node2; }
public FSMConditionLineEditor(string name, FSMNodeEditor source, FSMNodeEditor target) { conditionName = name; sourceNode = source; targetNode = target; }
public FSMConditionLineEditor(string name) { conditionName = name; sourceNode = null; targetNode = null; }
public FSMConditionLineEditor() { conditionName = "ConditionName"; sourceNode = null; targetNode = null; }