Created
November 19, 2017 13:58
-
-
Save tarukosu/c0ebe1f6326c272e9967d9ad5fc6d088 to your computer and use it in GitHub Desktop.
FadePlayableBehaviour.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Playables; | |
public class FadePlayableBehaviour : PlayableBehaviour | |
{ | |
public GameObject targetObject; | |
public bool IsFadeOut; | |
private Renderer[] renderers; | |
public override void ProcessFrame(Playable playable, FrameData info, object playerData) | |
{ | |
if (targetObject == null) { | |
return; | |
} | |
if(renderers == null) | |
{ | |
renderers = targetObject.GetComponentsInChildren<Renderer>(); | |
} | |
var currentTime = (float)playable.GetTime() / (float)playable.GetDuration(); | |
for(int i=0; i<renderers.Length; i++) | |
{ | |
var color = renderers[i].material.color; | |
color.a = IsFadeOut ? 1 - Mathf.Clamp01(currentTime) : Mathf.Clamp01(currentTime); | |
renderers[i].material.color = color; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment