GameAssistUI.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. Application.Quit();
  20. });
  21. this.transform.Find("Button1").GetComponent<Button>().onClick.AddListener(delegate(){
  22. AudioMgr.ins.PlayBtn();
  23. GameRuleView.Create();
  24. });
  25. Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
  26. btnScaleAim.onClick.AddListener(delegate(){
  27. AudioMgr.ins.PlayBtn();
  28. if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
  29. btnScaleAim.GetComponentInChildren<Image>().material = null;
  30. closeScaleAim();
  31. } else {
  32. if (openScaleAim()) {
  33. btnScaleAim.GetComponentInChildren<Image>().material = outlight;
  34. }
  35. }
  36. });
  37. Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
  38. btnScaleShoot.onClick.AddListener(delegate(){
  39. AudioMgr.ins.PlayBtn();
  40. if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
  41. btnScaleShoot.GetComponentInChildren<Image>().material = null;
  42. closeScaleShoot();
  43. } else {
  44. if (openScaleShoot()) {
  45. btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
  46. }
  47. }
  48. });
  49. Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
  50. btnIdentity.onClick.AddListener(delegate(){
  51. AudioMgr.ins.PlayBtn();
  52. AimHandler.ins.DoIdentity();
  53. });
  54. // ------ 查看靶子 ------
  55. Transform targetView = this.transform.Find("TargetView");
  56. Button btnViewTarget = this.transform.Find("Button10").GetComponent<Button>();
  57. btnViewTarget.onClick.AddListener(delegate(){
  58. AudioMgr.ins.PlayBtn();
  59. Transform icon1 = btnViewTarget.transform.Find("Icon1");
  60. Transform icon2 = btnViewTarget.transform.Find("Icon2");
  61. bool isOpen = icon2.gameObject.activeSelf;
  62. if (isOpen) {
  63. icon1.gameObject.SetActive(true);
  64. icon2.gameObject.SetActive(false);
  65. targetView.gameObject.SetActive(false);
  66. btnViewTarget.GetComponentInChildren<TextAutoLanguage>().SetText(204);
  67. } else {
  68. icon1.gameObject.SetActive(false);
  69. icon2.gameObject.SetActive(true);
  70. targetView.gameObject.SetActive(true);
  71. btnViewTarget.GetComponentInChildren<TextAutoLanguage>().SetText(205);
  72. }
  73. });
  74. targetView.gameObject.SetActive(false);
  75. if (GameMgr.gameType == 2) {
  76. targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
  77. btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
  78. }
  79. }
  80. // ------ 开镜瞄准功能 ------
  81. Transform scope = null;
  82. float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
  83. float[] scaleAimArmBowZs = {-0.813f, -0.799f, -0.77f, -0.695f, -0.55f};
  84. float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  85. Sequence seq1 = null;
  86. bool openScaleAim()
  87. {
  88. int scaleValue = GetPropScaleAimValue();
  89. if (scaleValue > 0)
  90. {
  91. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  92. bowCamera.banCameraFieldOfView = true;
  93. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  94. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  95. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  96. localPosition.z = -2;
  97. ArmBow.ins.transform.localPosition = localPosition;
  98. scope = bowCamera.transform.Find("Scope");
  99. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  100. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  101. return true;
  102. }
  103. if (seq1 != null && !seq1.IsComplete()) {
  104. seq1.Complete();
  105. }
  106. seq1 = DOTween.Sequence();
  107. seq1.Append(text1.DOFade(1, 0.5f));
  108. seq1.AppendInterval(2);
  109. seq1.Append(text1.DOFade(0, 0.5f));
  110. return false;
  111. }
  112. void closeScaleAim()
  113. {
  114. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  115. bowCamera.banCameraFieldOfView = false;
  116. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  117. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  118. localPosition.z = -0.1f;
  119. ArmBow.ins.transform.localPosition = localPosition;
  120. scope.localScale = new Vector3(0, 0, 0);
  121. scope = null;
  122. }
  123. int GetPropScaleAimValue()
  124. {
  125. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  126. foreach (var prop in props)
  127. {
  128. if (prop.config.type == 1) {
  129. PropScaleAim config = prop.config as PropScaleAim;
  130. return config.scaleValue;
  131. }
  132. }
  133. return 0;
  134. }
  135. // ------ 发射加速功能 ------
  136. public int shootScaleValue = 0;
  137. Sequence seq2 = null;
  138. bool openScaleShoot()
  139. {
  140. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  141. foreach (var prop in props)
  142. {
  143. if (prop.config.type == 2) {
  144. PropScaleShoot config = prop.config as PropScaleShoot;
  145. shootScaleValue = config.scaleValue;
  146. return true;
  147. }
  148. }
  149. if (seq2 != null && !seq2.IsComplete()) {
  150. seq2.Complete();
  151. }
  152. seq2 = DOTween.Sequence();
  153. seq2.Append(text2.DOFade(1, 0.5f));
  154. seq2.AppendInterval(2);
  155. seq2.Append(text2.DOFade(0, 0.5f));
  156. return false;
  157. }
  158. void closeScaleShoot()
  159. {
  160. shootScaleValue = 0;
  161. }
  162. }