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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
using System;
public class CameraFade : MonoBehaviour
{
public event Action OnFadeComplete; //Camera Fade In,Out 완료시 호출
[SerializeField] private bool fadeInOnStart = true;
[SerializeField] private bool fadeInOnSceneLoad = false;
[SerializeField] private float fadeDuration = 2f;
[SerializeField] private Image fadeImage;
private bool isFading;
private float fadeStartTime;
private Color fadeOutColor;
public bool IsFading
{
get
{
return isFading;
}
}
private void Awake()
{
SceneManager.sceneLoaded += HandleSceneLoaded;
fadeOutColor = new Color(fadeColor.r, fadeColor.g, fadeColor.b, 0f);
fadeImage.enabled = true;
}
// Start is called before the first frame update
void Start()
{
if(fadeInOnStart)
{
fadeImage.color = fadeColor;
FadeIn();
}
}
private void HandleSceneLoaded(Scene arg0, LoadSceneMode arg1)
{
if(fadeInOnSceneLoad)
{
fadeImage.color = fadeColor;
FadeIn();
}
}
public void FadeIn()
{
if (isFading)
return;
StartCoroutine(BeginFade(fadeColor, fadeOutColor, fadeDuration));
}
public void FadeOut()
{
if (isFading)
return;
StartCoroutine(BeginFade(fadeOutColor,fadeColor, fadeDuration));
}
public IEnumerator BeginFadeOut()
{
yield return StartCoroutine(BeginFade(fadeOutColor, fadeColor, fadeDuration));
}
public IEnumerator BeginFadeIn()
{
yield return StartCoroutine(BeginFade(fadeColor, fadeOutColor, fadeDuration));
}
private IEnumerator BeginFade(Color startCol, Color endCol , float duration)
{
//Start Fade
isFading = true;
float timer = 0f;
while(timer <= duration)
{
timer += Time.deltaTime;
yield return null;
}
isFading = false;
if (OnFadeComplete != null)
OnFadeComplete();
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= HandleSceneLoaded;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|