ActiveGameObjectPlayableBehaviour.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. [System.Serializable]
  4. public class ActiveGameObjectPlayableBehaviour : PlayableBehaviour
  5. {
  6. public bool isActive;
  7. public GameObject gameObject;
  8. public bool isLasting;
  9. // Called when the owning graph starts playing
  10. public override void OnGraphStart(Playable playable)
  11. {
  12. Debug.Log("OnGraphStart");
  13. }
  14. // Called when the owning graph stops playing
  15. public override void OnGraphStop(Playable playable)
  16. {
  17. Debug.Log("OnGraphStop");
  18. }
  19. // Called when the state of the playable is set to Play
  20. public override void OnBehaviourPlay(Playable playable, FrameData info)
  21. {
  22. Debug.Log("OnBehaviourPlay");
  23. if (gameObject != null)
  24. {
  25. gameObject.SetActive(isActive);
  26. }
  27. }
  28. // Called when the state of the playable is set to Paused
  29. public override void OnBehaviourPause(Playable playable, FrameData info)
  30. {
  31. if (gameObject != null)
  32. {
  33. if (!isLasting)
  34. {
  35. gameObject.SetActive(!isActive);
  36. }
  37. }
  38. Debug.Log("OnBehaviourPause");
  39. }
  40. // Called each frame while the state is set to Play
  41. public override void PrepareFrame(Playable playable, FrameData info)
  42. {
  43. // Debug.Log("PrepareFrame" + info.weight);
  44. }
  45. }