コード例 #1
0
 private Vector3 GetExitDirection(LoadingZone zone)
 {
     return(Vector3.Normalize(zone.transform.forward));
 }
コード例 #2
0
            /// <summary>
            /// Translates a unit a specified value in the X, Y and Z planes.
            /// </summary>
            /// <param name="unit">The unit whose position will be translated.</param>
            /// <param name="x">Amount of tiles to travel in the X axis.</param>
            /// <param name="y">Amount of tiles to travel in the Y axis.</param>
            /// <param name="z">Amount of tiles to travel in the Z axis.</param>
            /// <returns>Returns true if the overworld object moved successfully, and false otherwise.</returns>
            public bool Move(OverworldObject overworldObject, int x, int y, int z)
            {
                Vector3Int zyTranslation = UtilityFunctions.TranslateZAsY(new Vector3Int(x, y, z));

                x = zyTranslation.x;
                y = zyTranslation.y;

                Vector3Int currentPosition  = overworldObject.position;
                Vector3Int newPosition      = new Vector3Int(currentPosition.x + x, currentPosition.y + y, currentPosition.z + z);
                Vector3Int highestFloorTile = GetHighestFloorTileAtPosition(newPosition);

                Directions moveDirection;

                if (Math.Abs(x) > Math.Abs(y))
                {
                    if (x >= 0)
                    {
                        moveDirection = Directions.NE;
                    }
                    else
                    {
                        moveDirection = Directions.SW;
                    }
                }
                else if (Math.Abs(x) < Math.Abs(y))
                {
                    if (y >= 0)
                    {
                        moveDirection = Directions.NW;
                    }
                    else
                    {
                        moveDirection = Directions.SE;
                    }
                }
                else
                {
                    moveDirection = overworldObject.direction;
                }

                if (overworldObject.canTurn)
                {
                    overworldObject.direction = moveDirection;
                }

                if (IsTileOpen(newPosition, false) && !overworldObject.isStationary && !geography.HasTile(newPosition) && highestFloorTile.z != -255)
                {
                    Vector3Int oldPosition = overworldObject.position;
                    Vector3Int tileToPlace = newPosition;

                    overworldObject.position = tileToPlace;


                    DelayMovements(overworldObject, z);
                    if (overworldObject is Unit)
                    {
                        CheckHitboxesAtUnit((Unit)overworldObject);
                    }

                    //if unit moved was the player, check for loading zones
                    if (UtilityFunctions.GetActivePlayer().GetCurrentOverworldObject().Equals(overworldObject))
                    {
                        LoadingZone loadingZone = GetLoadingZoneAtPosition(overworldObject.position);

                        if (loadingZone != null /*&& !UtilityFunctions.GetActiveEncounter().IsEncounterActive()*/)
                        {
                            loadingZone.LoadZone(overworldObject);
                        }
                    }

                    return(true);
                }

                return(false);
            }