AnimatorCockController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using UnityEngine;
  3. namespace Game
  4. {
  5. public class AnimatorCockController : ICockController
  6. {
  7. private readonly Animator _animator;
  8. private const string Status = "status";
  9. private const int StatusIdle = 1;
  10. private const int StatusWalk = 2;
  11. private const int StatusRun = 3;
  12. private const int StatusIdle2 = 4;
  13. private const string TriggerAttack = "attack";
  14. private const string TriggerUnderAttack = "underattack";
  15. private const string TriggerJumpAttack = "jumpattack";
  16. private const string TriggerDie = "die";
  17. private const string TriggerRandom1 = "random1";
  18. private const string TriggerRandom2 = "random2";
  19. private const string TriggerRandom3 = "random3";
  20. private const string TriggerRandom4 = "random4";
  21. private const string TriggerRandom5 = "random5";
  22. public AnimatorCockController(Animator animator)
  23. {
  24. _animator = animator;
  25. }
  26. public Action OnRun { get; set; }
  27. public Action OnIdle { get; set; }
  28. public Action OnAttack { get; set; }
  29. public Action OnJumpAttack { get; set; }
  30. public void Idle()
  31. {
  32. _animator.SetInteger(Status, StatusIdle);
  33. OnIdle?.Invoke();
  34. }
  35. public void Walk()
  36. {
  37. throw new System.NotImplementedException();
  38. }
  39. public void Run()
  40. {
  41. _animator.SetInteger(Status, StatusRun);
  42. OnRun?.Invoke();
  43. }
  44. public void IdleInBattle()
  45. {
  46. _animator.SetInteger(Status, StatusIdle2);
  47. OnIdle?.Invoke();
  48. }
  49. public void Attack()
  50. {
  51. _animator.ResetTrigger(TriggerAttack);
  52. _animator.SetTrigger(TriggerAttack);
  53. OnAttack?.Invoke();
  54. }
  55. public void JumpAndAttack()
  56. {
  57. _animator.ResetTrigger(TriggerJumpAttack);
  58. _animator.SetTrigger(TriggerJumpAttack);
  59. OnJumpAttack?.Invoke();
  60. }
  61. public void UnderAttack()
  62. {
  63. _animator.ResetTrigger(TriggerUnderAttack);
  64. _animator.SetTrigger(TriggerUnderAttack);
  65. }
  66. public void Die()
  67. {
  68. _animator.ResetTrigger(TriggerDie);
  69. _animator.SetTrigger(TriggerDie);
  70. }
  71. public void RandomAttack(int attack)
  72. {
  73. switch (attack)
  74. {
  75. case 1:
  76. _animator.ResetTrigger(TriggerRandom1);
  77. _animator.SetTrigger(TriggerRandom1);
  78. break;
  79. case 2:
  80. _animator.ResetTrigger(TriggerRandom2);
  81. _animator.SetTrigger(TriggerRandom2);
  82. break;
  83. case 3:
  84. _animator.ResetTrigger(TriggerRandom3);
  85. _animator.SetTrigger(TriggerRandom3);
  86. break;
  87. case 4:
  88. _animator.ResetTrigger(TriggerRandom4);
  89. _animator.SetTrigger(TriggerRandom4);
  90. break;
  91. case 5:
  92. _animator.ResetTrigger(TriggerRandom5);
  93. _animator.SetTrigger(TriggerRandom5);
  94. break;
  95. default:
  96. _animator.ResetTrigger(TriggerJumpAttack);
  97. _animator.SetTrigger(TriggerJumpAttack);
  98. break;
  99. }
  100. OnJumpAttack?.Invoke();
  101. }
  102. public void BeLift()
  103. {
  104. }
  105. }
  106. }