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.
94 lines
2.0 KiB
94 lines
2.0 KiB
2 years ago
|
using ExitGames.Client.Photon;
|
||
|
using Photon.Pun;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class GameManager : MonoBehaviour {
|
||
|
|
||
|
public static GameManager Instance {
|
||
|
get;
|
||
|
set;
|
||
|
}
|
||
|
|
||
|
[Header("Settings")]
|
||
|
public bool loadDefaultSettings;
|
||
|
public bool autoSaveSettings;
|
||
|
|
||
|
private Dictionary<string, string> resources;
|
||
|
|
||
|
[HideInInspector]
|
||
|
public Settings settings;
|
||
|
|
||
|
|
||
|
//Game values to be hold
|
||
|
[HideInInspector]
|
||
|
public List<CircuitAmount> circuitAmounts;
|
||
|
[HideInInspector]
|
||
|
public int restPoints;
|
||
|
|
||
|
|
||
|
void Awake() {
|
||
|
|
||
|
//Manage Singleton
|
||
|
if (Instance != null && Instance != this)
|
||
|
Destroy(gameObject);
|
||
|
else
|
||
|
Instance = this;
|
||
|
DontDestroyOnLoad(gameObject);
|
||
|
|
||
|
SceneManager.sceneLoaded += OnSceneFinishedLoading;
|
||
|
|
||
|
|
||
|
//Edit this
|
||
|
resources = new Dictionary<string, string> {
|
||
|
{"Settings", Application.persistentDataPath + "/settings.dat"}
|
||
|
};
|
||
|
Settings.fileName = "settings.dat";
|
||
|
|
||
|
|
||
|
if (loadDefaultSettings)
|
||
|
settings = Settings.CreateDefault();
|
||
|
else
|
||
|
settings = Settings.Load(resources["Settings"]);
|
||
|
}
|
||
|
|
||
|
private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode) {
|
||
|
Debug.Log("Scene loaded: " + scene.name);
|
||
|
if (scene.name == "Main") {
|
||
|
CameraController.Instance.gameObject.SetActive(true);
|
||
|
GUIController.Instance.state = MenuState.Lobby;
|
||
|
GUIController.Instance.OpenMenu();
|
||
|
}
|
||
|
PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable() { ["CurrentScene"] = scene.buildIndex });
|
||
|
AudioManager.Instance.FadeMusicForScene(scene.buildIndex);
|
||
|
}
|
||
|
|
||
|
public void ApplySettings(Settings newSettings) {
|
||
|
settings = newSettings;
|
||
|
|
||
|
if (autoSaveSettings)
|
||
|
Settings.Save(settings, resources["Settings"]);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public Button settingsButton;
|
||
|
public GameObject settingsPanel;
|
||
|
|
||
|
private void Update() {
|
||
|
if (Input.GetKeyDown(KeyCode.Escape)) {
|
||
|
OpenSettingsMenu();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OpenSettingsMenu() {
|
||
|
if (SceneManager.GetActiveScene().name == "Main") {
|
||
|
settingsButton.onClick.Invoke();
|
||
|
} else {
|
||
|
settingsPanel.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
}
|