Adventure Creator Wikia
Register
Advertisement

Audio played from Unity Timelines does not get paused when an AC game is paused. This component can be used to pause it manually, as well as update its volume to AC Options values.

To use it:

  1. Paste the script below into a new C# file named TimelineAudioPauser.cs
  2. Attach the new Timeline Audio Pauser component to the Playable Director that is controlling the Timeline
  3. In the component's Inspector, set the "Sound Type" as well as the "Track Index" to control. Note that regular tracks start from index=1, with index=0 being reserved for events.

(Credit to cemleme on the AC forum)

TimelineAudioPauser.cs:

using UnityEngine;
using AC;
using UnityEngine.Playables;

[RequireComponent (AudioSource)]
public class TimelineAudioPauser : MonoBehaviour
{

public PlayableDirector director;

private AudioSource audioSource;
private AudioClip clip;
private float pausedTime;

private void OnEnable ()
{
audioSource = GetComponent<AudioSource>();
EventManager.OnEnterGameState += OnEnterGameState;
EventManager.OnExitGameState += OnExitGameState;
}

private void OnDisable ()
{
EventManager.OnEnterGameState -= OnEnterGameState;
EventManager.OnExitGameState -= OnExitGameState;
}

protected void OnEnterGameState (GameState gameState)
{
if (director != null && gameState == GameState.Paused && director.state == PlayState.Playing)
{
clip = audioSource.clip;
pausedTime = audioSource.time;
audioSource.volume = 0;
}
}

protected void OnExitGameState (GameState gameState)
{
if (director != null && gameState == GameState.Paused && director.state == PlayState.Paused)
{
audioSource.clip = clip;
audioSource.time = pausedTime;
audioSource.volume = 1;
audioSource.Play();
}
}

}
Advertisement