コード例 #1
0
ファイル: Actor.cs プロジェクト: xjab96/Im-A-Follower-Game
    protected virtual void Start()
    {
        tilemapNodes = TilemapNodes.Instance;

        pathFinder         = GetComponent <AStarPathFinding>();
        currentMapNode     = tilemapNodes.GetNearestNode(new Vector2(0, 0));
        transform.position = currentMapNode.position;

        startMovementTransform       = transform;
        startMovementRotation        = sprite.transform.rotation;
        currentMapNode.isTraversable = false;
    }
コード例 #2
0
    public List <PathNode> GeneratePath(PathNode start, PathNode goal, TilemapNodes tileMapNodes)
    {
        List <PathNode> openList   = new List <PathNode>();
        List <PathNode> closedList = new List <PathNode>();

        start.g = 0;
        start.h = FindH(start, goal);
        start.f = start.g + start.h;
        openList.Add(start);

        while (openList.Count != 0)
        {
            PathNode current = openList[0];
            foreach (var node in openList)
            {
                if (node.f < current.f)
                {
                    current = node;
                }
            }
            if (current == goal)
            {
                return(ReconstructPath(start, current));
            }

            openList.Remove(current);
            closedList.Add(current);

            List <PathNode> neighbors = tileMapNodes.GetAdjacent(current);
            if (neighbors.Count == 0)
            {
                //The piece is trapped so cant path
                return(neighbors);
            }
            foreach (var i in neighbors)
            {
                if (!closedList.Contains(i))
                {
                    i.g = current.g + 1;
                    i.h = FindH(i, goal);
                    i.f = i.g + i.h;

                    i.cameFromNode = current;
                    if (!openList.Contains(i))
                    {
                        openList.Add(i);
                    }
                }
            }
        }
        //Open set is empty but no path was found
        return(new List <PathNode>());
    }
コード例 #3
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
         DontDestroyOnLoad(this);
     }
     GenerateNodes();
 }