using System.Collections.Generic;
using UnityEngine;
///
/// 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.
///
public static class GameState
{
// The Player class maintains character stats for the player
public static Player CurrentPlayer = ScriptableObject.CreateInstance();
// This dictionary helps scenes keep track of the player's position on the map
public static Dictionary LastScenePositions = new Dictionary();
// 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;
///
/// 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.
///
///
///
public static Vector3 GetLastScenePosition(string sceneName)
{
if (GameState.LastScenePositions.ContainsKey(sceneName))
{
var lastPos = GameState.LastScenePositions[sceneName];
return lastPos;
}
else
{
return Vector3.zero;
}
}
///
/// This method allows a scene to save a character's position when the player leaves the scene.
///
///
///
public static void SetLastScenePosition(string sceneName, Vector3 position)
{
if (GameState.LastScenePositions.ContainsKey(sceneName))
{
GameState.LastScenePositions[sceneName] = position;
}
else
{
GameState.LastScenePositions.Add(sceneName, position);
}
}
}