07
24

PlayableDirector 클래스의 함수

Playable Asset (재생 가능한 에셋)
: PlayableDirector가 재생할 Playable Asset을 지정하는 속성이다.
  Playable Asset은 Timeline, Animation Clip 등과 같은 재생 가능한 요소를 나타낸다.

Initial Time (초기 시간)
: PlayableDirector가 시작되는 시간을 지정하는 속성이다.
  일반적으로 재생 가능한 에셋의 시작 시간을 설정하는 데 사용된다.

Wrap Mode (랩 모드)
: PlayableDirector의 재생 방식을 지정하는 속성이다.
  Loop, Once, Ping Pong, Hold(타임라인이 끝나면 마지막 프레임에서 머무른다.)
  등 다양한 랩 모드를 선택할 수 있다.

Play On Awake (시작 시 재생)
: PlayableDirector가 게임 오브젝트가 활성화될 때 자동으로 재생되도록 설정하는 속성이다.

Stop On Disable (비활성화 시 정지)
: 게임 오브젝트가 비활성화될 때 PlayableDirector를 자동으로 정지하도록 설정하는 속성이다.

Director Update Mode (업데이트 모드)
: PlayableDirector의 업데이트 동작 방식을 지정하는 속성이다.
  Game Time, Unscaled Game Time, Manual 등의 업데이트 모드를 선택할 수 있다.
1. Game Time: 게임 내 시간으로 timeScale의 영향을 받는다.
2. Unscaled Game Time: timeScale의 영향을 받지 않는다.
3. Manual: 스크립팅으로 조정할 수 있다.
4. Digital Signal Processing(DSP): 오디오를 처리하는 것과 동일한 클럭 소스가 타임라인 인스턴스에 사용된다.
Evaluate On Play (재생 시 평가?)
: PlayableDirector가 재생될 때 Playable Asset을 평가?하도록 설정하는 속성이다.
  이 설정을 사용하면 Timeline 또는 Animation Clip의 키프레임이 적용된다.

Pause (일시 정지)
: PlayableDirector를 일시 정지하는 함수이다.

Play (재생)
: PlayableDirector를 재생하는 함수이다.

Stop (정지)
: PlayableDirector를 정지하는 함수이다.

SetReferenceValue (참조 값 설정)
: PlayableDirector의 변수 또는 바인딩된 속성에 값을 설정하는 함수이다.
  이러한 변수는 변수트랙(Variable Track)에서 관리되며,
  타임라인 애니메이션의 재생 중에 값이 변경되거나 읽힐 수 있다.

GetReferenceValue (참조 값 가져오기)
: PlayableDirector의 변수 또는 바인딩된 속성의 값을 가져오는 함수이다.

예제 1 - Play, Pause, Stop

  • 모두 인자값 없이 아래처럼 사용하면 된다.
public PlayableDirector timeline;

void Start()
{
    timeline.Play();
}

예제 2 - EvaluateTime

  • 특정 시간으로 타임라인 애니메이션을 진행하며, 인자값은 float 타입의 변수로 타임라인의 시간을 나타낸다.
public PlayableDirector timeline;
public float desiredTime = 5.0f;

void Update()
{
    if (Input.GetKeyDown(KeyCode.Alpha1))
    {
        timeline.EvaluateTime(desiredTime);
    }
}

예제 3 - state

  • PlayableDirector의 상태를 나타내는 PlayState 열거형 속성, 함수는 아니지만 많이 사용되므로 예제에 넣었다.
  • PlayState.Playing: 타임라인 애니메이션이 실행 중인 상태
  • PlayState.Paused: 타임라인 애니메이션이 일시 정지된 상태
  • PlayState.Stopped: 타임라인 애니메이션이 정지된 상태
public PlayableDirector timeline;

void Update()
{
    if (timeline.state == PlayState.Playing)
    {
        Debug.Log("타임라인 애니메이션이 실행 중입니다.");
    }
}

예제 4 - SetReferenceValue, GetReferenceValue

  • 변수트랙을 활용하면 타임라인 애니메이션에서 게임 오브젝트, 숫자, 불린 등의 변수를 유연하게 조작할 수 있다.
  • 예를 들어, 타임라인 애니메이션에서 특정 오브젝트의 속도를 변경하거나 효과를 적용하는 등의 상호작용을 구현할 때 유용하게 사용된다.
using UnityEngine;
using UnityEngine.Playables;

public class ExampleController : MonoBehaviour
{
    public PlayableDirector timeline;
    public GameObject targetObject;
    public float newSpeed = 10.0f;

    void Start()
    {
        // PlayableDirector의 변수트랙에서 targetObject 변수 설정
        timeline.SetReferenceValue("targetObject", targetObject);

        // PlayableDirector의 변수트랙에서 newSpeed 변수 설정
        timeline.SetReferenceValue("newSpeed", newSpeed);
    }
}
using UnityEngine;
using UnityEngine.Playables;

public class ExampleController : MonoBehaviour
{
    public PlayableDirector timeline;

    void Update()
    {
        // PlayableDirector의 변수트랙에서 targetObject 변수 읽기
        GameObject targetObject = timeline.GetReferenceValue("targetObject") as GameObject;

        // PlayableDirector의 변수트랙에서 newSpeed 변수 읽기
        float newSpeed = (float)timeline.GetReferenceValue("newSpeed");
    }
}
COMMENT