zoukankan      html  css  js  c++  java
  • Unity开发笔记-Timeline利用Single实现Rewind回放

    先来看下效果,播放的结尾后回到前面的某一个位置,然后循环

    具体实现思路如下:

    1.设置marker标记,作为定位
    2.利用signal emitter,触发消息事件
    3.signal receiever监听事件,通过查找marker获得time
    4.通过设置PlayableDirector的time属性,改变timeline的播放位置,从而实现了rewind播放功能

    示例中,在timeline的结束处,在signal track上放置一个signal emitter
    点击signal emitter,添加signal asset,这里命名为marker_rewind

    在场景中新建一个signal reciever,新建MarkerRecieverRewind.cs脚本进行监听

    MarkerRecieverRewind需要实现INotificationReceiver接口

      `public void OnNotify(Playable origin, INotification notification, object context)
        {}`
    

    当监听到signal事件之后,我们需要
    1.获得marker对象,拿到time属性
    2.获得PlayableDirector,根据marker的time修改time属性

    marker的获取:

    1.将notification强转为signalEmitter

    SignalEmitter emitter = (SignalEmitter)notification;

    2.拿到TimlineAsset

    TimelineAsset ta = emitter.parent.timelineAsset;

    3,通过TimlineAsset的markerTrack属性获取marker

    IMarker marker = ta.markerTrack.GetMarker(0);

    PlayableDirector的获取:

    通过接口的Playable对象可以获取到

    PlayableDirector director = (PlayableDirector)origin.GetGraph().GetResolver();

    完整代码如下:

      `public class MarkerRecieverRewind : MonoBehaviour, INotificationReceiver
    {
        public void OnNotify(Playable origin, INotification notification, object context)
        {
            PlayableDirector director = (PlayableDirector)origin.GetGraph().GetResolver();
    
            SignalEmitter emitter = (SignalEmitter)notification;
            TimelineAsset ta = emitter.parent.timelineAsset;
            int markerCount = ta.markerTrack.GetMarkerCount();
            if (markerCount > 0)
            {
                IMarker marker = ta.markerTrack.GetMarker(0);
                director.Pause();
                director.time = marker.time;
                director.Play();
            }
        }`
  • 相关阅读:
    css+javascript 仿outlook滑动菜单效果代码
    闭包
    AJAX式多数据源及节点异步加载树_meetrice
    CSS圆角边框表格
    Editplus 3.0 开发ext 教程
    IE右键快速转载到博客
    自已扩展EXT组件(Extending Ext Components)
    Ext程序规划入门
    EXT2联动选框 (Linked Combos Tutorial for Ext 2)
    EXT snippets 笔记
  • 原文地址:https://www.cnblogs.com/terrynoya/p/13442644.html
Copyright © 2011-2022 走看看