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 等资源可使用它来创建对场景对象的引用。

相关推荐
土了个豆子的11 小时前
unity中的动画混合树
unity·游戏引擎
奔跑的犀牛先生14 小时前
unity学习26:用Input接口去监测: 鼠标,键盘,虚拟轴,虚拟按键
unity
Dr.勿忘1 天前
C#面试常考随笔8:using关键字有哪些用法?
开发语言·unity·面试·c#·游戏引擎
存储服务专家StorageExpert1 天前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
追逐梦想永不停1 天前
Unity实现按键设置功能代码
unity
我命由我123452 天前
游戏引擎 Unity - Unity 下载与安装
c语言·开发语言·c++·后端·unity·c#·游戏引擎
车载诊断技术2 天前
车载软件架构 --- 基于AUTOSAR软件架构的ECU开发流程小白篇
网络·unity·架构·汽车·电子电器框架·车载充电器(obc)
我命由我123452 天前
游戏引擎 Unity - Unity 启动(下载 Unity Editor、生成 Unity Personal Edition 许可证)
c语言·c++·后端·unity·c#·游戏引擎·ue4
我命由我123452 天前
游戏开发领域 - 游戏引擎 UE 与 Unity
开发语言·c++·unity·c#·游戏引擎·unreal engine·unreal engine 4
一个一定要撑住的学习者2 天前
Day29(补)-【AI思考】-精准突围策略——从“时间贫困“到“效率自由“的逆袭方案
人工智能·unity·游戏引擎