using System; using UnityEngine; namespace Superlazy.UI { public abstract class SLUIComponent : MonoBehaviour { private bool init; [NonSerialized] public SLUIObjectOnOff bindParent; private void OnValidate() { SetBindParent(); Validate(); } private void SetBindParent() { if (this is SLUIObjectOnOff) { if (transform.parent != null) { bindParent = transform.parent.GetComponentInParent(); } } else { bindParent = transform.GetComponentInParent(); } } private void Awake() { OnInit(); } protected void OnInit() { if (init) return; SetBindParent(); bindParent?.OnInit(); Validate(); Init(); init = true; } private void OnEnable() { if (init == false) return; Enable(); } private void OnDisable() { if (init == false) return; Disable(); } protected abstract void Validate(); protected abstract void Init(); protected abstract void Enable(); protected abstract void Disable(); } }