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