ScriptPlayableTrackStoryDialogue.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. using UnityEngine.UI;
  6. // A behaviour that is attached to a playable
  7. public class ScriptPlayableTrackStoryDialogue : PlayableBehaviour
  8. {
  9. public StoryMgr mgr;
  10. public Text talkText;
  11. public Toggle toggleBtn;
  12. public int dlgId;
  13. private PlayableDirector director;
  14. bool isPlayed = false;
  15. public void Init(Text talkText, Toggle toggleBtn, int dlgId, StoryMgr mgr)
  16. {
  17. this.mgr = mgr;
  18. this.talkText = talkText;
  19. this.toggleBtn = toggleBtn;
  20. this.dlgId = dlgId;
  21. }
  22. // Called when the owning graph starts playing
  23. public override void OnGraphStart(Playable playable)
  24. {
  25. //Debug.Log("OnGraphStart");
  26. director = GameObject.FindObjectOfType<PlayableDirector>();
  27. }
  28. // Called when the owning graph stops playing
  29. public override void OnGraphStop(Playable playable)
  30. {
  31. //Debug.Log("OnGraphStop");
  32. }
  33. // Called when the state of the playable is set to Play
  34. public override void OnBehaviourPlay(Playable playable, FrameData info)
  35. {
  36. isPlayed = true;
  37. //talkText.text = talkStr;
  38. }
  39. public override void OnBehaviourPause(Playable playable, FrameData info)
  40. {
  41. //Debug.Log("pause");
  42. if (isPlayed && !toggleBtn.isOn)
  43. {
  44. //Debug.Log("pause11111111111111111111111111111111111111111111111111111");
  45. director.Pause();
  46. }
  47. }
  48. }