Signal Track(2019.1Version)
Timeline Signal信号是建立Timeline窗口与外部系统的沟通渠道
Signal Asset 信号资源:
信号资源是发射器和接收器之间的联系,可以在多个Timeline实例中复用
Signal Emitter 信号发射器:
通过 标记Marker 来显示,信号发射器包含对信号资源的引用,可以在Markers区域、Signal Track、或者其他轨道上添加信号发射器
Signal Receiver 信号接收器
带有一组反应(Reactions组件) 关联到信号资源
创建自定义 Timeline Signal
自定义的Signal信号接收器和信号发射器有两种使用方式
1、通过代码方式调用
2、通过在Timeline Track Marker内标记调用
接收器:
using UnityEngine;
using UnityEngine.Timeline;
using UnityEngine.Playables;
public class MySignalReceiver : MonoBehaviour, INotificationReceiver
{
private void Start()
{
}
public void OnNotify(Playable origin, INotification notification, object context)
{
Debug.Log(notification.GetType());
if (notification is MyEmitter)
{
MyEmitter my = notification as MyEmitter;
Debug.Log("MyEmitter" + my.annotation);
}
else if (notification is SignalEmitter)
{
Debug.Log("SignalEmitter");
}
}
}
发射器:
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public class MyEmitter : Marker, INotification
{
[TextArea] public string annotation;
public PropertyName id
{
get { return new PropertyName("MyEmiter"); }
}
}
代码方式调用
using UnityEngine;
using UnityEngine.Playables;
public class MyPlayable : MonoBehaviour
{
PlayableGraph m_Graph;
MySignalReceiver m_Receiver;
void Start()
{
m_Graph = PlayableGraph.Create("NotificationGraph");
var output = ScriptPlayableOutput.Create(m_Graph, "NotificationOutput");
//创建和注册接收器
m_Receiver = gameObject.GetComponent<MySignalReceiver>();
output.AddNotificationReceiver(m_Receiver);
MyEmitter emitter = new MyEmitter();
emitter.annotation = "emitter.annotation";
Playable play = Playable.Create(PlayableGraph.Create("acc"));
//在输出推送一个通知 参数1 也可以使用 Playable.Null
output.PushNotification(play, emitter);
m_Graph.Play();
}
private void OnDestroy()
{
m_Graph.Destroy();
}
}
第一种方式,通过代码的方式,只需要把代码调用的脚本挂载到一个物体上即可,接收器当然也有放到上面。不然无法找到组件
第二种方式,通过标记的方式触发,首先需要将接收器放置在带有Signal Receiver 组件的物体上。
然后在添加标记即可
当Timeline 运行过标记后。触发信号通知给接收器。接收器打印出对应信息
这样就创建了一个自定义信号组件,当然也可以通过Signal Track的方式来操作,也可以将标记放置在其他Track上进行标记
以上也是本人在学习中了解到的一些信息,分享出来。少走弯路,如果有介绍不对的地方可以及时指正出来。我在进行修改