【Unity博客节选】Timeline 的 Traversal mode参数

article/2025/6/19 5:59:47

注:软件版本Unity 6.0 + Timeline 1.8.7

作者:CSDN @ RingleaderWang
原文:《Unity第25期——Timeline结构及其源码浅析》
文章首发Github👍:《Timeline结构及其源码浅析》

Bilibili 视频版👍👍:《Timeline结构及其源码解析》https://www.bilibili.com/video/BV1bHjYzNE35

TraversalModeMix/Passthrough,表示遍历节点input的方式,Mix就是将各输入进行加权;passthrough就是匹配input与output,第几个output来请求数据,就从第几个input获取数据。Passthrough目前只用于TimelinePlayable,使之成为graph的统一入口

⭐Traversal mode 验证

对Traversal mode这个参数的理解非常重要,不明白它的话,你会误以为每个PlayableOutput都会接收所有叶子节点的数据。

我们来创建个graph案例:

[Tooltip("false则mode是passthrough,true则mode是mix")]  
public bool changeTraversalMode = false;  
[Tooltip("false则PlayableOutput的source为playable1,true则为playable2")]  
public bool changeSourcePlayable = false;//newInput system绑定空格键触发
public void BackspaceDown(InputAction.CallbackContext ctx)  
{  if (ctx.performed)  {   ValidateTraversalMode2(changeTraversalMode,changeSourcePlayable);  }
}private void ValidateTraversalMode2(bool _changeTraversalMode,bool _changeSourcePlayable)  
{  DestoryGraph(graph);  graph = PlayableGraph.Create();  var playable1 = Playable.Create(graph,1);  var playable2 = Playable.Create(graph,2);  var playable3 = Playable.Create(graph);  playable3.SetTraversalMode(!_changeTraversalMode?PlayableTraversalMode.Passthrough:PlayableTraversalMode.Mix);  var playable4 = Playable.Create(graph,4);  var playable5 = Playable.Create(graph,5);  playable3.SetInputCount(10);  playable3.SetOutputCount(10);  graph.Connect(playable3, 0, playable1, 0);  graph.Connect(playable3, 1, playable2, 0);  graph.Connect(playable4, 0, playable3, 0);  graph.Connect(playable5, 0, playable3, 1);  ScriptPlayableOutput output = ScriptPlayableOutput.Create(graph, "customOutput");  output.SetSourcePlayable(!_changeSourcePlayable?playable1:playable2,100);graph.Play();  
}

当前中间Playable的 traversalMode是passthrough,可以看到只有port 0 这条线有数据传输。

mode为passthrough数据流向

改变PlayableOutput连在port 1 这端,数据又只接受input 1 这个port输入了。

mode为passthrough的数据流向(改变sourcePlayable)

而当 MODE 设为 MIX ,input 0 和 input 1 都接收数据。

MODE=MIX的数据流向

通过这个例子,能大概理解 TraversalMode 遍历模式到底是什么意思。

不过要注意,按照Passthrough源码注释的本意:

应该是sourceOutputPortPlayableOutput跟对应input位置的节点进行直通,但实测sourceOutputPort没起作用,实际上是由PlayableOutput在graph中的顺序决定,也就是下图中PlayableOutput前面的#0 #1 #2 标号(其实就是PlayableOutput数组的index)。

passthrough mode下input port匹配的其实是PlayableOutput数组标号

测试代码你可以发现SetSourcePlayable的port你设50设100都不影响。

void ValidateTraversalMode()  
{  DestoryGraph(graph);  graph = PlayableGraph.Create("TraversalModeGraph");  ScriptPlayableOutput output = ScriptPlayableOutput.Create(graph, "customOutput");  ScriptPlayableOutput output2 = ScriptPlayableOutput.Create(graph, "customOutput2");  ScriptPlayableOutput output3 = ScriptPlayableOutput.Create(graph, "customOutput3");  var playable = ScriptPlayable<CustomClipBehaviour>.Create(graph);  var playable2 = ScriptPlayable<CustomClipBehaviour>.Create(graph);  var playable3 = ScriptPlayable<CustomClipBehaviour>.Create(graph);  var playable4 = ScriptPlayable<CustomClipBehaviour>.Create(graph);  var playable5 = ScriptPlayable<CustomClipBehaviour>.Create(graph);  var mixer = ScriptPlayable<CustomMixerBehaviour>.Create(graph);  mixer.SetTraversalMode(PlayableTraversalMode.Passthrough);//默认mode为mix,这里改为passthrough  mixer.SetInputCount(10);// 很重要,否则连接报错:Connecting invalid input  mixer.ConnectInput(4,playable,0,1);  mixer.ConnectInput(6,playable2,0,1);  mixer.ConnectInput(2,playable3,0,1);  mixer.ConnectInput(8,playable4,0,1);  mixer.ConnectInput(1,playable5,0,1);  output.SetSourcePlayable(mixer,30);// 这个SetSourcePlayable的port根本没用,完全根据PlayableOutput顺序获取的  output2.SetSourcePlayable(mixer,50);  output3.SetSourcePlayable(mixer,100);  graph.Play();  
}

