using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// ??????
///
public class BasePanel : MonoBehaviour
{
///
/// ??????????п??
///
private readonly Dictionary> controlDic = new Dictionary>();
///
/// ????? ??????
///
protected virtual void Awake()
{
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
FindChildrenControl();
}
///
/// ?????????????
///
///
///
///
public T GetControl(string controlName) where T : UIBehaviour
{
if (controlDic.ContainsKey(controlName))
{
for (int i = 0; i < controlDic[controlName].Count; i++)
{
if (controlDic[controlName][i] is T)
return controlDic[controlName][i] as T;
}
}
return null;
}
///
/// ?????????????
///
///
private void FindChildrenControl() where T : UIBehaviour
{
T[] controls = GetComponentsInChildren(true);
for (int i = 0; i < controls.Length; i++)
{
string controlName = controls[i].gameObject.name;
if (controlDic.ContainsKey(controlName))
{
controlDic[controlName].Add(controls[i]);
}
else
{
controlDic.Add(controlName,new List() { controls[i] });
}
if (controls[i] is Button button)
{
button.onClick.AddListener(() =>
{
OnClick(controlName);
});
}
else if(controls[i] is Toggle toggle)
{
toggle.onValueChanged.AddListener((value) =>
{
OnChangeToggle(controlName,value);
});
}
else if (controls[i] is Slider slider)
{
slider.onValueChanged.AddListener((value) =>
{
OnChangeSlider(controlName, value);
});
}
else if (controls[i] is InputField inputField)
{
inputField.onValueChanged.AddListener((value) =>
{
OnChangeInputFile(controlName,value);
});
}
}
}
///
/// ??????
///
public virtual void ShowMe()
{
}
///
/// ???????
///
public virtual void HideMe()
{
}
///
/// ?????????
///
///
protected virtual void OnClick(string btnName)
{
}
///
/// Toogle???
///
/// toogle????
/// ???
protected virtual void OnChangeToggle(string toogleName,bool isOn)
{
}
///
/// Slider???
///
/// Slider???????
/// ???
protected virtual void OnChangeSlider(string SliderName, float value)
{
}
///
/// ?????????
///
/// ?????????
/// ?????????
protected virtual void OnChangeInputFile(string inputFileName,string value)
{
}
}