ArmBow.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ArmBow : MonoBehaviour
  5. {
  6. [SerializeField] AnimationPlayer AP_arm;
  7. [SerializeField] Animator AP_bow;
  8. [SerializeField] AnimationPlayer AP_bowForArrow;
  9. [SerializeField] GameObject arrow;
  10. [SerializeField] BowCamera bowCamera;
  11. public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
  12. private bool canShoot = false;
  13. private bool pulling = false;
  14. private bool readying = false;
  15. public static ArmBow ins;
  16. void Start()
  17. {
  18. ins = this;
  19. this.readyShoot();
  20. }
  21. void OnDestroy()
  22. {
  23. ins = null;
  24. }
  25. void FixedUpdate()
  26. {
  27. // if (this.canShoot)
  28. // {
  29. // DebugBowPower.ins.DoUpdate();
  30. // }
  31. }
  32. void Update()
  33. {
  34. if (Input.GetKeyDown(KeyCode.Q))
  35. {
  36. this.ADS_fire();
  37. }
  38. if (this.pulling) {
  39. this.bowCamera.updateFollowPullBow();
  40. } else if (!this.canShoot)
  41. {
  42. this.bowCamera.updateGiveUpPullBow();
  43. }
  44. CrossHair.ins.gameObject.SetActive(this.canShoot);
  45. }
  46. void onComplete(AnimationPlayerCompleteResult res) {
  47. if (res.index == 1) {
  48. this.ADS_idle();
  49. } else if (res.index == 3) {
  50. this.idle();
  51. }
  52. }
  53. void idle() {
  54. this.arrow.SetActive(false);
  55. AP_arm.play(0, WrapMode.Loop);
  56. AP_bowForArrow.play(0, WrapMode.Loop);
  57. // AP_bow.SetBool("ads", false);
  58. // AP_bow.SetBool("fire", false);
  59. AP_bow.Play("gong_daiji");
  60. AP_arm.completeCallback = null;
  61. this.pulling = false;
  62. this.canShoot = false;
  63. // DebugBowPower.ins.Init();
  64. }
  65. public void idleToADS() {
  66. this.arrow.SetActive(true);
  67. AP_arm.play(1, WrapMode.Once);
  68. AP_bowForArrow.play(1, WrapMode.Once);
  69. // AP_bow.SetBool("ads", true);
  70. // AP_bow.SetBool("idle", false);
  71. AP_bow.Play("gong_lagong");
  72. AP_arm.completeCallback = onComplete;
  73. this.pulling = true;
  74. this.canShoot = false;
  75. }
  76. void ADS_idle() {
  77. AP_arm.play(2, WrapMode.Loop);
  78. AP_bowForArrow.play(2, WrapMode.Loop);
  79. AP_bow.Play("gong_lagongdaiji");
  80. AP_arm.completeCallback = null;
  81. this.canShoot = true;
  82. this.pulling = false;
  83. // DebugBowPower.ins.PullFinish();
  84. }
  85. public void ADS_fire() {
  86. if (!this.canShoot)
  87. {
  88. return;
  89. }
  90. this.pulling = false;
  91. this.canShoot = false;
  92. this.readying = false;
  93. AP_arm.play(3, WrapMode.Once);
  94. AP_bowForArrow.play(3, WrapMode.Once);
  95. // AP_bow.SetBool("fire", true);
  96. AP_bow.Play("gong_songshou");
  97. AP_arm.completeCallback = onComplete;
  98. this.Invoke("shoot", 0.1f);
  99. }
  100. public void readyShoot() {
  101. this.readying = true;
  102. this.bowCamera.setFieldOfView(60, false);
  103. this.idle();
  104. this.gameObject.SetActive(true);
  105. this.Invoke("idleToADS", 0.5f);
  106. }
  107. public void shoot() {
  108. Vector3 rayHitPoint = CrossHair.ins.getRayHitPoint();
  109. GameObject arrowCopy = GameObject.Instantiate(this.arrow, this.bowCamera.transform.position, this.bowCamera.transform.rotation);
  110. Vector3 s1 = arrowCopy.transform.localScale;
  111. Vector3 s2 = bowCamera.transform.localScale;
  112. arrowCopy.transform.localScale = new Vector3(s1.x * s2.x, s1.y * s2.y, s1.z * s2.z);
  113. arrowCopy.transform.LookAt(rayHitPoint);
  114. Arrow arrowComp = arrowCopy.AddComponent<Arrow>();
  115. arrowComp.armBow = this;
  116. // arrowComp.calculateSpeed(rayHitPoint);
  117. // Arrow.speed = BaseSpeedSlider.ins.getValue() * DebugBowPower.ins.getPowerPercent();
  118. // Arrow.speed = BaseSpeedSlider.ins.getValue();
  119. Arrow.speed = Mathf.Pow(ShootCheck.ins.shootSpeed, ShootCheck.ins.shootSpeed < 13 ? 2f: (ShootCheck.ins.shootSpeed < 15 ? 2.5f : 3.0f));
  120. arrowCopy.SetActive(true);
  121. arrow.SetActive(false);
  122. AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(arrowCopy));
  123. this.gameObject.SetActive(false);
  124. }
  125. public void OnEnable()
  126. {
  127. AudioMgr.GetAudioSource(this.gameObject).clip = null;
  128. }
  129. //debug
  130. public void mouseDown()
  131. {
  132. if (!this.readying) return;
  133. if (this.pulling || this.canShoot) return;
  134. this.idleToADS();
  135. }
  136. public void mouseUp()
  137. {
  138. if (!this.readying) return;
  139. if (this.pulling) {
  140. this.idle();
  141. } else if (this.canShoot) {
  142. this.ADS_fire();
  143. }
  144. }
  145. }