ScriptPlayableAssetAnimation.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 ScriptPlayableAssetAnimation : PlayableAsset, IPlayableAssetDeal
  8. {
  9. public int masterId;
  10. public StoryLocation location = StoryLocation.Left;
  11. public Animator animator;
  12. public float startTime;
  13. public float endTime;
  14. public string animationName;
  15. public StoryMgr mgr;
  16. bool isPlayed = false;
  17. // Factory method that generates a playable based on this asset
  18. public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
  19. {
  20. ScriptPlayableTrackAnimation animationPlayable = new ScriptPlayableTrackAnimation();
  21. animationPlayable.Init(masterId, location, animationName, mgr);
  22. return ScriptPlayable<ScriptPlayableTrackAnimation>.Create(graph, animationPlayable);
  23. }
  24. public void DealWithSimpleMode(int time)
  25. {
  26. if (animator == null)
  27. return;
  28. if (time >= startTime && time < endTime)
  29. {
  30. if (!isPlayed)
  31. {
  32. animator.Play(animationName);
  33. isPlayed = true;
  34. }
  35. }
  36. }
  37. }