GameAssistUI.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. /* 游戏帮助界面(右侧方的辅助功能) */
  8. public class GameAssistUI : MonoBehaviour
  9. {
  10. [SerializeField] Material outlight;
  11. [SerializeField] Text text1;
  12. [SerializeField] Text text2;
  13. public static GameAssistUI ins;
  14. void Awake() {
  15. ins = this;
  16. }
  17. void Start()
  18. {
  19. this.transform.Find("Button0").GetComponent<Button>().onClick.AddListener(delegate(){
  20. AudioMgr.ins.PlayBtn();
  21. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  22. });
  23. this.transform.Find("Button1").GetComponent<Button>().onClick.AddListener(delegate(){
  24. AudioMgr.ins.PlayBtn();
  25. GameRuleView.Create();
  26. });
  27. Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
  28. btnScaleAim.onClick.AddListener(delegate(){
  29. AudioMgr.ins.PlayBtn();
  30. if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
  31. btnScaleAim.GetComponentInChildren<Image>().material = null;
  32. closeScaleAim();
  33. } else {
  34. if (openScaleAim()) {
  35. btnScaleAim.GetComponentInChildren<Image>().material = outlight;
  36. }
  37. }
  38. });
  39. Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
  40. btnScaleShoot.onClick.AddListener(delegate(){
  41. AudioMgr.ins.PlayBtn();
  42. if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
  43. btnScaleShoot.GetComponentInChildren<Image>().material = null;
  44. closeScaleShoot();
  45. } else {
  46. if (openScaleShoot()) {
  47. btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
  48. }
  49. }
  50. });
  51. Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
  52. btnIdentity.onClick.AddListener(delegate(){
  53. AudioMgr.ins.PlayBtn();
  54. AimHandler.ins.DoIdentity();
  55. });
  56. // ------ 查看靶子 ------
  57. Transform targetView = this.transform.Find("TargetView");
  58. Button btnViewTarget = this.transform.Find("Button10").GetComponent<Button>();
  59. btnViewTarget.onClick.AddListener(delegate(){
  60. AudioMgr.ins.PlayBtn();
  61. TargetView.ins.ReverseActive();
  62. });
  63. if (GameMgr.gameType == 2) {
  64. targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
  65. btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
  66. }
  67. //看看是不是双人游戏的再次对战
  68. applyPlayerRecordsWhenGameTryAgain();
  69. }
  70. // ------ 开镜瞄准功能 ------
  71. Transform scope = null;
  72. float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
  73. float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  74. Sequence seq1 = null;
  75. bool scaleAimOn = false; //该功能是否处于打开状态
  76. bool openScaleAim()
  77. {
  78. int scaleValue = GetPropScaleAimValue();
  79. if (scaleValue > 0)
  80. {
  81. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  82. bowCamera.banCameraFieldOfView = true;
  83. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  84. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  85. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  86. localPosition.z = -2;
  87. ArmBow.ins.transform.localPosition = localPosition;
  88. scope = bowCamera.transform.Find("Scope");
  89. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  90. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  91. scaleAimOn = true;
  92. onOpenScaleAimSuccess();
  93. return true;
  94. }
  95. if (seq1 != null && !seq1.IsComplete()) {
  96. seq1.Complete();
  97. }
  98. seq1 = DOTween.Sequence();
  99. seq1.Append(text1.DOFade(1, 0.5f));
  100. seq1.AppendInterval(2);
  101. seq1.Append(text1.DOFade(0, 0.5f));
  102. return false;
  103. }
  104. void closeScaleAim()
  105. {
  106. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  107. bowCamera.banCameraFieldOfView = false;
  108. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  109. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  110. localPosition.z = -0.1f;
  111. ArmBow.ins.transform.localPosition = localPosition;
  112. scope.localScale = new Vector3(0, 0, 0);
  113. scope = null;
  114. scaleAimOn = false;
  115. onCloseScaleAimSuccess();
  116. }
  117. int GetPropScaleAimValue()
  118. {
  119. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  120. foreach (var prop in props)
  121. {
  122. if (prop.config.type == 1) {
  123. PropScaleAim config = prop.config as PropScaleAim;
  124. return config.scaleValue;
  125. }
  126. }
  127. return 0;
  128. }
  129. // ------ 发射加速功能 ------
  130. public int shootScaleValue = 1;
  131. Sequence seq2 = null;
  132. bool scaleShootOn = false; //该功能是否处于打开状态
  133. bool openScaleShoot()
  134. {
  135. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  136. foreach (var prop in props)
  137. {
  138. if (prop.config.type == 2) {
  139. PropScaleShoot config = prop.config as PropScaleShoot;
  140. shootScaleValue = config.scaleValue;
  141. if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
  142. scaleShootOn = true;
  143. onOpenScaleShootSuccess();
  144. return true;
  145. }
  146. }
  147. if (seq2 != null && !seq2.IsComplete()) {
  148. seq2.Complete();
  149. }
  150. seq2 = DOTween.Sequence();
  151. seq2.Append(text2.DOFade(1, 0.5f));
  152. seq2.AppendInterval(2);
  153. seq2.Append(text2.DOFade(0, 0.5f));
  154. return false;
  155. }
  156. void closeScaleShoot()
  157. {
  158. shootScaleValue = 1;
  159. if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
  160. scaleShootOn = false;
  161. onCloseScaleShootSuccess();
  162. }
  163. //------ 以下给双人模式分别记录提供的接口 ------
  164. //两位玩家的开镜情况
  165. bool[] playerScaleAimRecords = {false, false};
  166. //两位玩家的加速情况
  167. bool[] playerScaleShootRecords = {false, false};
  168. private void onOpenScaleAimSuccess() {
  169. if (GameMgr.gameType == 2) {
  170. playerScaleAimRecords[getPlayerIndex()] = true;
  171. }
  172. }
  173. private void onCloseScaleAimSuccess() {
  174. if (GameMgr.gameType == 2) {
  175. playerScaleAimRecords[getPlayerIndex()] = false;
  176. }
  177. }
  178. private void onOpenScaleShootSuccess() {
  179. if (GameMgr.gameType == 2) {
  180. playerScaleShootRecords[getPlayerIndex()] = true;
  181. }
  182. }
  183. private void onCloseScaleShootSuccess() {
  184. if (GameMgr.gameType == 2) {
  185. playerScaleShootRecords[getPlayerIndex()] = false;
  186. }
  187. }
  188. private int getPlayerIndex() {
  189. return ((PKGameMode) GameMgr.ins.gameMode).currentPlayerIndex;
  190. }
  191. private void updateFunctionByPlayerRecords() {
  192. if (GameMgr.gameType != 2) return;
  193. int playerIndex = getPlayerIndex();
  194. if (scaleAimOn != playerScaleAimRecords[playerIndex]) {
  195. Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
  196. if (playerScaleAimRecords[playerIndex]) {
  197. if (openScaleAim()) {
  198. btnScaleAim.GetComponentInChildren<Image>().material = outlight;
  199. }
  200. } else {
  201. btnScaleAim.GetComponentInChildren<Image>().material = null;
  202. closeScaleAim();
  203. }
  204. }
  205. if (scaleShootOn != playerScaleShootRecords[playerIndex]) {
  206. Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
  207. if (playerScaleShootRecords[playerIndex]) {
  208. if (openScaleShoot()) {
  209. btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
  210. }
  211. } else {
  212. btnScaleShoot.GetComponentInChildren<Image>().material = null;
  213. closeScaleShoot();
  214. }
  215. }
  216. }
  217. private static bool[] playerRecords = null;
  218. public void recordPlayerRecordsWhenGameTryAgain() {
  219. if (GameMgr.gameType != 2) return;
  220. playerRecords = new bool[] {
  221. playerScaleAimRecords[0], playerScaleAimRecords[1],
  222. playerScaleShootRecords[0], playerScaleShootRecords[1]
  223. };
  224. }
  225. private void applyPlayerRecordsWhenGameTryAgain() {
  226. if (playerRecords != null) {
  227. playerScaleAimRecords[0] = playerRecords[0];
  228. playerScaleAimRecords[1] = playerRecords[1];
  229. playerScaleShootRecords[0] = playerRecords[2];
  230. playerScaleShootRecords[1] = playerRecords[3];
  231. playerRecords = null;
  232. }
  233. }
  234. void Update() {
  235. updateFunctionByPlayerRecords();
  236. }
  237. }