コード例 #1
0
 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;
 }
コード例 #2
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;
            }
        }
コード例 #3
0
 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);
 }
コード例 #4
0
        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();
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 public virtual string GetJsonText(FSMNodeEditor node, string condition, string name)
 {
     return("{\"condition_name\":\""
            + condition + "\",\"state_name\":\""
            + name + "\",\"states\": [<<0>>]}");
 }
コード例 #7
0
 public virtual void OnDraw(FSMNodeEditor node1, FSMNodeEditor node2, Event currentEvent)
 {
     OnDraw(node1.nodeRect, node2.nodeRect);
     sourceNode = node1;
     targetNode = node2;
 }
コード例 #8
0
 public FSMConditionLineEditor(string name, FSMNodeEditor source, FSMNodeEditor target)
 {
     conditionName = name;
     sourceNode    = source;
     targetNode    = target;
 }
コード例 #9
0
 public FSMConditionLineEditor(string name)
 {
     conditionName = name;
     sourceNode    = null;
     targetNode    = null;
 }
コード例 #10
0
 public FSMConditionLineEditor()
 {
     conditionName = "ConditionName";
     sourceNode    = null;
     targetNode    = null;
 }