AimLoadChecker.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. /**瞄准器负载检测 */
  7. public class AimLoadChecker : MonoBehaviour
  8. {
  9. [SerializeField] GameObject outTip;
  10. // void Update()
  11. // {
  12. // bool needActiveOutTip = false;
  13. // if (ArmBow.ins && ArmBow.ins.IsCanShoot() && TargetBody.ins) {
  14. // RaycastHit ray = CrossHair.ins.GetRaycastHit();
  15. // if (ray.transform && ray.transform.gameObject.name == "TargetBody") {
  16. // float mySpeed = Arrow.speed;
  17. // if (GameAssistUI.ins) {
  18. // mySpeed *= GameAssistUI.ins.shootScaleValue;
  19. // }
  20. // Vector3 destination = ray.point;
  21. // Vector3 startPoint = BowCamera.ins.transform.position;
  22. // float deltaX = Mathf.Sqrt(
  23. // Mathf.Pow(destination.x - startPoint.x, 2) +
  24. // Mathf.Pow(destination.z - startPoint.z,2)
  25. // );
  26. // float deltaY = destination.y - startPoint.y;
  27. // float a = 0.5f * Physics.gravity.y * Mathf.Pow(deltaX, 2) / Mathf.Pow(mySpeed, 2);
  28. // float b = deltaX;
  29. // float c = a - deltaY;
  30. // bool hasParabolaAngle = Mathf.Pow(b, 2) - 4 * a * c >= 0;
  31. // if (hasParabolaAngle) {
  32. // float res1 = (-b + Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
  33. // float res2 = (-b - Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
  34. // float parabolaAngle = Mathf.Min(Mathf.Atan(res1), Mathf.Atan(res2)) / Mathf.PI * 180;
  35. // needActiveOutTip = parabolaAngle > 5;
  36. // }
  37. // }
  38. // }
  39. // ActiveOutTip(needActiveOutTip);
  40. // }
  41. // public void ActiveOutTip(bool value)
  42. // {
  43. // if (outTip.activeSelf != value) {
  44. // outTip.SetActive(value);
  45. // }
  46. // }
  47. public static AimLoadChecker ins;
  48. void Awake() {
  49. ins = this;
  50. }
  51. void OnDestroy() {
  52. if (ins == this) ins = null;
  53. }
  54. Sequence outTipSeq;
  55. public void ShowOutTip() {
  56. if (outTipSeq != null) {
  57. outTipSeq.Kill(true);
  58. }
  59. outTip.SetActive(true);
  60. Text text = outTip.GetComponent<Text>();
  61. Sequence seq = DOTween.Sequence();
  62. seq.Append(text.DOFade(1, 0f));
  63. seq.AppendInterval(3f);
  64. seq.Append(text.DOFade(0, 1f));
  65. seq.AppendCallback(delegate() {
  66. outTip.SetActive(false);
  67. outTipSeq = null;
  68. });
  69. seq.SetUpdate(true);
  70. outTipSeq = seq;
  71. }
  72. }