• Unity开发笔记-Timeline利用Clip实现Rewind回放


    效果展示

    除了使用signal,timeline也可以通过自定义clip实现rewind回放

    原理:

    实现PlayableBehaviour的子类,重写ProcessFrame方法,参数中的Playable对象的GetDuration()和GetTime()可以获得当前clip的总时间和当前时间
    如果time接近duration,那么设法取到playableDirector,将time减去当前clip已播放的GetTime()即可

    下面是PlayableBehaviour核心代码:

      `public class LoopClipBehavior:PlayableBehaviour
      {
    private PlayableDirector director { get; set; }
    
    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        double duration = playable.GetDuration();
        double time = playable.GetTime();
        if (Math.Abs(time- duration)<=0.1f) 
        {
            var diff = playable.GetTime();
            director.time -= diff;
        }
        base.ProcessFrame(playable, info, playerData);
    }
    
    public override void OnPlayableCreate(Playable playable)
    {
        base.OnPlayableCreate(playable);
        director = (playable.GetGraph().GetResolver() as PlayableDirector);
    }
      }
      `
    

    同时也需要实现PlayableAsset和TrackAsset的子类

    LoopClipTrack.cs

    [TrackClipType(typeof(LoopClip))]
    public class LoopClipTrack: TrackAsset
    {

    }

    LoopClip.cs

      `public class LoopClip : PlayableAsset
      {
    public LoopClipBehavior template = new LoopClipBehavior();
    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        var playable = ScriptPlayable<LoopClipBehavior>.Create(graph, template);
        return playable;
    }
      }`
  • 相关阅读:
    mysql相关
    java注解@Valid@Validated表单验证
    驼峰参数、下划线["_"]参数,属性互传
    redis,windows设置记录
    Java入门第一季学习总结
    计算属性calc()的运算规则
    swiper实现翻页,页面高度超出可滚动
    git常用命令
    Linux下svn常用命令
    图片高度不够一页,如何覆盖全屏
  • 原文地址:https://www.cnblogs.com/terrynoya/p/13504276.html
Copyright © 2020-2023  润新知