ScriptPlayableAssetAudio.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. using UnityEngine.UI;
  6. [System.Serializable]
  7. public class ScriptPlayableAssetAudio : PlayableAsset, IPlayableAssetDeal
  8. {
  9. public string audioName;
  10. public string audioPath;
  11. public float startTime;
  12. public float endTime;
  13. public StoryMgr mgr;
  14. bool isPlayed = false;
  15. // Factory method that generates a playable based on this asset
  16. public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
  17. {
  18. ScriptPlayableTrackAudio audioPlayable = new ScriptPlayableTrackAudio();
  19. audioPlayable.Init(audioName, mgr);
  20. return ScriptPlayable<ScriptPlayableTrackAudio>.Create(graph, audioPlayable);
  21. }
  22. public void DealWithSimpleMode(int time)
  23. {
  24. if (string.IsNullOrEmpty(audioName) || string.IsNullOrEmpty(audioPath))
  25. return;
  26. if (time >= startTime && time < endTime)
  27. {
  28. if (!isPlayed)
  29. {
  30. MusicMgr.Instance.PlaySound(audioPath, audioName);
  31. isPlayed = true;
  32. }
  33. }
  34. }
  35. }