/// <summary> /// Awake function of GameManager. Checks if another instance of this GameObject exists and /// if not, initializes all required atributes and values of the GameManager, creating a new /// one. /// /// If the GameManager already exists, destroy this gameObject. /// </summary> private void Awake() { // If GameManager is not created and initialized... if (_instance == null) { // Set this GameManager as instance _instance = this; // Set this gameObject to not Destroy when changing between scenes DontDestroyOnLoad(gameObject); _gc = LoadingFiles.ReadGameConfig(); // Store canvas' scaling reference resolution _scalingReferenceResolution = _cnv.GetComponent <CanvasScaler>().referenceResolution; // Initialize Scaling with cam values and scalingreference values _scalator = new Scaling(new Vector2(Screen.width, Screen.height), _scalingReferenceResolution, (int)_cam.orthographicSize); // Search all panels for later calculation ReloadPanels(); // Load all AssetBundles _lab = new LoadAssetBundle(); // Depending on OS system, load from a different path and using different techniques #if !UNITY_EDITOR && UNITY_ANDROID _lab.LoadBundlesAndroid(Application.streamingAssetsPath + "/AssetBundles/"); #else _lab.LoadBundlesWindows(Application.streamingAssetsPath + "/AssetBundles/"); #endif // Initialize random value _rnd = new Random(); // Load gameInfo previously generated, data driven information _gi = LoadingFiles.ReadGameInfo(); // Set all values of this information SetGameInfo(); // Get Player information and store it _currentPlayerData = LoadingFiles.ReadPlayerData(_maxDifficulty); // Set the time waiting for challenge info SetTimeForChallenge(); } else if (_instance != this) { Destroy(gameObject); } }
private void Awake() { // Si no se ha inicializado el GameManager en ningún momento, lo crea e inicializa if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); // Nos aseguramos que el canvas tenga la resolución de referencia correcta scalingReferenceResolution = cnv.GetComponent <CanvasScaler>().referenceResolution; // Aquí iría la inicialización de los datos del jugador scalator = new Scaling(new Vector2(Screen.width, Screen.height), scalingReferenceResolution, (int)cam.orthographicSize); // Buscamos los paneles para luego realizar los cálculos ReloadPanels(); lab = new LoadAssetBundle(); #if !UNITY_EDITOR && UNITY_ANDROID lab.LoadBundlesAndroid(Application.streamingAssetsPath + "/AssetBundles/"); #else lab.LoadBundlesWindows(Application.streamingAssetsPath + "/AssetBundles/"); #endif rnd = new Random(); _gi = LoadingFiles.ReadGameInfo(); SetGameInfo(); // GetPlayer information currentPlayerData = LoadingFiles.ReadPlayerData(_maxDifficulty); } else if (instance != this) { Destroy(gameObject); } }