2025-07-08 10:46:31 +00:00
|
|
|
|
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<SLUIObjectOnOff>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bindParent = transform.GetComponentInParent<SLUIObjectOnOff>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|