예제 #1
0
파일: GridGraph.cs 프로젝트: myth326/ecs
        public void ResetConnections(int sourceIndex)
        {
            var connection = new Node.Connection()
            {
                index = -1,
                cost  = 0f
            };

            var node = this.GetNodeByIndex <GridNode>(sourceIndex);

            for (int i = 0; i < node.connections.Length; ++i)
            {
                node.connections[i] = connection;
            }
        }
예제 #2
0
파일: GridGraph.cs 프로젝트: myth326/ecs
        public void SetupConnectionByDirection(int sourceIndex, Direction direction)
        {
            var connection = new Node.Connection()
            {
                index = -1,
                cost  = 0f
            };
            var node   = this.GetNodeByIndex <GridNode>(sourceIndex);
            var target = GridGraphUtilities.GetIndexByDirection(this, sourceIndex, direction);

            if (target >= 0)
            {
                var targetNode = this.GetNodeByIndex <GridNode>(target);
                var cost       = (node.worldPosition - targetNode.worldPosition).sqrMagnitude;
                connection.cost  = cost * (GridGraphUtilities.IsDiagonalDirection(direction) == true ? this.diagonalCostFactor : 1f) + targetNode.penalty;
                connection.index = target;
            }

            node.connections[(int)direction] = connection;
        }