Merge remote-tracking branch 'origin/main' into main

main
Ivy 4 years ago
commit 3b8ad70d7c

@ -1,119 +1,119 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions.Must; using UnityEngine.Assertions.Must;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
public static GameManager Instance { get; private set; } public static GameManager Instance { get; private set; }
public GameObject canvas; public GameObject canvas;
public GameObject spriteToFade; public GameObject spriteToFade;
public GameObject events; public GameObject events;
public GameObject player; public GameObject player;
public List<Powerup> obtainedPowerups = new List<Powerup>{ }; public List<Powerup> obtainedPowerups = new List<Powerup>{ };
public List<bool> powerupStatus = new List<bool>{ }; public List<bool> powerupStatus = new List<bool>{ };
public string sceneToLoad = ""; public string sceneToLoad = "";
void Awake() void Awake()
{ {
if (Instance == null) if (Instance == null)
{ {
Instance = this; Instance = this;
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
DontDestroyOnLoad(canvas); DontDestroyOnLoad(canvas);
DontDestroyOnLoad(events); DontDestroyOnLoad(events);
DontDestroyOnLoad(player); DontDestroyOnLoad(player);
} }
else else
{ {
Destroy(gameObject); Destroy(gameObject);
Destroy(canvas); Destroy(canvas);
Destroy(events); Destroy(events);
DontDestroyOnLoad(player); Destroy(player);
} }
} }
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
if (sceneToLoad != "") if (sceneToLoad != "")
{ {
LoadLevel(sceneToLoad, new Vector3(0, 0, 0)); LoadLevel(sceneToLoad, new Vector3(0, 0, 0));
} }
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
doGliderButtonCheck(); doGliderButtonCheck();
} }
public void LoadLevel(string levelName, Vector3 whereTo) public void LoadLevel(string levelName, Vector3 whereTo)
{ {
StartCoroutine(LerpFunction(Color.black, 0.25f)); StartCoroutine(LerpFunction(Color.black, 0.25f));
StartCoroutine(LoadSceneAsync(levelName, whereTo)); StartCoroutine(LoadSceneAsync(levelName, whereTo));
} }
IEnumerator LoadSceneAsync(string scene, Vector3 whereTo) IEnumerator LoadSceneAsync(string scene, Vector3 whereTo)
{ {
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene); AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene);
// Wait until the asynchronous scene fully loads // Wait until the asynchronous scene fully loads
while (!asyncLoad.isDone) while (!asyncLoad.isDone)
{ {
yield return null; yield return null;
} }
player.transform.position = whereTo; player.transform.position = whereTo;
} }
IEnumerator LerpFunction(Color endValue, float duration) IEnumerator LerpFunction(Color endValue, float duration)
{ {
Image sprite = spriteToFade.GetComponent<Image>(); Image sprite = spriteToFade.GetComponent<Image>();
spriteToFade.SetActive(true); spriteToFade.SetActive(true);
float time = 0; float time = 0;
Color startValue = sprite.color; Color startValue = sprite.color;
while (time < duration) while (time < duration)
{ {
sprite.color = Color.Lerp(startValue, endValue, time / duration); sprite.color = Color.Lerp(startValue, endValue, time / duration);
time += Time.deltaTime; time += Time.deltaTime;
yield return null; yield return null;
} }
sprite.color = endValue; sprite.color = endValue;
spriteToFade.SetActive(false); spriteToFade.SetActive(false);
} }
private void doGliderButtonCheck() private void doGliderButtonCheck()
{ {
if (obtainedPowerups.Contains(Powerup.Glider)) if (obtainedPowerups.Contains(Powerup.Glider))
{ {
if (Input.GetKeyDown("1")) if (Input.GetKeyDown("1"))
{ {
var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider); var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider);
var status = powerupStatus[index]; var status = powerupStatus[index];
if (!status) if (!status)
{ {
player.GetComponent<Glider>().IsGliding = true; player.GetComponent<Glider>().IsGliding = true;
powerupStatus[index] = true; powerupStatus[index] = true;
} }
else else
{ {
player.GetComponent<Glider>().IsGliding = false; player.GetComponent<Glider>().IsGliding = false;
powerupStatus[index] = false; powerupStatus[index] = false;
} }
} }
} }
} }
} }
// } // }
//} //}
//} //}

@ -7,15 +7,18 @@ EditorUserSettings:
m_ConfigSettings: m_ConfigSettings:
RecentlyUsedScenePath-0: RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620d183eedd43b2fe7f578fce9332b25
flags: 0 flags: 0
RecentlyUsedScenePath-1: RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0 value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e52637edea78fce9332b25
flags: 0 flags: 0
RecentlyUsedScenePath-2: RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b
flags: 0 flags: 0
RecentlyUsedScenePath-3: RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b
value: 22424703114646680e0b0227036c72110203102f3b1c2323391a1e36ece57a2decee22f0
flags: 0 flags: 0
RecentlyUsedScenePath-4: RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b
@ -31,6 +34,7 @@ EditorUserSettings:
flags: 0 flags: 0
RecentlyUsedScenePath-8: RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1220f1d23b37efa923e7ee2e26 value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1220f1d23b37efa923e7ee2e26
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0
flags: 0 flags: 0
RecentlyUsedScenePath-9: RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d32f5ee7a2decee22f0 value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d32f5ee7a2decee22f0

Loading…
Cancel
Save