Unity Timeline学习笔记(5) - 自定义轨道切片上变量Transform对象丢失,使用ExposedReference来解决。

问题

我在笔记(4)中后来又引用了Hierarchy中的Transform对象Transform obj,发现一些问题。

要么无法拖入进去对象,要么拖入进去保存后,再次编辑或者运行的时候发现obj丢失了。

我们还是用修改下笔记(4)的部分代码来解决。

csharp 复制代码
[DisplayName("玩家固定(Transform)Clip")]
[Serializable]
public class PlayerTransformMixerPlayableAsset : PlayableAsset
{
    [Tooltip("固定玩家的Transform")]
    public ExposedReference<Transform> fixedTransform;
    [Tooltip("结束后返回原始位置")]
    public bool FinishToBack = true;

    //public PlayerTransformBehaviour template = new PlayerTransformBehaviour();
    public ClipCaps clipCaps
    {
        get
        {
            return ClipCaps.Blending; 
        }
    }
    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        PlayerTransformBehaviour template = new PlayerTransformBehaviour();
        template.fixedTransform = fixedTransform.Resolve(graph.GetResolver());
        template.FinishToBack = FinishToBack;
        return ScriptPlayable<PlayerTransformBehaviour>.Create(graph, template);
       
    }

  
}

  
public class PlayerTransformBehaviour : PlayableBehaviour
{
    public Transform fixedTransform;  
    public bool FinishToBack = true;  
    public float passtime;  //计算当前块的播放进度
    public bool started;  //是否刚进入
}

我们需要把面板值加上ExposedReference来添加引用。

然后创建的时候通过fixedTransform.Resolve来赋值就可以了。

说明

ExposedReference 是一个泛型类型,可用于创建对场景对象的引用,以及通过使用上下文对象在运行时解析它们的实际值。ScriptableObject 或 PlayableAsset 等资源可使用它来创建对场景对象的引用。

相关推荐
淡海水16 小时前
16-02-C#常用数据结构源码-附录B-源码索引速查
unity·c#·游戏引擎·il2cpp
警醒与鞭策1 天前
【无标题】
android·unity·性能优化·游戏引擎·perforce
zhchyun20081 天前
【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(10)
ui·unity·游戏引擎
地狱为王1 天前
Unity使用NVIDIA的Audio2Face驱动口型
unity·游戏引擎
ebiobiz1 天前
STM32F4 Unity 单元测试与多次测试失败率统计详细步骤
stm32·unity·单元测试
淡海水2 天前
16-01-C#数据结构源码-附录A-术语表
unity·c#·游戏引擎·il2cpp
淡海水2 天前
16-03-C#数据结构源码-附录C-参考资源
unity·c#·游戏引擎·il2cpp
天神哥哥啊2 天前
unity联调注意事项-安卓
android·unity·游戏引擎
天神哥哥啊2 天前
unity联调注意事项-IOS
unity·ios·游戏引擎
可爱系程序猿2 天前
Unity 材质预览才弹 d3dcompiler_47.dll?先分清编辑器 SDK、着色器缓存和玩家包
程序人生·3d·unity·电脑·材质