55 lines
1.2 KiB
C#
55 lines
1.2 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class TgCheckGroup : MonoBehaviour
|
|||
|
{
|
|||
|
TgCheck[] checks;
|
|||
|
/// <summary>
|
|||
|
/// Ĭ<><C4AC>ѡ<EFBFBD><D1A1>
|
|||
|
/// </summary>
|
|||
|
public int select;
|
|||
|
|
|||
|
public Action<int> onValueChange;
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
checks = new TgCheck[transform.childCount];
|
|||
|
for (int i = 0; i < checks.Length; i++)
|
|||
|
{
|
|||
|
var check = transform.GetChild(i).GetComponent<TgCheck>();
|
|||
|
if (check == null)
|
|||
|
check = transform.GetChild(i).gameObject.AddComponent<TgCheck>();
|
|||
|
checks[i] = check;
|
|||
|
|
|||
|
check.index = i;
|
|||
|
UIEvent.Get(check.gameObject).onClick = (e) =>
|
|||
|
{
|
|||
|
SelectTg(check.index);
|
|||
|
onValueChange?.Invoke(check.index);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
SelectTg(select);
|
|||
|
}
|
|||
|
|
|||
|
public void SelectTg(int select)
|
|||
|
{
|
|||
|
this.select = select;
|
|||
|
for (int i = 0; i < checks.Length; i++)
|
|||
|
{
|
|||
|
var check = checks[i];
|
|||
|
if(check.index == select)
|
|||
|
check.Select();
|
|||
|
else
|
|||
|
check.UnSelect();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|