GameAssistUI.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  69. Sequence seq1 = null;
  70. bool openScaleAim()
  71. {
  72. int scaleValue = GetPropScaleAimValue();
  73. if (scaleValue > 0)
  74. {
  75. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  76. bowCamera.banCameraFieldOfView = true;
  77. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  78. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  79. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  80. localPosition.z = -2;
  81. ArmBow.ins.transform.localPosition = localPosition;
  82. scope = bowCamera.transform.Find("Scope");
  83. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  84. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  85. return true;
  86. }
  87. if (seq1 != null && !seq1.IsComplete()) {
  88. seq1.Complete();
  89. }
  90. seq1 = DOTween.Sequence();
  91. seq1.Append(text1.DOFade(1, 0.5f));
  92. seq1.AppendInterval(2);
  93. seq1.Append(text1.DOFade(0, 0.5f));
  94. return false;
  95. }
  96. void closeScaleAim()
  97. {
  98. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  99. bowCamera.banCameraFieldOfView = false;
  100. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  101. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  102. localPosition.z = -0.1f;
  103. ArmBow.ins.transform.localPosition = localPosition;
  104. scope.localScale = new Vector3(0, 0, 0);
  105. scope = null;
  106. }
  107. int GetPropScaleAimValue()
  108. {
  109. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  110. foreach (var prop in props)
  111. {
  112. if (prop.config.type == 1) {
  113. PropScaleAim config = prop.config as PropScaleAim;
  114. return config.scaleValue;
  115. }
  116. }
  117. return 0;
  118. }
  119. // ------ 发射加速功能 ------
  120. public int shootScaleValue = 1;
  121. Sequence seq2 = null;
  122. bool openScaleShoot()
  123. {
  124. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  125. foreach (var prop in props)
  126. {
  127. if (prop.config.type == 2) {
  128. PropScaleShoot config = prop.config as PropScaleShoot;
  129. shootScaleValue = config.scaleValue;
  130. if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
  131. return true;
  132. }
  133. }
  134. if (seq2 != null && !seq2.IsComplete()) {
  135. seq2.Complete();
  136. }
  137. seq2 = DOTween.Sequence();
  138. seq2.Append(text2.DOFade(1, 0.5f));
  139. seq2.AppendInterval(2);
  140. seq2.Append(text2.DOFade(0, 0.5f));
  141. return false;
  142. }
  143. void closeScaleShoot()
  144. {
  145. shootScaleValue = 1;
  146. if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
  147. }
  148. }