但从Animation计算权重的过程也能看出,SourceOutputPort本意就是playable的output port。但实测中Playableout获取数据时并没有使用这个参数,更没有校验,你设多少都可以(只校验了不能重复绑定,但没校验port是否存在)。

如果是bug的话,官方可能需要做下面两个步骤进行修复:

  • 每connect一个节点到TimelinePlayable,TimelinePlayable的outputCount加一(这样直通才有意义)
  • 对每个Playableout从根节点TimelinePlayable开始遍历时,严格按照TimelinePlayable.getInput(PlayableOutput.GetSourceOutputport())获取绑定的Playable,而不是用PlaybleGraph中类似PlayableOytput[]数组的index来get input playable。(注:Timeline生成的graph中PlayableOutput.GetSourcePlayable()得到的就是TimelinePlayable

http://www.hkcw.cn/article/ZrueKdstVs.shtml

相关文章

Constraints and Triggers

目录 Kinds of Constraints Single-Attribute Keys Multiattribute Key Foreign Keys Expressing Foreign Keys Enforcing Foreign-Key Constraints Actions Taken Attribute-Based Checks Timing of Checks Tuple-Based Checks Assertions Timing of Assertion Ch…

免费且好用的PDF水印添加工具

软件介绍 今天要给大家推荐一款超实用的PDF添加水印工具&#xff0c;它能够满足用户给PDF文件添加水印的需求&#xff0c;而且完全免费。 这款PDF添加水印的软件有着简洁的界面&#xff0c;操作简便&#xff0c;无需安装&#xff0c;解压后即可使用。 在使用前&#xff0c;先…

设计模式——面向对象设计六大原则

摘要 本文详细介绍了设计模式中的六大基本原则&#xff0c;包括单一职责原则、开放封闭原则、里氏替换原则、接口隔离原则、依赖倒置原则和合成复用原则。每个原则都通过定义、理解、示例三个部分进行阐述&#xff0c;旨在帮助开发者提高代码的可维护性和灵活性。通过具体代码…

DO指数GPU版本

大指数下DO指数模型计算优化 DO指数模型概述 DO指数&#xff08;Duranton-Overman Index&#xff09;是由Duranton和Overman于2005年提出的产业空间集聚测度方法&#xff0c;它通过分析企业间的精确地理距离分布来识别产业集聚模式。与传统集聚指标相比&#xff0c;DO指数具有…

工业物联网中的事件驱动采样架构及优化

论文标题 Event-Based Sampling Architecture and Optimization for Industrial Internet of Things 工业物联网中的事件驱动采样架构及优化 作者信息 Tejas Thosani Process Control Systems, Micron Technology Inc., Manassas, USA tthosanimicron.com Andres Prado Esp…

Windows | 总误按Num Lock?修改注册表永久禁用Numlk键使小键盘一直输入数字

先说需修改注册表的位置与键值 路径&#xff1a;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\ 二进制键&#xff1a;Scancode Map 键值&#xff1a; 00 00 00 00 00 00 00 00 01 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00如下图&#xff1a; …

c#与halcon环境配置,导出算法库,使用halcon环境编程

目录 1. C#配置halcon运行环境 2.导出halcon算法库 3.使用方法 记录下C#配置halcon环境的方法&#xff0c;以及halcon导出库的使用方法。 1. C#配置halcon运行环境 VS版本&#xff1a; vs2019 halcon版本: 20.11 创建c#工程&#xff0c;点击“创建新项目”&#xff0c;…

tomcat yum安装

使用yum安装 yum install -y java-1.7.0-openjdk* tomcat* --disablerepoepel## java-1.7.0-openjdk* 注意&#xff1a;最终安装的是java-1.8.0版本## --disablerepoepel 禁用&#xff1a;EPEL源&#xff0c;防止版本冲突 java -version (2) 启停&#xff1a;Tomcat 7 s…

时间的基本概念与相关技术三

1.5 守时技术 所谓守时&#xff08;time keeping&#xff09;是指一个时频系统&#xff08;包括频标和分频钟&#xff09;对时间信号和时间信息的保持。频率标准&#xff08;简称频标&#xff09;的频率准确度、频率稳定度和守时系统的环境条件是决定守时能力的三个关键因素。…

云原生安全基石:Kubernetes 核心概念与安全实践指南

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、基础概念 1. Kubernetes 架构全景 Kubernetes&#xff08;简称 K8s&#xff09;采用主从架构&#xff0c;由控制平面&#xff08;Control Plane&…

【python】uv管理器

uv是一个速度极快的 Python 包和项目管理器&#xff0c;用 Rust 编写。 安装 安装uv之前&#xff0c;确保你的电脑不需要安装了python 在Windows下&#xff0c;可以使用官方的脚本直接安装 powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.…

2021 年 12 月大学英语四级考试真题(第 1 2 3 套)——解析版——篇章题

&#x1f3e0;个人主页&#xff1a;fo安方的博客✨ &#x1f482;个人简历&#xff1a;大家好&#xff0c;我是fo安方&#xff0c;目前中南大学MBA在读&#xff0c;也考取过HCIE Cloud Computing、CCIE Security、PMP、CISP、RHCE、CCNP RS、PEST 3等证书。&#x1f433; &…

【Linux】mmap文件内存映射

&#x1f4dd;前言&#xff1a; 这篇文章我们来讲讲Linux——mmap mmap介绍mmap接口介绍mmap使用示例 &#x1f3ac;个人简介&#xff1a;努力学习ing &#x1f4cb;个人专栏&#xff1a;Linux &#x1f380;CSDN主页 愚润求学 &#x1f304;其他专栏&#xff1a;C学习笔记&a…

深度学习驱动的超高清图修复技术——综述

Deep Learning-Driven Ultra-High-Definition Image Restoration: A Survey Liyan Wang, Weixiang Zhou, Cong Wang, Kin-Man Lam, Zhixun Su, Jinshan Pan Abstract Ultra-high-definition (UHD) image restoration​​ aims to specifically solve the problem of ​​quali…

【Docker系列】Docker 容器内安装`ps`命令

博客目录 一、为什么需要在 Docker 容器中安装ps命令二、不同 Linux 发行版的安装方法1. Alpine Linux 镜像的安装方法2. Debian/Ubuntu 镜像的安装方法3. CentOS/RHEL 镜像的安装方法 三、验证安装与基本使用四、永久解决方案&#xff1a;修改 Dockerfile1. Alpine 基础镜像的…

【KWDB 创作者计划】_再热垃圾发电汽轮机仿真与监控系统:KaiwuDB 批量插入10万条数据性能优化实践

再热垃圾发电汽轮机仿真与监控系统&#xff1a;KaiwuDB 批量插入10万条数据性能优化实践 我是一台N25-3.82/390型汽轮机&#xff0c;心脏在5500转/分的轰鸣中跳动。垃圾焚烧炉是我的胃&#xff0c;将人类遗弃的残渣转化为金色蒸汽&#xff0c;沿管道涌入我的胸腔。 清晨&#x…

对蚁群算法的理解和实例详解

目录 一、算法概述 二、实例详解 1&#xff09;问题分析 2&#xff09;初始化参数 2&#xff09;设置蚂蚁初始位置 3&#xff09;选择路径 4&#xff09;记录本次最佳路径 5&#xff09;更新信息素 6&#xff09;清空禁忌表 三、计算结果 四、总结 一、算法概述 一群…

【PowerPoint专栏】PowerPoint的保存选项

在PowerPoint的保存选项中有非常多的可用选项,保存的类型也非常多。 在PowerPoint中的工具选项中同样有一些相关的菜单操作帮助用户完成一些特殊操作。 在

直击2025粤港澳大湾区车展 科技引领未来车展

5月31日,第二十九届粤港澳大湾区车展在深圳国际会展中心(宝安)拉开帷幕。本届车展延续“面向科技、面向未来、面向市场”的主题,以“科技Alpha车展”为核心方向,探索汽车前沿科技。展会规模超过26万平方米,有超8万平方米的户外活动体验区及试驾专区。车展期间,全球近百家…

新王加冕!巴黎5比0国米首夺欧冠 年轻风暴席卷欧洲

北京时间6月1日凌晨,2024至2025赛季欧冠联赛决赛在德国慕尼黑安联球场进行。经过90分钟的激战,法甲巴黎圣日耳曼队以5比0大胜意甲国际米兰队,夺得队史首座“大耳朵杯”。此前的淘汰赛中,“大巴黎”先后淘汰了利物浦队、阿斯顿维拉队和阿森纳队三支英超劲旅。而国米则在半决…