TimeLimitGameDistanceSelectView.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /* 限时模式的靶子距离选择界面 */
  7. public class TimeLimitGameDistanceSelectView : MonoBehaviour
  8. {
  9. public static TimeLimitGameDistanceSelectView ins;
  10. public Action action_OnClickSelectDistance;
  11. void Awake()
  12. {
  13. SimulateMouseController.ins?.AddOpenLocker(this);
  14. }
  15. void Start()
  16. {
  17. ins = this;
  18. GameMgr.ins.addLockerForGamePause(this);
  19. Transform layout = this.transform.Find("Layout");
  20. GameObject itemPrefab = layout.Find("Item").gameObject;
  21. for (int i = 1; i < TimeLimitGameMode.distanceCanSelected.Length; i++) {
  22. Instantiate(
  23. itemPrefab, Vector3.zero, Quaternion.identity, this.transform.Find("Layout")
  24. );
  25. }
  26. for (int i = 0; i < TimeLimitGameMode.distanceCanSelected.Length; i++) {
  27. int distance = TimeLimitGameMode.distanceCanSelected[i];
  28. Transform item = layout.GetChild(i);
  29. var tal = item.transform.Find("Text").GetComponent<TextAutoLanguage2>();
  30. tal.textFormatArgs = new object[]{distance};
  31. tal.ApplyToText();
  32. Button btn = item.gameObject.GetComponent<Button>();
  33. GetComponentInParent<KeyBoardNavigation>()?.buttons.Add(btn);
  34. btn.onClick.AddListener(delegate() {
  35. AudioMgr.ins.PlayBtn();
  36. TimeLimitGameMode.distance = distance;
  37. ((TimeLimitGameMode) GameMgr.ins.gameMode).ConfirmSelectedTargetDistance();
  38. Destroy(this.gameObject);
  39. action_OnClickSelectDistance?.Invoke();
  40. });
  41. }
  42. }
  43. void OnDestroy()
  44. {
  45. if (ins == this) ins = null;
  46. if (GameMgr.ins) GameMgr.ins.removeLockerForGamePause(this);
  47. SimulateMouseController.ins?.RemoveOpenLocker(this);
  48. }
  49. public void OnClick_Back()
  50. {
  51. GameAssistUI.ins.onBtnBack();
  52. }
  53. }