Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Timeline(5.6b6)で作成した、フェードアウト・フェードイン用。画面最前面にあるImageが必要
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using UnityEngine.UI;
namespace Timeline
{
[System.Serializable]
public class FadeoutPlayable : ScriptPlayable
{
public enum FadeType{ FadeIn, FadeOut }
public FadeType fadeType;
public override void ProcessFrame (FrameData info, object playerData)
{
// Trackから値を取得
var image = (Image)playerData;
// 時間(0-1)を求める
var time = handle.time / handle.duration;
// 透明度を指定
float alpha = (float)(fadeType == FadeType.FadeOut ? time : 1 - time);
var color = image.color;
color.a = alpha;
image.color = color;
}
}
// フェードのタイプを保持するPlayableAsset
[System.Serializable]
public class Fadeout : PlayableAsset, ITimelineClipAsset
{
[SerializeField] FadeoutPlayable.FadeType type = FadeoutPlayable.FadeType.FadeIn;
public override PlayableHandle CreatePlayable(PlayableGraph graph, GameObject go)
{
var handle = graph.CreateScriptPlayable<FadeoutPlayable>();
handle.GetObject<FadeoutPlayable> ().fadeType = type;
return handle;
}
// ブレンドは無し
public ClipCaps clipCaps { get { return ClipCaps.None; } }
}
// Fadeout ScriptPlayableを登録可能で、Imageを登録するトラック
[TrackClipType(typeof(Fadeout))]
[TrackBindingType(typeof(Image))]
public class FadeTrack : TrackAsset{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment