コード例 #1
0
        private void PopulateGraph()
        {
            var loadFromCache =
                _nodePositionCache.ValidateCache(_target.GetAllBehaviourNodes()
                                                 .Select(behaviour => behaviour.Guid));

            ClearGraph();
            var actionBehaviourNodes = _target.GetActionBehaviourNodes().ToArray();

            var stepX        = Mathf.Max(100, position.width / actionBehaviourNodes.Length);
            var nodePosition = new Vector2(stepX / 2, position.height - 100);

            foreach (var actionBehaviourNode in actionBehaviourNodes)
            {
                if (loadFromCache)
                {
                    nodePosition = _nodePositionCache.GetCachedPosition(actionBehaviourNode.Guid);
                }

                CreateNode(nodePosition, actionBehaviourNode);
                nodePosition.x += stepX;
            }

            var compoundBehaviourNodes = _target.GetCompoundBehaviourNodes().ToArray();

            stepX        = Mathf.Max(100, position.width / compoundBehaviourNodes.Length);
            nodePosition = new Vector2(stepX / 2, nodePosition.y - 100);
            foreach (var compoundBehaviourNode in compoundBehaviourNodes)
            {
                if (loadFromCache)
                {
                    nodePosition = _nodePositionCache.GetCachedPosition(compoundBehaviourNode.Guid);
                }

                CreateCompoundNode(nodePosition, compoundBehaviourNode);
                nodePosition.x += stepX;
            }

            foreach (var compoundBehaviourNode in compoundBehaviourNodes)
            {
                var topNode = (CompoundNode)_nodes[compoundBehaviourNode.Guid];

                foreach (var childNodeGuid in compoundBehaviourNode.GetChildNodes())
                {
                    topNode.AddOutConnectionPoint();

                    if (!loadFromCache)
                    {
                        var bottomNode = _nodes[childNodeGuid];
                        if (bottomNode is CompoundNode)
                        {
                            topNode.Rect.y = Mathf.Min(bottomNode.Rect.y - 100, topNode.Rect.y);
                            UpdateCacheNodePosition(topNode);
                        }
                    }
                }
            }

            Repaint();
        }