Files
Cielonos/Assets/Scripts/MainGame/Base/SubcontrollerBase.cs
SoulliesOfficial 7bc1e1722c 爆更
2026-06-05 04:21:00 -04:00

41 lines
968 B
C#

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