ExposedReference<T0>

Unity · Версия 2020.3 LTS · Scripting

ExposedReference<T0>

Описание

Создает тип, значение которого может быть разрешено во время выполнения.

ExposedReference — это универсальный тип, который можно использовать для создания ссылок на объекты сцены и разрешения их фактических значений во время выполнения и с помощью объекта контекста. Это может использоваться активами, такими как ScriptableObject или PlayableAsset, для создания ссылок на объекты сцены.

В приведенном ниже примере показано, как PlayableAsset может использовать открытые ссылки для создания ссылок на игровой объект сцены. Это пример использования временной шкалы, поэтому вы можете настроить свой игровой объект на временной шкале (откроется другой сайт) and сначала сделайте анимацию с вашим 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 PlayableBehaviour script
        TestExample playableBehaviour = new TestExample();
        //Resolve the exposed reference on the SceneGameObject 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.Create(graph, playableBehaviour);
    }
}

Поместите этот следующий сценарий в свой проект в ту же папку, что и предыдущий сценарий. Этот скрипт изменяет поведение временной шкалы, перемещая игровой объект сцены во время воспроизведения воспроизводимой дорожки.

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 SceneGameObject 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 Значение по умолчанию, если значение не может быть разрешено.
exposedName Имя ExposedReference.

Публичные Методы

Resolve Получает значение ссылки, разрешая ее с учетом объекта контекста ExposedPropertyResolver.

Обновлено 17 ноября 2026 г.