44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame
|
||
{
|
||
/// <remarks>
|
||
/// Submodule 是普通 C# 逻辑对象,不是 Unity Component。
|
||
/// Submodule 可以作为 owner class 的 nested class,用类型层级表达归属关系。
|
||
/// Submodule 不允许继承 MonoBehaviour / SerializedMonoBehaviour,也不应直接挂载到 GameObject。
|
||
/// 需要 Unity 生命周期、Inspector 组件绑定或 prefab/scene script 引用的逻辑,应使用顶层 Subcontroller。
|
||
/// </remarks>
|
||
/// <summary>
|
||
/// 子模块通用接口。允许子模块通过继承其他类(如动作播放器)来避免单继承限制。
|
||
/// </summary>
|
||
public interface ISubmodule<T>
|
||
{
|
||
T Owner { get; set; }
|
||
}
|
||
|
||
public class SubmoduleBase<T> : ISubmodule<T>
|
||
{
|
||
[HideInInspector]
|
||
protected T owner;
|
||
|
||
public T Owner => owner;
|
||
|
||
T ISubmodule<T>.Owner
|
||
{
|
||
get => Owner;
|
||
set => owner = value;
|
||
}
|
||
|
||
public SubmoduleBase(T owner)
|
||
{
|
||
this.owner = owner;
|
||
}
|
||
|
||
public void SetOwner(T newOwner)
|
||
{
|
||
this.owner = newOwner;
|
||
}
|
||
}
|
||
}
|