描述

PlayableDirector 组件开始播放时所引发的事件。

向此事件添加一个事件处理程序,以便在 PlayableDirector 开始播放时接收相关通知。该处理程序还接收正在播放的 PlayableDirector。

使用 PlayableBehaviour 时,系统将在 PlayableBehaviour.OnPlayableCreate 之后以及 PlayableBehaviour.OnGraphStartPlayableBehaviour.OnBehaviourPlay 之前引发此事件。

如果使用 PlayableDirector.playOnAwake 自动播放 PlayableDirector,则不会引发此事件。

using UnityEngine;
using UnityEngine.Playables;

public class PlayableDirectorCallbackExample : MonoBehaviour { public PlayableDirector director;

void OnEnable() { director.played += OnPlayableDirectorPlayed; }

void OnPlayableDirectorPlayed(PlayableDirector aDirector) { if (director == aDirector) Debug.Log("PlayableDirector named " + aDirector.name + " is now playing."); }

void OnDisable() { director.played -= OnPlayableDirectorPlayed; } }