Version: 2020.1

ExposedReference<T0>

struct in UnityEngine

切换到手册

描述

创建一个值在运行时可加以解析的类型。

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

以下示例显示 PlayableAsset 如何使用暴露的引用来创建对 Scene GameObject 的引用。 这是一个使用 Timeline 的示例,因此您可能想要首先 set up your GameObject in Timelinemake an animation with your GameObject

//Put both of these scripts in your Project, then go to your Timeline, click the Add dropdown and choose Playable Track. Place this script on your Timeline as a Playable Track
//Click on the track and choose a GameObject from your Scene in the "My Scene Object" field. Also set the velocity.

using UnityEngine; using UnityEngine.Playables;

[System.Serializable] public class ExposedReferenceExample : PlayableAsset { //This allows you to use GameObjects in your Scene public ExposedReference<GameObject> m_MySceneObject; //This variable allows you to decide the velocity of your GameObject public Vector3 m_SceneObjectVelocity;

public override Playable CreatePlayable(PlayableGraph graph , GameObject myGameObject) { //Get access to the Playable Behaviour script TestExample playableBehaviour = new TestExample(); //Resolve the exposed reference on the Scene GameObject by returning the table used by the graph playableBehaviour.m_MySceneObject = m_MySceneObject.Resolve(graph.GetResolver());

//Make the PlayableBehaviour velocity variable the same as the variable you set playableBehaviour.m_SceneObjectVelocity = m_SceneObjectVelocity;

//Create a custom playable from this script using the Player Behaviour script return ScriptPlayable<TestExample>.Create(graph, playableBehaviour); } }

将您 Project 中的下一个脚本放在与上述脚本相同的文件夹中。 该脚本通过在 Playable Track 正在播放时移动 Scene GameObject 来更改时间轴的行为。

using  UnityEngine;
using  UnityEngine.Playables;

public class TestExample : PlayableBehaviour { public GameObject m_MySceneObject; public Vector3 m_SceneObjectVelocity;

public override void PrepareFrame(Playable playable, FrameData frameData) { //If the Scene GameObject exists, move it continuously until the Playable pauses if (m_MySceneObject != null) //Move the GameObject using the velocity you set in your Playable Track's inspector m_MySceneObject.transform.Translate(m_SceneObjectVelocity); } }

变量

defaultValue默认值,以防无法解析该值。
exposedNameExposedReference 的名称。

公共函数

Resolve根据 ExposedPropertyResolver 上下文对象,通过解析此引用的值来获取该值。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961