示例#1
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;
            }
        }
示例#2
0
 public virtual void DeleteLine(FSMConditionLineEditor line)
 {
     lineList.Remove(line);
 }
        public virtual void OnDraw(int id, Event currentEvent)
        {
            nodeRect = GUILayout.Window(id, nodeRect, NodeFunction, nodeName);
            if (GUI.Button(new Rect(nodeRect.width + nodeRect.x - 50f, nodeRect.height + nodeRect.y + 1f, 20, 20), "x"))
            {
                if (IsNodeType == ENodeType.Node)
                {
                    rootGraph.DeleteNode(this);
                }
            }
            var createConditionRect = new Rect(nodeRect.width + nodeRect.x - 25f, nodeRect.height + nodeRect.y + 1f, 25, 20);

            if (GUI.Button(createConditionRect, OnDrawCondition ? "[]" : "->"))
            {
                m_CurrentLine   = new FSMConditionLineEditor();
                OnDrawCondition = true;
            }
            if (currentEvent.type == EventType.MouseUp)
            {
                m_CurrentLine   = null;
                OnDrawCondition = false;
            }
            if (OnDrawCondition && m_CurrentLine != null)
            {
                m_CurrentLine.OnDraw(this, currentEvent);
                for (int i = 0; i < FSMGraphEditor.nodeList.Count; i++)
                {
                    var node = FSMGraphEditor.nodeList [i];
                    if (node != this &&
                        node.nodeRect.Contains(currentEvent.mousePosition))
                    {
                        var isDuplicatedNode = false;
                        for (int x = 0; x < conditionLines.Count; x++)
                        {
                            if (conditionLines [x].sourceNode == this && conditionLines [x].targetNode == node)
                            {
                                isDuplicatedNode = true;
                                break;
                            }
                        }
                        if (isDuplicatedNode == false)
                        {
                            OnDrawCondition        = false;
                            m_CurrentLine.haveDraw = true;
                            m_CurrentLine.OnDraw(this, node, currentEvent);
                            if (IsNodeType == ENodeType.Node)
                            {
                                conditionLines.Add(m_CurrentLine);
                                FSMGraphEditor.lineList.Add(m_CurrentLine);
                            }
                            else
                            {
                                if (conditionLines.Contains(m_CurrentLine) == false)
                                {
                                    conditionLines.Clear();
                                    m_CurrentLine.conditionName = IsNodeType == ENodeType.Root ? "IsRoot" : "ConditionName";
                                    conditionLines.Add(m_CurrentLine);
                                    FSMGraphEditor.lineList.Add(m_CurrentLine);
                                }
                            }
                            m_CurrentLine = null;
                        }
                    }
                }
            }
            for (int i = 0; i < conditionLines.Count; i++)
            {
                conditionLines [i].OnDraw(currentEvent);
            }
        }