赞
踩
unity 自定义时间轴
Starting with Unity 2019.1, Timeline supports markers! In this blog post, I will show you how to create custom markers.
从 Unity 2019.1 开始 ,时间轴支持标记! 在此博客文章中,我将向您展示如何创建自定义标记。
Previously, I explained how to use Timeline Signals to trigger events. When we originally designed that feature, we quickly saw that in order to make it work, we couldn’t use clips. Since one of the main characteristics of a signal is that it has no “duration”, we would need a new type of item, hence the addition of markers to Timeline. Internally, signals are implemented using markers. Let’s see how to add a custom marker to Timeline.
之前 ,我解释了如何使用时间轴信号触发事件。 当我们最初设计该功能时,我们很快看到为了使其起作用,我们无法使用剪辑。 由于信号的主要特征之一是它没有“持续时间”,因此我们需要一种新型的物品,因此需要在时间轴上添加标记。 在内部,信号是使用标记实现的。 让我们看看如何向时间轴添加自定义标记。
The code and assets used for this blog post are available here.
此处提供了 用于此博客文章的代码和资产 。
A marker is a new item that can be added to a Timeline Asset and is used to represent a point in time. Markers also have a specialization, just like clips do (Activation clip, Audio clip, Animation clip, etc). This lets you create your own type of marker to build something that covers your specific workflows.
标记是可以添加到时间轴资产的新项目,用于表示时间点。 标记也具有特殊性,就像剪辑一样( 激活 剪辑, 音频 剪辑, 动画 剪辑等)。 这使您可以创建自己的标记类型来构建涵盖您特定工作流程的标记。
In order to add a new type of marker, all you need to do is to create a class that inherits the Marker class:
为了添加新型标记,您需要做的就是创建一个继承 Marker 类的类:
1 |
public class SimpleMarker : UnityEngine.Timeline.Marker {}
|
1 |
public class SimpleMarker : UnityEngine . Timeline . Marker { }
|
That’s it! This custom marker can now be added to any track on the timeline marker area:
而已! 现在可以将此自定义标记添加到时间线标记区域上的任何轨道:
At this point, this simple marker is only a visual item. This means that this marker cannot run code when triggered. That doesn’t mean it is isn’t useful; a marker can be a snap point or an annotation (see Part V). It’s also accessible through the Timeline API in editor and at runtime.
在这一点上,这个简单的标记只是一个 视觉项目 。 这意味着该标记 在触发时 无法运行代码 。 这并不意味着它没有用。 标记可以是捕捉点或注释(请参见第V部分)。 也可以 通过 编辑器中和运行时 的Timeline API对其 进行 访问 。
We will need to combine a marker with another system to make it able to execute code. If you’re interested in knowing how the system works, read the next two parts, otherwise, you can skip to Part IV (I won’t be offended!).
我们将需要将标记与另一个系统结合起来以使其能够执行代码。 如果您想了解系统的工作原理,请阅读下面的两部分,否则,您可以跳至第四部分(我不会感到冒犯!)。
The Playable API allows notifications to be sent to an object while a PlayableGraph is processed. Playable Notifications can be used to inform a target object that an event occurred. I will build a simple graph and manually send a notification.
Playable API允许在处理PlayableGraph时将通知发送到对象。 可播放的通知可用于通知目标对象已发生事件。 我将构建一个简单的图形并手动发送通知。
First, I need to create a notification: a class that implements the INotification interface.
首先,我需要创建一个 Notification :一个实现 INotification 接口的类。
1
2
3
4
|
public class MyNotification : INotification
{
public PropertyName id { get; }
}
|
1
2
3
4
|
public class MyNotification : INotification
{
public PropertyName id { get ; }
}
|
We can use the id property to uniquely identify the notification. For these examples, I don’t really need it, so I will use the default implementation.
我们可以使用 id 属性来唯一标识通知。 对于这些示例,我并不是真的需要它,因此我将使用默认实现。
Then, I need a receiver: a class that implements the INotificationReceiver interface. For this example, I have a receiver that will print the time at which a notification was received.
然后,我需要一个 接收器 :一个实现 INotificationReceiver 接口的类。 对于此示例,我有一个接收器,它将打印接收通知的时间。
1
2
3
4
5
6
7
8
9
10
11
|
class ReceiverExample : INotificationReceiver
{
public void OnNotify(Playable origin, INotification notification, object context)
{
if (notification != null)
{
double time = origin.IsValid() ? origin.GetTime() : 0.0;
Debug.LogFormat("Received notification of type {0} at time {1}", notification.GetType(), time);
}
}
}
|
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。