【Unity博客节选】Playable Graph Monitor 安装使用

注:软件版本Unity 6.0 + Timeline 1.8.7
作者:CSDN @ RingleaderWang

原文:《Unity第25期------Timeline结构及其源码浅析》
文章首发Github👍《Timeline结构及其源码浅析》
Bilibili 视频版👍👍《Timeline结构及其源码解析》https://www.bilibili.com/video/BV1bHjYzNE35

可以使用Playable Graph Monitor 查看 Timeline生成的graph。

安装步骤:

  1. open Edit/Project Settings/Package Manager

  2. add a new Scoped Registry (or edit the existing OpenUPM entry)

    • Name: package.openupm.com
    • URL: https://package.openupm.com
    • Scope(s): com.greenbamboogames.playablegraphmonitor
  3. click Save or Apply

  4. open Window/Package Manager

  5. click +

  6. select Add package by name... or Add package from git URL...

  7. paste com.greenbamboogames.playablegraphmonitor into name

  8. paste 2.6.3 into version

  9. click Add

测试案例:

csharp 复制代码
public AnimationClip clip;  
public AnimationClip clip2;  
private PlayableGraph graph;

void DestoryGraph(PlayableGraph graph)  
{  
    if (graph.IsValid())  
    {        
	    graph.Destroy();  
    }
}
  private void CreateMixerGraph()
    {
        DestoryGraph(graph);
        // 1. 创建 PlayableGraph
        graph = PlayableGraph.Create("MixerPlayableGraph");
        // 2. 获取 Animator 并创建 AnimationPlayableOutput
        var animator = GetComponent<Animator>();
        var animationOutput = AnimationPlayableOutput.Create(graph, "Animation", animator);
        // 3. 创建 AnimationClipPlayable
        var clipPlayable = AnimationClipPlayable.Create(graph, clip);
        var clipPlayable2 = AnimationClipPlayable.Create(graph, clip2);
        // 4. 创建一个 Mixer,管理多个动画输入
        AnimationMixerPlayable mixer = AnimationMixerPlayable.Create(graph, 2);
        mixer.ConnectInput(0, clipPlayable, 0,1);
        mixer.ConnectInput(1, clipPlayable2, 0,1);
        // 5. 设置 mixer 作为输出
        animationOutput.SetSourcePlayable(mixer);
        // 6. 播放图谱
        graph.Play();
    }
public void OnDestroy()  
{  
    DestoryGraph(graph); 
}

逻辑很简单,就4步:

  • 创建graph
  • 创建playable、mixerPlayable 并 connect
  • 创建playableOutput 并 setSourceOutput
  • 运行graph

对应的graph如下:

如果你使用官方的PlayableGraph Visualizer 的话,你会发现和 Playable Graph Monitor所展示的不一样。

比如这个例子:

PlayableGraph Visualizer展示:

Playable Graph Monitor展示:

你可以发现区别很大,Visualizer从PlayableOutput往Playable构图,且两个PlayableOutput独立构图;而Monitor是从叶子Playable节点往PlayableOutput构图,两个PlayableOutput连在一个output端口上。

到底哪个对呢?

其实都对。Visualizer是从graph play角度构图的,Monitor是从graph create角度构图的。

执行遍历节点获取数据时,其发起端其实是PlayableOutput,所以Visualizer把各个PlayableOutput独立开来构图,但这种展示方式对认识graph的结构不如Monitor清晰,而且官方Visualizer不能缩放,插件还有些bug会导致系统闪退,所以直接用Monitor就行。

不过Monitor的展示还是有些问题,两个PlayableOutput连在同一个output port了,这应该是Unity Timeline自身的问题,你理解成第二个PlayableOutput连在第二个port就行,以此类推。(不影响运行)

相关推荐
郝学胜-神的一滴9 小时前
[简化版 GAMES 101] 计算机图形学 07:图形学投影完全推导
c++·unity·图形渲染·three.js·unreal engine
Avalon7121 天前
Unity3D响应式渲染UI框架UniVue
游戏·ui·unity·c#·游戏引擎
ellis19701 天前
Unity UI性能优化一之插件【Unity UI Optimization Tool】
unity·性能优化
Zik----1 天前
Unity基础学习笔记(B站视频课整理)
unity·vr
郝学胜-神的一滴2 天前
罗德里格斯旋转公式(Rodrigues‘ Rotation Formula)完整推导
c++·unity·godot·图形渲染·three.js·unreal
田鸡_2 天前
Unity新输入系统(Input System)教学篇
unity·游戏引擎·游戏程序
EQ-雪梨蛋花汤2 天前
【Unity笔记】Unity 音游模板与免费资源:高效构建节奏游戏开发全指南
笔记·unity·游戏引擎
星辰徐哥2 天前
Unity基础:游戏对象的激活与隐藏:SetActive方法详解
游戏·unity·lucene
微莱羽墨2 天前
零、0基础入门Unity 安装详细教程(2026最新版教程,安装Unity看这一篇就够了!)
unity·游戏引擎·unity安装
星辰徐哥2 天前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene