8 #if UNITY_2017_2_OR_NEWER 20 [Tooltip(
"If true, the FadeManager will update the shared material. Useful for fading multiple cameras that each render different layers.")]
23 private Material fadeMaterial;
24 private Color fadeColor = Color.black;
26 private enum FadeState
37 return currentState != FadeState.idle;
41 private FadeState currentState;
42 private float startTime;
43 private float fadeOutTime;
44 private Action fadeOutAction;
45 private float fadeInTime;
46 private Action fadeInAction;
52 #if UNITY_2017_2_OR_NEWER 53 if (!HolographicSettings.IsDisplayOpaque)
55 if (VRDevice.isPresent)
65 currentState = FadeState.idle;
66 fadeMaterial = FadeSharedMaterial
67 ? GetComponentInChildren<MeshRenderer>().sharedMaterial
68 : GetComponentInChildren<MeshRenderer>().material;
79 private void CalculateFade()
81 float actionTime = currentState == FadeState.fadingOut ? fadeOutTime : fadeInTime;
82 float timeBusy = Time.realtimeSinceStartup - startTime;
83 float timePercentUsed = timeBusy / actionTime;
84 if (timePercentUsed >= 1.0f)
86 Action callback = currentState == FadeState.fadingOut ? fadeOutAction : fadeInAction;
92 fadeColor.a = currentState == FadeState.fadingOut ? 1 : 0;
93 fadeMaterial.color = fadeColor;
95 currentState = currentState == FadeState.fadingOut ? FadeState.FadingIn : FadeState.idle;
96 startTime = Time.realtimeSinceStartup;
100 fadeColor.a = currentState == FadeState.fadingOut ? timePercentUsed : 1 - timePercentUsed;
101 fadeMaterial.color = fadeColor;
107 if (fadeMaterial != null && !FadeSharedMaterial)
109 Destroy(fadeMaterial);
115 public bool DoFade(
float _fadeOutTime,
float _fadeInTime, Action _fadedOutAction, Action _fadedInAction)
119 Debug.Log(
"Already fading");
123 fadeOutTime = _fadeOutTime;
124 fadeOutAction = _fadedOutAction;
125 fadeInTime = _fadeInTime;
126 fadeInAction = _fadedInAction;
128 startTime = Time.realtimeSinceStartup;
129 currentState = FadeState.fadingOut;