41 lines
968 B
C#
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
|
|
|
|
}
|
|
} |