您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

49 行
1.1 KiB

using GameplayIngredients;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
[RequireComponent(typeof(PlayableDirector))]
public class PlayableDirectorPausable : MonoBehaviour
{
public string PauseMessage = "PAUSE";
public string UnPauseMessage = "UNPAUSE";
PlayableDirector director;
bool wasPlaying;
private void OnEnable()
{
Messager.RegisterMessage(PauseMessage, OnPause);
Messager.RegisterMessage(UnPauseMessage, OnUnPause);
director = GetComponent<PlayableDirector>();
}
private void OnDisable()
{
Messager.RemoveMessage(PauseMessage, OnPause);
Messager.RemoveMessage(UnPauseMessage, OnUnPause);
}
void OnPause(GameObject instigator = null)
{
if (director.state == PlayState.Playing)
{
director.Pause();
wasPlaying = true;
}
else
{
wasPlaying = false;
}
}
void OnUnPause(GameObject instigator = null)
{
if(wasPlaying)
{
director.Play();
wasPlaying = false;
}
}
}