[ExecuteAlways]
public class ExecuteAlwaysTest : MonoBehaviour
{
// Start is called before the first frame updatevoid Start()
{
Debug.Log("Start");
}
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
var time = playable.GetTime();
var duration = playable.GetDuration();
}
public class CustomTimelineClipPlayable : PlayableBehaviour
{
public Color StartColor = Color.white;
public Color EndColor = Color.white;
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
var image = playerData as Image;
if (image != null)
{
var duration = playable.GetDuration();
var time = playable.GetTime();
image.color = Color.Lerp(StartColor, EndColor, (float) (time / duration));
}
}
}
[System.Serializable]
public class CustomTimeLinePlayableAsset : PlayableAsset
{
public Color startColor = Color.white;
public Color endColor = Color.white;
// Factory method that generates a playable based on this asset
public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
{
var playable = ScriptPlayable<CustomTimelineClipPlayable>.Create(graph);
var behaviour = playable.GetBehaviour();
// PlayableへInspectorでの設定値を渡しています。
behaviour.StartColor = startColor;
behaviour.EndColor = endColor;
return playable;
}
}
Trackを自作する
Timelineで使うTrackを作成します。
[TrackClipType(typeof(CustomTimeLinePlayableAsset))]
[TrackBindingType(typeof(Image))]
public class CustomTimelineTrack : TrackAsset
{
}
public class HogeInfo :
{
public string Id {get; private set;}
public int Value {get; private ser;}
public HogeInfo(string id, int value)
{
Id = id;
Value = value;
}
}
このクラスにIEquatableを使って等価判定用のメソッドを用意します。
public class HogeInfo : IEquatable<HogeInfo>
{
public string Id {get; private set;}
public int Value {get; private ser;}
public HogeInfo(string id, int value)
{
Id = id;
Value = value;
}
public bool Equals(HogeInfo other)
{
if (other == null)
{
return false;
}
return Id.Equals(other.Id) &&
Value.Equals(other.Value);
}
}
比較する
実際に等価比較を行う場合に定義をしてEqualsを使います。
var info1 = new HogeInfo("hoge", 100);
var info2 = new HogeInfo("hogehoge", 100);
var info3 = new HogeInfo("hoge", 50);
var info4 = new HogeInfo("hoge", 100);
bool isEqual1 = info1.Equals(info2); // false
bool isEqual2 = info1.Equals(info3); // false
bool isEqual3 = info1.Equals(info4); // true