ProjectDDD/Packages/SLUnity/SLUI/SLUIComponent.cs
2025-06-25 11:33:17 +09:00

72 lines
1.4 KiB (Stored with Git LFS)
C#

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();
}
}