UHSampleGame.CoreObjects.Units.Unit.UpdatePath C# (CSharp) Method

UpdatePath() public method

public UpdatePath ( ) : void
return void
        void UpdatePath()
        {
            SetCurrentTile(TileMap.GetTileFromPos(Position).ID);
            if (CurrentTileID == goalTileID)
                return;
            if (CheckIfStuck())
                return;

            if (!TileMap.Tiles[focalTileID].IsWalkable())
            {
                lock (AStar2.locks[CurrentTileID][goalTileID])
                {
                    SetFocalPointAndVelocity(TileMap.Tiles[CurrentTileID].PathsInts[goalTileID][1]);//currentTile.Paths[goalTile.ID][1]);
                }
            }

            if (TileMap.Tiles[CurrentTileID].TileType == TileType.Blocked)
            {
                if (TileMap.Tiles[previousTileID].PathsInts[goalTileID].Count > 1)
                {
                    lock (AStar2.locks[CurrentTileID][goalTileID])
                    {
                        SetFocalPointAndVelocity(TileMap.Tiles[previousTileID].PathsInts[goalTileID][1]);//previousTile.Paths[goalTile.ID][1]);
                    }
                }
                else
                {
                    List<Tile> goodNieghbors = TileMap.GetWalkableNeighbors(TileMap.Tiles[CurrentTileID]);
                    if (goodNieghbors.Count > 0)
                    {
                        for (int i = 0; i < goodNieghbors.Count; i++)
                        {
                            if (goodNieghbors[i].PathsInts[goalTileID].Count > 0)
                            {
                                lock (AStar2.locks[CurrentTileID][goalTileID])
                                {
                                    SetFocalPointAndVelocity(goodNieghbors[i].PathsInts[goalTileID][1]);
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        Health = 0;
                        OnDied();
                        //throw new NotImplementedException("NO walkable neighbors... handle this!");
                    }
                }

                if (CheckIfStuck())
                    return;
            }

            if (CurrentTileID != previousTileID)
            {
                lock (AStar2.locks[CurrentTileID][goalTileID])
                {
                    SetFocalPointAndVelocity(TileMap.Tiles[CurrentTileID].PathsInts[goalTileID][1]);//currentTile.Paths[goalTile.ID][1]);
                }
            }

            UpdatePositionAndRotation();
        }