GameAssistUI.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. using UnityEngine.SceneManagement;
  7. public class GameAssistUI : MonoBehaviour
  8. {
  9. [SerializeField] Material outlight;
  10. [SerializeField] Text text1;
  11. [SerializeField] Text text2;
  12. public static GameAssistUI ins;
  13. void Start()
  14. {
  15. ins = this;
  16. this.transform.Find("Button0").GetComponent<Button>().onClick.AddListener(delegate(){
  17. AudioMgr.ins.PlayBtn();
  18. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  19. });
  20. this.transform.Find("Button1").GetComponent<Button>().onClick.AddListener(delegate(){
  21. AudioMgr.ins.PlayBtn();
  22. GameRuleView.Create();
  23. });
  24. Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
  25. btnScaleAim.onClick.AddListener(delegate(){
  26. AudioMgr.ins.PlayBtn();
  27. if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
  28. btnScaleAim.GetComponentInChildren<Image>().material = null;
  29. closeScaleAim();
  30. } else {
  31. if (openScaleAim()) {
  32. btnScaleAim.GetComponentInChildren<Image>().material = outlight;
  33. }
  34. }
  35. });
  36. Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
  37. btnScaleShoot.onClick.AddListener(delegate(){
  38. AudioMgr.ins.PlayBtn();
  39. if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
  40. btnScaleShoot.GetComponentInChildren<Image>().material = null;
  41. closeScaleShoot();
  42. } else {
  43. if (openScaleShoot()) {
  44. btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
  45. }
  46. }
  47. });
  48. Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
  49. btnIdentity.onClick.AddListener(delegate(){
  50. AudioMgr.ins.PlayBtn();
  51. AimHandler.ins.DoIdentity();
  52. });
  53. // ------ 查看靶子 ------
  54. Transform targetView = this.transform.Find("TargetView");
  55. Button btnViewTarget = this.transform.Find("Button10").GetComponent<Button>();
  56. btnViewTarget.onClick.AddListener(delegate(){
  57. AudioMgr.ins.PlayBtn();
  58. TargetView.ins.ReverseActive();
  59. });
  60. if (GameMgr.gameType == 2) {
  61. targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
  62. btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
  63. }
  64. }
  65. // ------ 开镜瞄准功能 ------
  66. Transform scope = null;
  67. float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
  68. float[] scaleAimArmBowZs = {-0.813f, -0.799f, -0.77f, -0.695f, -0.55f};
  69. float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  70. Sequence seq1 = null;
  71. bool openScaleAim()
  72. {
  73. int scaleValue = GetPropScaleAimValue();
  74. if (scaleValue > 0)
  75. {
  76. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  77. bowCamera.banCameraFieldOfView = true;
  78. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  79. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  80. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  81. localPosition.z = -2;
  82. ArmBow.ins.transform.localPosition = localPosition;
  83. scope = bowCamera.transform.Find("Scope");
  84. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  85. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  86. return true;
  87. }
  88. if (seq1 != null && !seq1.IsComplete()) {
  89. seq1.Complete();
  90. }
  91. seq1 = DOTween.Sequence();
  92. seq1.Append(text1.DOFade(1, 0.5f));
  93. seq1.AppendInterval(2);
  94. seq1.Append(text1.DOFade(0, 0.5f));
  95. return false;
  96. }
  97. void closeScaleAim()
  98. {
  99. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  100. bowCamera.banCameraFieldOfView = false;
  101. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  102. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  103. localPosition.z = -0.1f;
  104. ArmBow.ins.transform.localPosition = localPosition;
  105. scope.localScale = new Vector3(0, 0, 0);
  106. scope = null;
  107. }
  108. int GetPropScaleAimValue()
  109. {
  110. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  111. foreach (var prop in props)
  112. {
  113. if (prop.config.type == 1) {
  114. PropScaleAim config = prop.config as PropScaleAim;
  115. return config.scaleValue;
  116. }
  117. }
  118. return 0;
  119. }
  120. // ------ 发射加速功能 ------
  121. public int shootScaleValue = 0;
  122. Sequence seq2 = null;
  123. bool openScaleShoot()
  124. {
  125. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  126. foreach (var prop in props)
  127. {
  128. if (prop.config.type == 2) {
  129. PropScaleShoot config = prop.config as PropScaleShoot;
  130. shootScaleValue = config.scaleValue;
  131. GameDebug.ins.caluculateAbsoluteAngle();
  132. return true;
  133. }
  134. }
  135. if (seq2 != null && !seq2.IsComplete()) {
  136. seq2.Complete();
  137. }
  138. seq2 = DOTween.Sequence();
  139. seq2.Append(text2.DOFade(1, 0.5f));
  140. seq2.AppendInterval(2);
  141. seq2.Append(text2.DOFade(0, 0.5f));
  142. return false;
  143. }
  144. void closeScaleShoot()
  145. {
  146. shootScaleValue = 0;
  147. GameDebug.ins.caluculateAbsoluteAngle();
  148. }
  149. }