using UnityEngine;
using System.Collections;
using CommonDelegate;
[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(UIWidget))]
public class UITabEx : MonoBehaviour
{
[SerializeField]
private GameObject mNormal; // 未选中时,显示的gameobject
[SerializeField]
private GameObject mPressed; // 选中时,显示的gameobject
[SerializeField]
private bool mDefault = false;
public VoidDelegate OnClickHandler;
public void SetDefult(bool visible)
{
mDefault = visible;
}
void Start()
{
Set(mDefault);
}
void OnTab()
{
if (mPressed != null)
{
mPressed.SetActive(true);
}
if (mNormal != null)
{
mNormal.SetActive(false);
}
if (OnClickHandler != null)
{
OnClickHandler();
}
}
void UnTab()
{
if (mPressed != null)
{
mPressed.SetActive(false);
}
if (mNormal != null)
{
mNormal.SetActive(true);
}
}
public void OnClick()
{
Set(true);
}
void Set(bool state)
{
if (state)
{
if (transform.parent != null)
{
UITabEx[] tabs = transform.parent.GetComponentsInChildren<UITabEx>(true);
if (tabs == null || tabs.Length == 0)
{
return;
}
for (int i = 0; i < tabs.Length; ++i)
{
UITabEx tab = tabs[i];
tab.UnTab();
}
}
}
if (state)
OnTab();
}
void OnDestroy()
{
OnClickHandler = null;
}
}
UITabEx
最新推荐文章于 2022-02-07 16:29:17 发布