using UnityEngine;

public class UIBase : MonoBehaviour
{
    public RectTransform rectTransform
    {
        get
        {
            if (_rectTransform == null) 
                _rectTransform = GetComponent<RectTransform>();
            return _rectTransform;
        }
    }
    RectTransform _rectTransform;
    public UIBase parent;
    public virtual void OnCreate() { }
    public virtual void OnShow() { }
    public virtual void OnHide() { }

    public void SetFull()
    {
        rectTransform.anchorMin = Vector2.zero;
        rectTransform.anchorMax = Vector2.one;
        rectTransform.offsetMin = Vector2.zero;
        rectTransform.offsetMax = Vector2.zero;
        rectTransform.sizeDelta = Vector2.zero;
    }

    public void SetParent(RectTransform ui, bool isFull = false)
    {
        rectTransform.SetParent(ui);
        rectTransform.localScale = Vector3.one;
        rectTransform.localPosition = Vector3.zero;
        rectTransform.localRotation = Quaternion.identity;
        if (isFull)
            SetFull();
    }
}
