ActivationMixerPlayable.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine.Playables;
  2. namespace UnityEngine.Timeline
  3. {
  4. class ActivationMixerPlayable : PlayableBehaviour
  5. {
  6. ActivationTrack.PostPlaybackState m_PostPlaybackState;
  7. bool m_BoundGameObjectInitialStateIsActive;
  8. private GameObject m_BoundGameObject;
  9. public static ScriptPlayable<ActivationMixerPlayable> Create(PlayableGraph graph, int inputCount)
  10. {
  11. return ScriptPlayable<ActivationMixerPlayable>.Create(graph, inputCount);
  12. }
  13. public ActivationTrack.PostPlaybackState postPlaybackState
  14. {
  15. get { return m_PostPlaybackState; }
  16. set { m_PostPlaybackState = value; }
  17. }
  18. public override void OnPlayableDestroy(Playable playable)
  19. {
  20. if (m_BoundGameObject == null)
  21. return;
  22. switch (m_PostPlaybackState)
  23. {
  24. case ActivationTrack.PostPlaybackState.Active:
  25. m_BoundGameObject.SetActive(true);
  26. break;
  27. case ActivationTrack.PostPlaybackState.Inactive:
  28. m_BoundGameObject.SetActive(false);
  29. break;
  30. case ActivationTrack.PostPlaybackState.Revert:
  31. m_BoundGameObject.SetActive(m_BoundGameObjectInitialStateIsActive);
  32. break;
  33. case ActivationTrack.PostPlaybackState.LeaveAsIs:
  34. default:
  35. break;
  36. }
  37. }
  38. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
  39. {
  40. if (m_BoundGameObject == null)
  41. {
  42. m_BoundGameObject = playerData as GameObject;
  43. m_BoundGameObjectInitialStateIsActive = m_BoundGameObject != null && m_BoundGameObject.activeSelf;
  44. }
  45. if (m_BoundGameObject == null)
  46. return;
  47. int inputCount = playable.GetInputCount();
  48. bool hasInput = false;
  49. for (int i = 0; i < inputCount; i++)
  50. {
  51. if (playable.GetInputWeight(i) > 0)
  52. {
  53. hasInput = true;
  54. break;
  55. }
  56. }
  57. m_BoundGameObject.SetActive(hasInput);
  58. }
  59. }
  60. }