CubismMotionPreview.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using Live2D.Cubism.Core;
  8. using Live2D.Cubism.Framework.Motion;
  9. using UnityEngine;
  10. namespace Live2D.Cubism.Samples.OriginalWorkflow.Motion
  11. {
  12. [RequireComponent(typeof(CubismMotionController))]
  13. public class CubismMotionPreview : MonoBehaviour
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. public AnimationClip Animation;
  19. /// <summary>
  20. /// MotionController to be operated.
  21. /// </summary>
  22. CubismMotionController _motionController;
  23. /// <summary>
  24. /// Get motion controller.
  25. /// </summary>
  26. private void Start()
  27. {
  28. var model = this.FindCubismModel();
  29. _motionController = model.GetComponent<CubismMotionController>();
  30. _motionController.AnimationEndHandler += PlayIdleAnimation;
  31. if (Animation == null)
  32. {
  33. return;
  34. }
  35. PlayIdleAnimation();
  36. }
  37. private void PlayIdleAnimation(int index = 0)
  38. {
  39. _motionController.PlayAnimation(Animation, isLoop: false, priority: CubismMotionPriority.PriorityIdle);
  40. }
  41. /// <summary>
  42. /// Play specified animation.
  43. /// </summary>
  44. /// <param name="animation">Animation clip to play.</param>
  45. public void PlayAnimation(AnimationClip animation)
  46. {
  47. _motionController.PlayAnimation(animation, isLoop: false, priority: CubismMotionPriority.PriorityForce);
  48. }
  49. }
  50. }