예제 #1
0
        private void Load(FSMData asset)
        {
            if (!asset)
            {
                return;
            }
            currentFSMAsset = asset;
            if (currentFSMAsset.NodeDatas == null || currentFSMAsset.NodeDatas.Count == 0)
            {
                return;
            }

            // 清除Node和Edge
            foreach (var edge in graphView.edges.ToList())
            {
                graphView.RemoveElement(edge);
            }
            foreach (var node in graphView.nodes.ToList())
            {
                graphView.RemoveElement(node);
            }

            foreach (var data in currentFSMAsset.NodeDatas)
            {
                var node = graphView.AddNode(data.Position);
                node.viewDataKey = data.GUID;
                node.SetPosition(new Rect(data.Position, new Vector2(200f, 150f)));
            }

            if (currentFSMAsset.PortDatas == null || currentFSMAsset.PortDatas.Count == 0)
            {
                return;
            }
            foreach (var portData in currentFSMAsset.PortDatas)
            {
                FSMStateNode fromNode = null;
                FSMStateNode toNode   = null;
                foreach (FSMStateNode tempNode in graphView.nodes.ToList())
                {
                    if (tempNode.viewDataKey == portData.FromNodeGUID)
                    {
                        fromNode = tempNode;
                    }
                    if (tempNode.viewDataKey == portData.ToNodeGUID)
                    {
                        toNode = tempNode;
                    }
                }
                if (fromNode == null || toNode == null)
                {
                    continue;
                }
                var fromPort = fromNode.AddCondition();
                if (!string.IsNullOrEmpty(portData.ConditionGUID))
                {
                    fromNode.SetCondition(portData.Index, fromPort, portData.ConditionGUID);
                }
                graphView.Add(fromPort.ConnectTo(toNode.InputPort));
            }
            ;
        }
예제 #2
0
 public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
 {
     fsmNode.SetCondition(selectedPortIndex, selectedPort, searchTreeEntry.userData as FSMVisualCondition);
     return(true);
 }