using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Cielonos.MainGame
{
///
/// 子控制器通用接口。
///
public interface ISubcontroller
{
T Owner { get; set; }
void Initialize();
}
public class SubcontrollerBase : SerializedMonoBehaviour, ISubcontroller where T : MonoBehaviour
{
[HideInEditorMode]
public T owner;
// 显式接口实现以满足 ISubcontroller 接口,保持原有 public 字段完整兼容性
T ISubcontroller.Owner
{
get => owner;
set => owner = value;
}
public virtual void Initialize()
{
owner ??= GetComponent() ?? GetComponentInParent();
}
#if UNITY_EDITOR
protected virtual void Reset()
{
owner ??= GetComponent() ?? GetComponentInParent();
}
#endif
}
}