|
@@ -1,18 +1,31 @@
|
|
|
|
|
+using System;
|
|
|
|
|
+using System.Collections;
|
|
|
|
|
+using System.Linq;
|
|
|
|
|
+using TMPro;
|
|
|
|
|
+using UnityEditor;
|
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
+using UnityEngine.SocialPlatforms.Impl;
|
|
|
|
|
|
|
|
public class GameManager : MonoBehaviour
|
|
public class GameManager : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
|
|
+ public int GameOverHour;
|
|
|
|
|
+ public int GameOverMinutes;
|
|
|
|
|
+
|
|
|
private GameData data;
|
|
private GameData data;
|
|
|
|
|
|
|
|
private SaveManager saveManager;
|
|
private SaveManager saveManager;
|
|
|
private TimeManager timeManager;
|
|
private TimeManager timeManager;
|
|
|
private MapGenerator mapGenerator;
|
|
private MapGenerator mapGenerator;
|
|
|
|
|
+ private OrbManager orbManager;
|
|
|
|
|
+ public TMP_Text UI;
|
|
|
|
|
|
|
|
private GameObject player;
|
|
private GameObject player;
|
|
|
|
|
+ private int score;
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
void Start()
|
|
void Start()
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
//Get the player
|
|
//Get the player
|
|
|
player = GameObject.Find("Player");
|
|
player = GameObject.Find("Player");
|
|
|
if (player == null) return;
|
|
if (player == null) return;
|
|
@@ -21,8 +34,15 @@ public class GameManager : MonoBehaviour
|
|
|
saveManager = GetComponent<SaveManager>();
|
|
saveManager = GetComponent<SaveManager>();
|
|
|
timeManager = GetComponent<TimeManager>();
|
|
timeManager = GetComponent<TimeManager>();
|
|
|
mapGenerator = GameObject.Find("Map Generator").GetComponent<MapGenerator>();
|
|
mapGenerator = GameObject.Find("Map Generator").GetComponent<MapGenerator>();
|
|
|
|
|
+ orbManager = GetComponent<OrbManager>();
|
|
|
|
|
|
|
|
data = saveManager.LoadGame();
|
|
data = saveManager.LoadGame();
|
|
|
|
|
+
|
|
|
|
|
+ if (data.Orbs.Length == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ StartCoroutine(orbManager.StartSpawn());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//reset light settings
|
|
//reset light settings
|
|
|
RenderSettings.skybox.SetTexture("_Texture1", timeManager.skyboxNight);
|
|
RenderSettings.skybox.SetTexture("_Texture1", timeManager.skyboxNight);
|
|
|
RenderSettings.skybox.SetTexture("_Texture2", timeManager.skyboxSunrise);
|
|
RenderSettings.skybox.SetTexture("_Texture2", timeManager.skyboxSunrise);
|
|
@@ -45,18 +65,27 @@ public class GameManager : MonoBehaviour
|
|
|
void Update()
|
|
void Update()
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- if (Input.GetKeyDown(KeyCode.F5))
|
|
|
|
|
|
|
+ if (Input.GetKeyDown(KeyCode.F5))
|
|
|
{
|
|
{
|
|
|
Save();
|
|
Save();
|
|
|
}
|
|
}
|
|
|
- if (Input.GetKeyDown(KeyCode.F9))
|
|
|
|
|
|
|
+ if (Input.GetKeyDown(KeyCode.F9))
|
|
|
{
|
|
{
|
|
|
//SceneManager.LoadScene("Game");
|
|
//SceneManager.LoadScene("Game");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if(timeManager.Hours >= GameOverHour && timeManager.Minutes >= GameOverMinutes)
|
|
|
|
|
+ {
|
|
|
|
|
+ OnGameOver();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
void GetData()
|
|
void GetData()
|
|
|
{
|
|
{
|
|
|
|
|
+ #region PlayerAndOrbs
|
|
|
data.playerPosition = player.transform.position;
|
|
data.playerPosition = player.transform.position;
|
|
|
|
|
+ data.playerScore = score;
|
|
|
|
|
+ data.Orbs = GetAllOrbs();
|
|
|
|
|
+ #endregion
|
|
|
|
|
|
|
|
#region DaylightCycle
|
|
#region DaylightCycle
|
|
|
data.minutes = timeManager.Minutes;
|
|
data.minutes = timeManager.Minutes;
|
|
@@ -79,8 +108,19 @@ public class GameManager : MonoBehaviour
|
|
|
|
|
|
|
|
void SetData()
|
|
void SetData()
|
|
|
{
|
|
{
|
|
|
|
|
+ #region PlayerAndOrbs
|
|
|
if (data.playerPosition != Vector3.zero)
|
|
if (data.playerPosition != Vector3.zero)
|
|
|
|
|
+ {
|
|
|
player.transform.position = data.playerPosition;
|
|
player.transform.position = data.playerPosition;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ StartCoroutine(SpawnPlayer());
|
|
|
|
|
+ }
|
|
|
|
|
+ score = data.playerScore;
|
|
|
|
|
+ UpdateUI();
|
|
|
|
|
+ SpawnOrbs();
|
|
|
|
|
+ #endregion
|
|
|
|
|
|
|
|
#region DaylightCycle
|
|
#region DaylightCycle
|
|
|
|
|
|
|
@@ -90,11 +130,11 @@ public class GameManager : MonoBehaviour
|
|
|
if (data.skybox != null)
|
|
if (data.skybox != null)
|
|
|
RenderSettings.skybox = data.skybox;
|
|
RenderSettings.skybox = data.skybox;
|
|
|
|
|
|
|
|
- if(data.globalLightColor != null)
|
|
|
|
|
|
|
+ if (data.globalLightColor != null)
|
|
|
{
|
|
{
|
|
|
timeManager.globalLight.color = data.globalLightColor;
|
|
timeManager.globalLight.color = data.globalLightColor;
|
|
|
RenderSettings.fogColor = data.globalLightColor;
|
|
RenderSettings.fogColor = data.globalLightColor;
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (data.globalLightRotation != null)
|
|
if (data.globalLightRotation != null)
|
|
|
timeManager.globalLight.transform.rotation = data.globalLightRotation;
|
|
timeManager.globalLight.transform.rotation = data.globalLightRotation;
|
|
@@ -102,7 +142,7 @@ public class GameManager : MonoBehaviour
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region Stamina
|
|
#region Stamina
|
|
|
- if(data.skybox !=null) //because !
|
|
|
|
|
|
|
+ if (data.skybox != null) //because !
|
|
|
player.GetComponent<Stamina>().Reinit(data.currentStamina, data.canSprint);
|
|
player.GetComponent<Stamina>().Reinit(data.currentStamina, data.canSprint);
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -113,10 +153,61 @@ public class GameManager : MonoBehaviour
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ IEnumerator SpawnPlayer()
|
|
|
|
|
+ {
|
|
|
|
|
+ yield return new WaitForSeconds(3);
|
|
|
|
|
+ Vector3 rayStart = Vector3.zero + Vector3.up * 300;
|
|
|
|
|
+
|
|
|
|
|
+ if (Physics.Raycast(rayStart, Vector3.down, out RaycastHit hit, 600f))
|
|
|
|
|
+ {
|
|
|
|
|
+ player.transform.position = hit.point + new Vector3(0f, 1f, 0f);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void SpawnOrbs()
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int i = 0; i < data.Orbs.Length; i++) {
|
|
|
|
|
+ Instantiate(orbManager.prefab, data.Orbs[i], Quaternion.identity);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Vector3[] GetAllOrbs()
|
|
|
|
|
+ {
|
|
|
|
|
+ string targetName = "Orb(Clone)";
|
|
|
|
|
+ var actors = FindObjectsByType<GameObject>(FindObjectsSortMode.None)
|
|
|
|
|
+ .Where(obj => obj.name == targetName)
|
|
|
|
|
+ .ToArray();
|
|
|
|
|
+
|
|
|
|
|
+ Vector3[] orbs = new Vector3[actors.Length];
|
|
|
|
|
+ for (int i = 0; i < actors.Length; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ orbs[i] = actors[i].transform.position;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return orbs;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void Save()
|
|
public void Save()
|
|
|
{
|
|
{
|
|
|
GetData();
|
|
GetData();
|
|
|
saveManager.SaveGame(data);
|
|
saveManager.SaveGame(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void IncreaseScore()
|
|
|
|
|
+ {
|
|
|
|
|
+ score++;
|
|
|
|
|
+ UpdateUI();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void UpdateUI()
|
|
|
|
|
+ {
|
|
|
|
|
+ UI.text = score.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void OnGameOver()
|
|
|
|
|
+ {
|
|
|
|
|
+ Save();
|
|
|
|
|
+ Debug.Log("you died");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|