WeaponsBaseMecanim.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.Characters.FirstPerson;
  5. public enum WeaponType {
  6. Bow,
  7. Crossbow,
  8. Bludgeoning,
  9. Spear
  10. }
  11. public abstract class WeaponsBaseMecanim : MonoBehaviour {
  12. #region Fields
  13. protected WeaponType wpType;
  14. public WeaponType WpType { get { return wpType; } }
  15. public RuntimeAnimatorController properArmsAnimation;
  16. public AudioClip TakeSound;
  17. public AudioClip FireSound;
  18. protected AudioSource Source;
  19. protected Animator[] myAnims = null;
  20. // bool disableWeapon = false;
  21. protected bool isReloading;
  22. // float nextFireTime = 0.0f;
  23. #endregion
  24. protected virtual void Awake()
  25. {
  26. Source = GetComponent<AudioSource>();
  27. // disableWeapon = false;
  28. if (GetComponentInChildren<Animator>()) {
  29. myAnims = GetComponentsInChildren <Animator> ();
  30. }
  31. }
  32. protected virtual void OnEnable()
  33. {
  34. Source.clip = TakeSound;
  35. Source.Play();
  36. canFire = true;
  37. // disableWeapon = false;
  38. isReloading = false;
  39. playerSync.UpdateCurrentGun (GetComponent <WeaponsBaseMecanim> ());
  40. }
  41. protected virtual void OnDisable ()
  42. {
  43. // disableWeapon = false;
  44. }
  45. protected virtual void Update()
  46. {
  47. InputUpdate();
  48. Aim();
  49. UpdateAnimatorParameters ();
  50. }
  51. protected abstract void InputUpdate ();
  52. // protected abstract void SyncState ();
  53. protected virtual void UpdateAnimatorParameters () {}
  54. protected virtual void Aim() {}
  55. protected IEnumerator WaitAnimationFinish (AnimationClip clip)
  56. {
  57. float reloadTime = clip.length;
  58. yield return new WaitForSeconds (reloadTime);
  59. }
  60. public virtual void DisableWeapon()
  61. {
  62. // canAim = false;
  63. canFire = false;
  64. // disableWeapon = true;
  65. StopAllCoroutines();
  66. playerSync.TriggerLowerGunAnimation ();
  67. // SendMessageUpwards ("TriggerLowerGunAnimation");
  68. }
  69. protected bool isFiring = false;
  70. public bool IsFiring { get { return isFiring; } }
  71. protected bool firePressed = false;
  72. public bool FirePressed { get { return firePressed; } }
  73. protected bool isAimed;
  74. public bool IsAimed { get { return isAimed; } }
  75. protected bool canFire = true;
  76. public bool CanFire { get { return canFire; } }
  77. protected bool isStriking = false;
  78. public virtual bool IsStriking { get { return isStriking; } }
  79. protected bool isStrikingMiss = false;
  80. public virtual bool IsStrikingMiss { get { return isStrikingMiss; } }
  81. protected bool isSwingingRight = false;
  82. public bool IsSwingingRight { get { return isSwingingRight; } }
  83. protected bool isSwingingLeft = false;
  84. public bool IsSwingingLeft { get { return isSwingingLeft; } }
  85. protected bool isSpinning = false;
  86. public bool IsSpinning { get { return isSpinning; } }
  87. protected bool isBlocking = false;
  88. public virtual bool IsBlocking { get { return isBlocking; } }
  89. protected bool blockHit = false;
  90. public bool BlockHit { get { return blockHit; } }
  91. protected bool isThrowing = false;
  92. public virtual bool IsThrowing { get { return isThrowing; } }
  93. protected bool isSpearLow = false;
  94. public virtual bool IsSpearLow { get { return isSpearLow; } }
  95. protected FirstPersonController controller
  96. {
  97. get
  98. {
  99. return transform.root.GetComponent<FirstPersonController>();
  100. }
  101. }
  102. protected PlayerSyncMecanim playerSync
  103. {
  104. get
  105. {
  106. return PlayerSyncMecanim.Instance;
  107. }
  108. }
  109. protected PlayerManager playerManager
  110. {
  111. get
  112. {
  113. return PlayerManager.Instance;
  114. }
  115. }
  116. } // class