You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.2 KiB
56 lines
2.2 KiB
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
/// <summary> |
|
/// This is a static class that loads with the game and maintains objects across scenes. |
|
/// In other words, this is a collection of globals. This script is not attached to a specific |
|
/// game object in any scene. Since it is static, it will be available all of the time. |
|
/// </summary> |
|
public static class GameState |
|
{ |
|
// The Player class maintains character stats for the player |
|
public static Player CurrentPlayer = ScriptableObject.CreateInstance<Player>(); |
|
// This dictionary helps scenes keep track of the player's position on the map |
|
public static Dictionary<string, Vector3> LastScenePositions = new Dictionary<string, Vector3>(); |
|
// This switch prevents a situation in which the scene can start switching between the |
|
// world and a battle scene in an infinite loop. |
|
public static bool justExitedBattle; |
|
// This switch prevents an infinite loop between locations (towns) on the world map and the world map |
|
public static bool saveLastPosition = true; |
|
|
|
/// <summary> |
|
/// This method gets that last known position of the player on the given scene. This allows a |
|
/// scene to place the player at the last know position within that same scene. |
|
/// </summary> |
|
/// <param name="sceneName"></param> |
|
/// <returns></returns> |
|
public static Vector3 GetLastScenePosition(string sceneName) |
|
{ |
|
if (GameState.LastScenePositions.ContainsKey(sceneName)) |
|
{ |
|
var lastPos = GameState.LastScenePositions[sceneName]; |
|
return lastPos; |
|
} |
|
else |
|
{ |
|
return Vector3.zero; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// This method allows a scene to save a character's position when the player leaves the scene. |
|
/// </summary> |
|
/// <param name="sceneName"></param> |
|
/// <param name="position"></param> |
|
public static void SetLastScenePosition(string sceneName, Vector3 position) |
|
{ |
|
if (GameState.LastScenePositions.ContainsKey(sceneName)) |
|
{ |
|
GameState.LastScenePositions[sceneName] = position; |
|
} |
|
else |
|
{ |
|
GameState.LastScenePositions.Add(sceneName, position); |
|
} |
|
} |
|
} |