GameAssistUI.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. Transform icon1 = btnViewTarget.transform.Find("Icon1");
  59. Transform icon2 = btnViewTarget.transform.Find("Icon2");
  60. bool isOpen = icon2.gameObject.activeSelf;
  61. if (isOpen) {
  62. icon1.gameObject.SetActive(true);
  63. icon2.gameObject.SetActive(false);
  64. targetView.gameObject.SetActive(false);
  65. btnViewTarget.GetComponentInChildren<TextAutoLanguage>().SetText(204);
  66. } else {
  67. icon1.gameObject.SetActive(false);
  68. icon2.gameObject.SetActive(true);
  69. targetView.gameObject.SetActive(true);
  70. btnViewTarget.GetComponentInChildren<TextAutoLanguage>().SetText(205);
  71. }
  72. });
  73. targetView.gameObject.SetActive(false);
  74. if (GameMgr.gameType == 2) {
  75. targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
  76. btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
  77. }
  78. }
  79. // ------ 开镜瞄准功能 ------
  80. Transform scope = null;
  81. float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
  82. float[] scaleAimArmBowZs = {-0.813f, -0.799f, -0.77f, -0.695f, -0.55f};
  83. float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  84. Sequence seq1 = null;
  85. bool openScaleAim()
  86. {
  87. int scaleValue = GetPropScaleAimValue();
  88. if (scaleValue > 0)
  89. {
  90. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  91. bowCamera.banCameraFieldOfView = true;
  92. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  93. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  94. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  95. localPosition.z = -2;
  96. ArmBow.ins.transform.localPosition = localPosition;
  97. scope = bowCamera.transform.Find("Scope");
  98. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  99. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  100. return true;
  101. }
  102. if (seq1 != null && !seq1.IsComplete()) {
  103. seq1.Complete();
  104. }
  105. seq1 = DOTween.Sequence();
  106. seq1.Append(text1.DOFade(1, 0.5f));
  107. seq1.AppendInterval(2);
  108. seq1.Append(text1.DOFade(0, 0.5f));
  109. return false;
  110. }
  111. void closeScaleAim()
  112. {
  113. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  114. bowCamera.banCameraFieldOfView = false;
  115. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  116. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  117. localPosition.z = -0.1f;
  118. ArmBow.ins.transform.localPosition = localPosition;
  119. scope.localScale = new Vector3(0, 0, 0);
  120. scope = null;
  121. }
  122. int GetPropScaleAimValue()
  123. {
  124. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  125. foreach (var prop in props)
  126. {
  127. if (prop.config.type == 1) {
  128. PropScaleAim config = prop.config as PropScaleAim;
  129. return config.scaleValue;
  130. }
  131. }
  132. return 0;
  133. }
  134. // ------ 发射加速功能 ------
  135. public int shootScaleValue = 0;
  136. Sequence seq2 = null;
  137. bool openScaleShoot()
  138. {
  139. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  140. foreach (var prop in props)
  141. {
  142. if (prop.config.type == 2) {
  143. PropScaleShoot config = prop.config as PropScaleShoot;
  144. shootScaleValue = config.scaleValue;
  145. return true;
  146. }
  147. }
  148. if (seq2 != null && !seq2.IsComplete()) {
  149. seq2.Complete();
  150. }
  151. seq2 = DOTween.Sequence();
  152. seq2.Append(text2.DOFade(1, 0.5f));
  153. seq2.AppendInterval(2);
  154. seq2.Append(text2.DOFade(0, 0.5f));
  155. return false;
  156. }
  157. void closeScaleShoot()
  158. {
  159. shootScaleValue = 0;
  160. }
  161. }