/// <summary>
    /// This method generates all the nodes available for the pathfinding (no visual overlays).
    /// </summary>
    private void GeneratePossibleMoves()
    {
        GraphNodes.Clear();

        ConstantPath path = ConstantPath.Construct(selected.transform.position, selected.unitData.stats.Ap * 750);

        path.traversalProvider = selected.traversalProvider;

        AstarPath.StartPath(path);

        path.BlockUntilCalculated();

        foreach (GraphNode node in path.allNodes)
        {
            if (node != path.startNode)
            {
                GameObject go = Instantiate(nodePrefab, (Vector3)node.position, Quaternion.identity);
                possibleMoves.Add(go);

                go.GetComponent <AStarNode>().node = node;
                node.position.z = 0;

                GraphNodes.Add((Vector3)node.position);
            }
        }
    }
Пример #2
0
    public static Vector3 RandomPointConstantPath(Vector3 origin, int searchLength)
    {
        ConstantPath path = ConstantPath.Construct(origin, searchLength);

        AstarPath.StartPath(path);
        path.BlockUntilCalculated();

        var randomPoint = PathUtilities.GetPointsOnNodes(path.allNodes, 1)[0];

        return(randomPoint);
    }
        // Token: 0x06002A30 RID: 10800 RVA: 0x001C7418 File Offset: 0x001C5618
        private void GeneratePossibleMoves(TurnBasedAI unit)
        {
            ConstantPath constantPath = ConstantPath.Construct(unit.transform.position, unit.movementPoints * 1000 + 1, null);

            constantPath.traversalProvider = unit.traversalProvider;
            AstarPath.StartPath(constantPath, false);
            constantPath.BlockUntilCalculated();
            foreach (GraphNode graphNode in constantPath.allNodes)
            {
                if (graphNode != constantPath.startNode)
                {
                    GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.nodePrefab, (Vector3)graphNode.position, Quaternion.identity);
                    this.possibleMoves.Add(gameObject);
                    gameObject.GetComponent <Astar3DButton>().node = graphNode;
                }
            }
        }
Пример #4
0
        public void GeneratePossibleMoves(Unit.Unit unit)
        {
            ConstantPath path       = null;
            GameObject   nodePrefab = null;

            if (UnitStateManager.currentState == State.SelectAttackTarget)
            {
                path       = ConstantPath.Construct(unit.transform.position, unit.AttackRangePoints * 1000 + 1);
                nodePrefab = nodePrefabs[1];
            }
            else if (UnitStateManager.currentState == State.SelectMoveTarget)
            {
                path                   = ConstantPath.Construct(unit.transform.position, unit.MovementPoints * 1000 + 1);
                nodePrefab             = nodePrefabs[0];
                path.traversalProvider = unit.TraversalProvider;
            }

            // Schedule the path for calculation
            AstarPath.StartPath(path);

            // Force the path request to complete immediately
            // This assumes the graph is small enough that
            // this will not cause any lag
            if (path == null)
            {
                return;
            }
            path.BlockUntilCalculated();

            foreach (var node in path.allNodes)
            {
                if (node != path.startNode)
                {
                    // Create a new node prefab to indicate a node that can be reached
                    // NOTE: If you are going to use this in a real game, you might want to
                    // use an object pool to avoid instantiating new GameObjects all the time
                    var go = Instantiate(nodePrefab, (Vector3)node.position, Quaternion.identity);
                    possibleMoves.Add(go);

                    go.GetComponent <MoveReservable>().Node = node;
                }
            }

            OnPathHasBeenGenerated?.Invoke(true);
        }