| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- public class DistanceSelectView : MonoBehaviour
- {
- static int[] distanceCanSelected = { 10, 20, 30, 50, 70 }; // { 6, 8, 10, 15, 20 };
- public Action<float> OnClickSelectDistance;
- void OnEnable()
- {
- SimulateMouseController.ins?.AddOpenLocker(this);
- Time.timeScale = 0;
- }
- void Start()
- {
-
- Transform layout = transform.Find("Layout");
- GameObject itemPrefab = layout.Find("Item").gameObject;
- for (int i = 1; i < distanceCanSelected.Length; i++)
- {
- Instantiate(
- itemPrefab, Vector3.zero, Quaternion.identity, transform.Find("Layout")
- );
- }
- for (int i = 0; i < distanceCanSelected.Length; i++)
- {
- int distance = distanceCanSelected[i];
- Transform item = layout.GetChild(i);
- var tal = item.transform.Find("Text").GetComponent<TextAutoLanguage2>();
- tal.textFormatArgs = new object[] { distance };
- tal.ApplyToText();
- Button btn = item.gameObject.GetComponent<Button>();
- GetComponentInParent<KeyBoardNavigation>()?.buttons.Add(btn);
- btn.onClick.AddListener(delegate () {
- AudioMgr.ins.PlayBtn();
- OnClickSelectDistance?.Invoke(distance);
- });
- }
- }
- void OnDisable()
- {
- SimulateMouseController.ins?.RemoveOpenLocker(this);
- Time.timeScale = 1;
- }
- private void OnDestroy()
- {
- Time.timeScale = 1;
- }
- }
|