| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using UnityEngine;
- public class GameManager : MonoBehaviour
- {
- private GameData data;
- private SaveManager saveManager;
- private TimeManager timeManager;
- private GameObject player;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
- //Get the player
- player = GameObject.Find("Player");
- if (player == null) return;
- //Get components
- saveManager = GetComponent<SaveManager>();
- timeManager = GetComponent<TimeManager>();
- data = saveManager.LoadGame();
- if (data != null)
- {
- SetData();
- }
- else
- {
- data = new GameData();
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- GetData();
- saveManager.SaveGame(data);
- }
- }
- void GetData()
- {
- data.playerPosition = player.transform.position;
- #region DaylightCycle
- data.minutes = timeManager.Minutes;
- data.hours = timeManager.Hours;
- data.skybox = RenderSettings.skybox;
- data.globalLightColor = timeManager.globalLight.color;
- data.globalLightRotation = timeManager.globalLight.transform.rotation;
- #endregion
- #region Stamina
- data.currentStamina = player.GetComponent<Stamina>().GetCurrentStamina();
- data.maxStamina = player.GetComponent<Stamina>().maxStamina;
- data.canSprint = player.GetComponent<Stamina>().GetCanSprint();
- #endregion
- }
- void SetData()
- {
- player.transform.position = data.playerPosition;
- #region DaylightCycle
- timeManager.Minutes = data.minutes;
- timeManager.Hours = data.hours;
- RenderSettings.skybox = data.skybox;
- timeManager.globalLight.color = data.globalLightColor;
- RenderSettings.fogColor = data.globalLightColor;
- timeManager.globalLight.transform.rotation = data.globalLightRotation;
- #endregion
- #region Stamina
- player.GetComponent<Stamina>().Reinit(data.currentStamina, data.maxStamina, data.canSprint);
- #endregion
- }
- }
|