版本: Unity 6 (6000.0)
语言英语
  • C#

ExposedReference<T0>

UnityEngine 中的结构

/

实现于:UnityEngine.CoreModule

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每个建议更改,并在适用时进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请<a>稍后重试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

描述

创建一种类型,其值可以在运行时解析。

ExposedReference 是一个泛型类型,可用于创建对场景对象的引用并在运行时以及使用上下文对象时解析其实际值。资产(例如 ScriptableObjectPlayableAsset)可以使用它来创建对场景对象的引用。

以下示例展示了 PlayableAsset 如何使用公开引用来创建对场景 GameObject 的引用。这是一个使用 Timeline 的示例,因此您可能需要 在 Timeline 中设置您的 GameObject 以及 用您的 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); } }

将下一个脚本放在您的项目中,与上面的脚本位于同一个文件夹中。此脚本通过在 Playable Track 播放时移动场景 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 上下文对象解析来获取引用的值。