싱글톤으로 만들어서 사용.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TransitionManager : MonoBehaviour { public Image _Image; Color blackColor = Color.black; Color offColor = Color.clear; Color startColor = Color.black; Color targetColor = Color.black; private bool isOnTransition = false; float fadeTime = 0.5f; float delay = 0f; string nextScene = ""; void Start() { BlackIn(0.5f); Debug.Log("fadeIn"); } public void BlackIn(float a_fadeTime = 0.5f, float a_delay = 0f) { fadeTime = a_fadeTime; delay = a_delay; _Image.enabled = true; _Image.color= blackColor; startColor = blackColor; targetColor = offColor; _Image.raycastTarget = false; if (isOnTransition) StopCoroutine("UpdateColorCoroutine"); StartCoroutine("UpdateColorCoroutine"); } public void BlackOut(float a_fadeTime = 0.5f, float a_delay = 0f, string a_nextScene = "") { fadeTime = a_fadeTime; delay = a_delay; nextScene = a_nextScene; _Image.enabled = true; startColor = _Image.color; targetColor = blackColor; _Image.raycastTarget = true; if (isOnTransition) StopCoroutine("UpdateColorCoroutine"); StartCoroutine("UpdateColorCoroutine"); } IEnumerator UpdateColorCoroutine() { isOnTransition = true; if(delay != 0) yield return new WaitForSeconds(delay); float t = 0; while (t < 1) { _Image.color = Color.Lerp(startColor, targetColor, t); t += Time.deltaTime / fadeTime; yield return new WaitForEndOfFrame(); } if (targetColor == Color.clear) // 시간을 지났을 경우! 즉 트랜지션 끝남 _Image.enabled = false; else if(nextScene != "") LoadingManager.LoadScene(nextScene); isOnTransition = false; } } |
'🌍 Unity > 유니티 프로그래밍' 카테고리의 다른 글
유니티 앱 설정 열기 (Unity open App setting) (0) | 2019.11.14 |
---|---|
사운드/오디오 매니저 Unity Sound Manager (0) | 2019.07.29 |
유니티 LINQ 활용하기 (0) | 2019.06.06 |
유니티에서 물리 오류가 나는 경우의 대부분은 FixedUpdate. (0) | 2019.05.29 |
Unity Script checkbox 유니티 스크립트 체크박스가 없을 때 (0) | 2019.05.23 |