框架上传
This commit is contained in:
34
Assets/00.StaryEvo/Runtime/Design/ICommand.cs
Normal file
34
Assets/00.StaryEvo/Runtime/Design/ICommand.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface ICommand : IBelongToArchitecture,ICanSetArchitecture,ICanGetSystem,ICanGetData,ICanGetUtility,ICanSendCommand,ICanSendEvent, ICanSendQuery
|
||||
{
|
||||
void Execute();
|
||||
}
|
||||
|
||||
public abstract class AbstractCommand : ICommand
|
||||
{
|
||||
private IArchitecture mArchitecture;
|
||||
|
||||
IArchitecture IBelongToArchitecture.GetArchitecture()
|
||||
{
|
||||
return mArchitecture;
|
||||
}
|
||||
|
||||
void ICanSetArchitecture.SetArchitecture(IArchitecture architecture)
|
||||
{
|
||||
mArchitecture = architecture;
|
||||
|
||||
}
|
||||
|
||||
void ICommand.Execute()
|
||||
{
|
||||
OnExecute();
|
||||
}
|
||||
|
||||
protected abstract void OnExecute();
|
||||
}
|
||||
}
|
||||
11
Assets/00.StaryEvo/Runtime/Design/ICommand.cs.meta
Normal file
11
Assets/00.StaryEvo/Runtime/Design/ICommand.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 501ba9abd3ae8344c8f30f3d4a18b34b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Assets/00.StaryEvo/Runtime/Design/IController.cs
Normal file
7
Assets/00.StaryEvo/Runtime/Design/IController.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface IController:IBelongToArchitecture,ICanGetSystem,ICanGetData,ICanSendCommand,ICanRegisterEvent,ICanSendQuery, ICanGetUtility
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/00.StaryEvo/Runtime/Design/IController.cs.meta
Normal file
3
Assets/00.StaryEvo/Runtime/Design/IController.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 485e552656f54b618a85271943a76c3d
|
||||
timeCreated: 1625018098
|
||||
34
Assets/00.StaryEvo/Runtime/Design/IData.cs
Normal file
34
Assets/00.StaryEvo/Runtime/Design/IData.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface IData: IBelongToArchitecture,ICanSetArchitecture,ICanGetUtility ,ICanSendEvent
|
||||
{
|
||||
void Init();
|
||||
void Dispose();
|
||||
}
|
||||
|
||||
public abstract class AbstractData : IData
|
||||
{
|
||||
private IArchitecture mArchitecture;
|
||||
//接口阉割,子类重写无法用子类调用
|
||||
IArchitecture IBelongToArchitecture.GetArchitecture()
|
||||
{
|
||||
return mArchitecture;
|
||||
}
|
||||
|
||||
void ICanSetArchitecture.SetArchitecture(IArchitecture architecture)
|
||||
{
|
||||
mArchitecture = architecture;
|
||||
}
|
||||
|
||||
void IData.Init()
|
||||
{
|
||||
OnInit();
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
//数据初始化
|
||||
protected abstract void OnInit();
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/00.StaryEvo/Runtime/Design/IData.cs.meta
Normal file
3
Assets/00.StaryEvo/Runtime/Design/IData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2138d8e4edea4564b328a71f45aadfd7
|
||||
timeCreated: 1624937508
|
||||
29
Assets/00.StaryEvo/Runtime/Design/IQuery.cs
Normal file
29
Assets/00.StaryEvo/Runtime/Design/IQuery.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface IQuery<TResult> : IBelongToArchitecture,ICanSetArchitecture,ICanGetData,ICanGetSystem,ICanGetUtility
|
||||
{
|
||||
TResult Do();
|
||||
}
|
||||
|
||||
public abstract class AbstractQuery<T> : IQuery<T>
|
||||
{
|
||||
public T Do()
|
||||
{
|
||||
return OnDo();
|
||||
}
|
||||
|
||||
protected abstract T OnDo();
|
||||
|
||||
private IArchitecture mArchitecture;
|
||||
|
||||
IArchitecture IBelongToArchitecture.GetArchitecture()
|
||||
{
|
||||
return mArchitecture;
|
||||
}
|
||||
|
||||
void ICanSetArchitecture.SetArchitecture(IArchitecture architecture)
|
||||
{
|
||||
mArchitecture = architecture;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/00.StaryEvo/Runtime/Design/IQuery.cs.meta
Normal file
11
Assets/00.StaryEvo/Runtime/Design/IQuery.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4fd5f513a09f6f47b1b0a27a2f0500e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/00.StaryEvo/Runtime/Design/ISystem.cs
Normal file
30
Assets/00.StaryEvo/Runtime/Design/ISystem.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface ISystem: IBelongToArchitecture,ICanSetArchitecture,ICanGetData,ICanGetUtility ,ICanRegisterEvent,ICanSendEvent,ICanGetSystem
|
||||
{
|
||||
void Init();
|
||||
void Dispose();
|
||||
}
|
||||
public abstract class AbstractSystem : ISystem
|
||||
{
|
||||
private IArchitecture mArchitecture;
|
||||
IArchitecture IBelongToArchitecture.GetArchitecture()
|
||||
{
|
||||
return mArchitecture;
|
||||
}
|
||||
|
||||
void ICanSetArchitecture.SetArchitecture(IArchitecture architecture)
|
||||
{
|
||||
mArchitecture = architecture;
|
||||
}
|
||||
|
||||
void ISystem.Init()
|
||||
{
|
||||
OnInit();
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
protected abstract void OnInit();
|
||||
}
|
||||
}
|
||||
3
Assets/00.StaryEvo/Runtime/Design/ISystem.cs.meta
Normal file
3
Assets/00.StaryEvo/Runtime/Design/ISystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 187938c258244d9ea6e81a5948033cf8
|
||||
timeCreated: 1624954926
|
||||
7
Assets/00.StaryEvo/Runtime/Design/IUtility.cs
Normal file
7
Assets/00.StaryEvo/Runtime/Design/IUtility.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface IUtility
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/00.StaryEvo/Runtime/Design/IUtility.cs.meta
Normal file
3
Assets/00.StaryEvo/Runtime/Design/IUtility.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55d0b44b52f841d4af6f7ebc0cad1abe
|
||||
timeCreated: 1625038442
|
||||
111
Assets/00.StaryEvo/Runtime/Design/UnRegisterOnDestroyTrigger.cs
Normal file
111
Assets/00.StaryEvo/Runtime/Design/UnRegisterOnDestroyTrigger.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 用于注销的接口(为了防止注册后忘记注销特实现此接口)
|
||||
/// </summary>
|
||||
public interface IUnRegister
|
||||
{
|
||||
void UnRegister();
|
||||
}
|
||||
public interface IUnRegisterList
|
||||
{
|
||||
List<IUnRegister> UnregisterList { get; }
|
||||
}
|
||||
public static class IUnRegisterListExtension
|
||||
{
|
||||
public static void AddToUnregisterList(this IUnRegister self, IUnRegisterList unRegisterList)
|
||||
{
|
||||
unRegisterList.UnregisterList.Add(self);
|
||||
}
|
||||
|
||||
public static void UnRegisterAll(this IUnRegisterList self)
|
||||
{
|
||||
foreach (var unRegister in self.UnregisterList)
|
||||
{
|
||||
unRegister.UnRegister();
|
||||
}
|
||||
|
||||
self.UnregisterList.Clear();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 自定义可注销的类
|
||||
/// </summary>
|
||||
public struct CustomUnRegister : IUnRegister
|
||||
{
|
||||
/// <summary>
|
||||
/// 委托对象
|
||||
/// </summary>
|
||||
private Action mOnUnRegister { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 带参构造函数
|
||||
/// </summary>
|
||||
/// <param name="onDispose"></param>
|
||||
public CustomUnRegister(Action onUnRegsiter)
|
||||
{
|
||||
mOnUnRegister = onUnRegsiter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源释放
|
||||
/// </summary>
|
||||
public void UnRegister()
|
||||
{
|
||||
mOnUnRegister.Invoke();
|
||||
mOnUnRegister = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 注销的触发器
|
||||
/// </summary>
|
||||
public class UnRegisterOnDestroyTrigger : MonoBehaviour
|
||||
{
|
||||
private HashSet<IUnRegister> mUnRegisters = new HashSet<IUnRegister>();
|
||||
|
||||
public void AddUnRegister(IUnRegister unRegister)
|
||||
{
|
||||
mUnRegisters.Add(unRegister);
|
||||
}
|
||||
public void RemoveUnRegister(IUnRegister unRegister)
|
||||
{
|
||||
mUnRegisters.Remove(unRegister);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var unRegister in mUnRegisters)
|
||||
{
|
||||
unRegister.UnRegister();
|
||||
}
|
||||
|
||||
mUnRegisters.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注销触发器的使用简化
|
||||
/// </summary>
|
||||
public static class UnRegisterExtension
|
||||
{
|
||||
public static IUnRegister UnRegisterWhenGameObjectDestroyed(this IUnRegister unRegister, GameObject gameObject)
|
||||
{
|
||||
var trigger = gameObject.GetComponent<UnRegisterOnDestroyTrigger>()??null;
|
||||
|
||||
if (!trigger)
|
||||
{
|
||||
trigger = gameObject.AddComponent<UnRegisterOnDestroyTrigger>();
|
||||
}
|
||||
|
||||
trigger.AddUnRegister(unRegister);
|
||||
|
||||
return unRegister;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81fe5c4dfa304c2ab19ebf1cc876813e
|
||||
timeCreated: 1730381395
|
||||
Reference in New Issue
Block a user