TimeLimitGameDistanceSelectView.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 限时模式的靶子距离选择界面 */
  6. public class TimeLimitGameDistanceSelectView : MonoBehaviour
  7. {
  8. void Awake()
  9. {
  10. SimulateMouseController.ins?.AddOpenLocker(this);
  11. }
  12. void Start()
  13. {
  14. GameMgr.ins.addLockerForGamePause(this);
  15. Transform layout = this.transform.Find("Layout");
  16. GameObject itemPrefab = layout.Find("Item").gameObject;
  17. for (int i = 1; i < TimeLimitGameMode.distanceCanSelected.Length; i++) {
  18. GameObject.Instantiate<GameObject>(
  19. itemPrefab, Vector3.zero, Quaternion.identity, this.transform.Find("Layout")
  20. );
  21. }
  22. for (int i = 0; i < TimeLimitGameMode.distanceCanSelected.Length; i++) {
  23. int distance = TimeLimitGameMode.distanceCanSelected[i];
  24. Transform item = layout.GetChild(i);
  25. item.transform.Find("Text").GetComponent<Text>().text = distance + "米";
  26. Button btn = item.gameObject.GetComponent<Button>();
  27. btn.onClick.AddListener(delegate() {
  28. AudioMgr.ins.PlayBtn();
  29. TimeLimitGameMode.distance = distance;
  30. ((TimeLimitGameMode) GameMgr.ins.gameMode).ConfirmSelectedTargetDistance();
  31. Destroy(this.gameObject);
  32. });
  33. }
  34. GameAssistUI.ins.copyButtonBack(this.transform);
  35. }
  36. void OnDestroy()
  37. {
  38. if (GameMgr.ins) GameMgr.ins.removeLockerForGamePause(this);
  39. SimulateMouseController.ins?.RemoveOpenLocker(this);
  40. }
  41. }