using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; namespace TBTK{ #region UIObject [System.Serializable] public class UIObject{ public GameObject rootObj; [HideInInspector] public Transform rootT; [HideInInspector] public RectTransform rectT; [HideInInspector] public CanvasGroup canvasG; [HideInInspector] public Image image; [HideInInspector] public Text label; [HideInInspector] public UIItemCallback itemCallback; public UIObject(){} public UIObject(GameObject obj){ rootObj=obj; Init(); } public virtual void Init(){ if(rootObj==null){ Debug.LogWarning("Unassgined rootObj"); return; } rootT=rootObj.transform; rectT=rootObj.GetComponent(); foreach(Transform child in rectT){ if(child.name=="Image") image=child.GetComponent(); else if(child.name=="Text") label=child.GetComponent(); } } public static UIObject Clone(GameObject srcObj, string name="", Vector3 posOffset=default(Vector3)){ GameObject newObj=UI.Clone(srcObj, name, posOffset); return new UIObject(newObj); } public virtual void SetCallback(Callback enter=null, Callback exit=null){ itemCallback=rootObj.GetComponent(); if(itemCallback==null) itemCallback=rootObj.AddComponent(); itemCallback.SetEnterCallback(enter); itemCallback.SetExitCallback(exit); } public virtual void SetActive(bool flag){ rootObj.SetActive(flag); } public void SetImage1(bool flag){ if(image!=null) image.gameObject.SetActive(flag); } public void SetLabel1(bool flag){ if(label!=null) label.gameObject.SetActive(flag); } public void SetImage(Sprite spr){ if(image!=null) image.sprite=spr; } public void SetLabel(string txt){ if(label!=null) label.text=txt; } //not being used public void SetSound(AudioClip eClip, AudioClip dClip){ if(itemCallback!=null) itemCallback.SetSound(eClip, dClip); } public void DisableSound(bool disableHover, bool disablePress){ itemCallback.DisableSound(disableHover, disablePress); } } #endregion #region UIButton [System.Serializable] public class UIButton : UIObject{ [HideInInspector] public Text label2; [HideInInspector] public Image image2; [HideInInspector] public Image hovered; [HideInInspector] public Image disabled; [HideInInspector] public Image highlight; [HideInInspector] public Button button; public UIButton(){} public UIButton(GameObject obj){ rootObj=obj; Init(); } public override void Init(){ base.Init(); button=rootObj.GetComponent