unity 自定义时间轴_如何创建自定义时间轴标记

本文介绍了如何在Unity 2019.1及更高版本中利用时间轴(Timeline)创建自定义标记。从简单的标记创建开始,逐步讲解如何结合可播放通知(Playable Notifications)、TimeNotificationBehaviour、MarkerNotification来实现代码执行和自定义样式。通过实现INotification接口,可以控制通知的发送时间,并通过自定义样式改变标记的视觉表现。此外,还展示了如何利用片段发送通知,增强时间轴功能。
摘要由CSDN通过智能技术生成

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 Simple Marker)

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!). 

我们将需要将标记与另一个系统结合起来以使其能够执行代码。 如果您想了解系统的工作原理,请阅读下面的两部分,否则,您可以跳至第四部分(我不会感到冒犯!)。

第二部分–可播放的通知 (Part II – Playable Notifications)

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);
       }
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值