AimLoadChecker.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Sequence outTipSeq;
  52. public void ShowOutTip() {
  53. if (outTipSeq != null) {
  54. outTipSeq.Kill(true);
  55. }
  56. outTip.SetActive(true);
  57. Text text = outTip.GetComponent<Text>();
  58. Sequence seq = DOTween.Sequence();
  59. seq.Append(text.DOFade(1, 0f));
  60. seq.AppendInterval(3f);
  61. seq.Append(text.DOFade(0, 1f));
  62. seq.AppendCallback(delegate() {
  63. outTip.SetActive(false);
  64. outTipSeq = null;
  65. });
  66. seq.SetUpdate(true);
  67. outTipSeq = seq;
  68. }
  69. }