Skip to content

Instantly share code, notes, and snippets.

@nabesi777
Last active November 26, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabesi777/851a8081e0bb9e97be7d7355224d3a67 to your computer and use it in GitHub Desktop.
Save nabesi777/851a8081e0bb9e97be7d7355224d3a67 to your computer and use it in GitHub Desktop.
FadeInPlayableBehaviour
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