Last active
November 26, 2018 11:53
-
-
Save nabesi777/851a8081e0bb9e97be7d7355224d3a67 to your computer and use it in GitHub Desktop.
FadeInPlayableBehaviour
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Playables; | |
using System; | |
using UnityEngine.UI; //UIを使用 | |
// A behaviour that is attached to a playable | |
public class FadeInPlayableBehaviour : PlayableBehaviour | |
{ | |
//UIテキストを格納 | |
public GameObject text; | |
//fadeのスピード | |
public float fadeSpeed = 0.02f; | |
public Color textColor; | |
public bool isFadeIn = false; //フェードイン処理の開始、完了を管理するフラグ | |
// クリップスタート時に呼ばれる | |
public override void OnGraphStart(Playable playable) | |
{ | |
//スタート時はテキストのアルファ値を0にする | |
textColor = this.text.GetComponent<Text>().color; | |
textColor.a = 0; | |
this.text.GetComponent<Text>().color = textColor; | |
isFadeIn = true; | |
this.text.SetActive(true); | |
} | |
// Called each frame while the state is set to Play | |
public override void PrepareFrame(Playable playable, FrameData info) | |
{ | |
if(isFadeIn) | |
{ | |
StartFadeIn(); | |
} | |
} | |
void StartFadeIn() | |
{ //テキストアルファ値を徐々に増やしていく | |
textColor.a += fadeSpeed; | |
this.text.GetComponent<Text>().color = textColor; | |
//1以上になったらやめる | |
if (textColor.a > 1) | |
{ | |
isFadeIn = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment