UPF/Assets/Game/Scripts/TabUI.cs
2023-02-24 22:14:55 +05:30

42 lines
1.1 KiB
C#
Executable File

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TabUI : MonoBehaviour
{
public TabUIElement[] elements;
// Start is called before the first frame update
void Start()
{
for(int i =0; i < elements.Length; i++){
int index = i;
elements[i].tabElement.GetComponent<Button>().onClick.AddListener(()=>{SelectItem(index);});
}
SelectItem(0);
}
public void SelectItem(int index){
for(int i=0; i< elements.Length; i++){
SetElementFocus(elements[i],i == index);
}
}
void SetElementFocus(TabUIElement element, bool value){
element.tabElement.GetComponentInChildren<TMP_Text>().color = value ? Color.white : new Color(74f/250f,172f/250f,247f/250f);
element.tabElement.transform.GetChild(1).gameObject.SetActive(value);
element.panel.SetActive(value);
}
}
[System.Serializable]
public class TabUIElement{
public GameObject tabElement;
public GameObject panel;
}