Advertisement
zORg_alex
Apr 23rd, 2024
6
0
Never
This is comment for paste Serialized AnimatorControllerParameter
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Use case:
  2. using UnityEngine;
  3. using Sirenix.OdinInspector;
  4. using zORgs;
  5. using zORgs.Utilities;
  6. using Parameter = zORgs.Utilities.AnimatorControllerParameter;
  7.  
  8. [RequireComponent(typeof(Animator))]
  9. public class BasicLocomotionInterface_v2 : MonoBehaviour
  10. {
  11. [HorizontalGroup("Parameters")]
  12. [BoxGroup("Parameters/Move")]
  13. public Parameter MoveZ;
  14. [BoxGroup("Parameters/Move")]
  15. public Parameter IsMoving;
  16. [BoxGroup("Parameters/State")]
  17. public Parameter Grounded;
  18. [BoxGroup("Parameters/State")]
  19. public Parameter Jump;
  20. [BoxGroup("Parameters/State")]
  21. public Parameter FreeFall;
  22.  
  23.  
  24. [BoxGroup("Aim")]
  25. public int _aimingLayerIndex;
  26. [BoxGroup("Aim")]
  27. public Parameter Empty;
  28. [BoxGroup("Aim")]
  29. public Parameter Aim;
  30. [BoxGroup("Aim")]
  31. public Parameter Rifle;
  32.  
  33. private Animator _animator;
  34. private void Awake()
  35. {
  36. _animator = GetComponent<Animator>();
  37. }
  38.  
  39. public void SetForwardSpeed(float value)
  40. {
  41. _animator.SetParameter(MoveZ, value);
  42. _animator.SetParameter(IsMoving, value != 0f);
  43. }
  44.  
  45. public void SetGrounded(bool value) => _animator.SetParameter(Grounded, value);
  46. public void SetJump(bool value) => _animator.SetParameter(Jump, value);
  47. public void SetFreeFall(bool value) => _animator.SetParameter(FreeFall, value);
  48.  
  49.  
  50. [Button]
  51. public void StartAiming()
  52. {
  53. this.Tween(v => _animator.SetLayerWeight(_aimingLayerIndex, v), 0, 1, .1f);
  54. _animator.SetParameter(Aim, true);
  55. }
  56. [Button]
  57. public void StopAiming()
  58. {
  59. this.Tween(v => _animator.SetLayerWeight(_aimingLayerIndex, v), 0, 1, .1f);
  60. _animator.SetParameter(Aim, false);
  61. }
  62. [Button]
  63. public void RifleEquipped()
  64. {
  65. this.Tween(v => _animator.SetLayerWeight(_aimingLayerIndex, v), 0, 1, .1f);
  66. _animator.SetParameter(Rifle, true);
  67. }
  68. [Button]
  69. public void UnEquip()
  70. {
  71. this.Tween(v => _animator.SetLayerWeight(_aimingLayerIndex, v), 1, 0, .25f);
  72. _animator.SetParameter(Rifle, false);
  73. _animator.SetParameter(Rifle, false);
  74. }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement