Files
Cielonos/Assets/Scripts/MainGame/Base/SubmoduleBase.cs

44 lines
1.2 KiB
C#
Raw Normal View History

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