初步提交
This commit is contained in:
parent
3eef938035
commit
e03acb15b4
50
AkiraPixelWind.sln
Normal file
50
AkiraPixelWind.sln
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axibug", "Axibug.csproj", "{1C6A6544-CF52-D2FA-C49F-74768676B988}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game.csproj", "{1E25715C-CDA3-48CD-B962-7142A7C4E9DE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axibug.Runtime", "Axibug.Runtime.csproj", "{88C9498B-28D5-9BC2-A070-28EA094BD304}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Axibug.Editor", "Axibug.Editor.csproj", "{627D77F4-C9BE-84D3-DB10-6046CB23071E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.AssetBundleBrowser.Editor", "Unity.AssetBundleBrowser.Editor.csproj", "{ABF204EF-1E2E-8CB2-72AF-91D7308875CD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game.Editor", "Game.Editor.csproj", "{98FBFC68-818B-0A9E-7472-D409D606C424}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1C6A6544-CF52-D2FA-C49F-74768676B988}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1C6A6544-CF52-D2FA-C49F-74768676B988}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1C6A6544-CF52-D2FA-C49F-74768676B988}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C6A6544-CF52-D2FA-C49F-74768676B988}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1E25715C-CDA3-48CD-B962-7142A7C4E9DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1E25715C-CDA3-48CD-B962-7142A7C4E9DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E25715C-CDA3-48CD-B962-7142A7C4E9DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E25715C-CDA3-48CD-B962-7142A7C4E9DE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{88C9498B-28D5-9BC2-A070-28EA094BD304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{88C9498B-28D5-9BC2-A070-28EA094BD304}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{88C9498B-28D5-9BC2-A070-28EA094BD304}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{88C9498B-28D5-9BC2-A070-28EA094BD304}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{627D77F4-C9BE-84D3-DB10-6046CB23071E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{627D77F4-C9BE-84D3-DB10-6046CB23071E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{627D77F4-C9BE-84D3-DB10-6046CB23071E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{627D77F4-C9BE-84D3-DB10-6046CB23071E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ABF204EF-1E2E-8CB2-72AF-91D7308875CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ABF204EF-1E2E-8CB2-72AF-91D7308875CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ABF204EF-1E2E-8CB2-72AF-91D7308875CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ABF204EF-1E2E-8CB2-72AF-91D7308875CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{98FBFC68-818B-0A9E-7472-D409D606C424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98FBFC68-818B-0A9E-7472-D409D606C424}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98FBFC68-818B-0A9E-7472-D409D606C424}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98FBFC68-818B-0A9E-7472-D409D606C424}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
8
Assets/Axibug.meta
Normal file
8
Assets/Axibug.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 096d23cae991fe645957ec9d22f4c42c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Axibug/Axibug.asmdef
Normal file
14
Assets/Axibug/Axibug.asmdef
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Axibug",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Assets/Axibug/Axibug.asmdef.meta
Normal file
7
Assets/Axibug/Axibug.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d85a50318bec6aa43ab22f7db3ba8024
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1061
Assets/Axibug/Axibug.prefab
Normal file
1061
Assets/Axibug/Axibug.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Axibug/Axibug.prefab.meta
Normal file
7
Assets/Axibug/Axibug.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2b00befcb5658541b1e5a6850840fd3
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries.meta
Normal file
8
Assets/Axibug/Libraries.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aeb38ed996a64384b957407fadf92ff8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug.meta
Normal file
8
Assets/Axibug/Libraries/Axibug.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5bd79da59cc66a4d871ad5e0fbb09e0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ff32d4413a6d3b43b7fade872da24ac
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/DataStruct.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/DataStruct.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbc5e4ad3c8e8044aa6801a773d92e1d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
128
Assets/Axibug/Libraries/Axibug/Base/DataStruct/TypeNamePair.cs
Normal file
128
Assets/Axibug/Libraries/Axibug/Base/DataStruct/TypeNamePair.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型和名称的组合值。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
internal struct TypeNamePair : IEquatable<TypeNamePair>
|
||||
{
|
||||
private readonly Type m_Type;
|
||||
private readonly string m_Name;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化类型和名称的组合值的新实例。
|
||||
/// </summary>
|
||||
/// <param name="type">类型。</param>
|
||||
public TypeNamePair(Type type)
|
||||
: this(type, string.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化类型和名称的组合值的新实例。
|
||||
/// </summary>
|
||||
/// <param name="type">类型。</param>
|
||||
/// <param name="name">名称。</param>
|
||||
public TypeNamePair(Type type, string name)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new GameException("Type is invalid.");
|
||||
}
|
||||
|
||||
m_Type = type;
|
||||
m_Name = name ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取类型。
|
||||
/// </summary>
|
||||
public Type Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取名称。
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取类型和名称的组合值字符串。
|
||||
/// </summary>
|
||||
/// <returns>类型和名称的组合值字符串。</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
if (m_Type == null)
|
||||
{
|
||||
throw new GameException("Type is invalid.");
|
||||
}
|
||||
|
||||
string typeName = m_Type.FullName;
|
||||
return string.IsNullOrEmpty(m_Name) ? typeName : Utility.Text.Format("{0}.{1}", typeName, m_Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取对象的哈希值。
|
||||
/// </summary>
|
||||
/// <returns>对象的哈希值。</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_Type.GetHashCode() ^ m_Name.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 比较对象是否与自身相等。
|
||||
/// </summary>
|
||||
/// <param name="obj">要比较的对象。</param>
|
||||
/// <returns>被比较的对象是否与自身相等。</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is TypeNamePair && Equals((TypeNamePair)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 比较对象是否与自身相等。
|
||||
/// </summary>
|
||||
/// <param name="value">要比较的对象。</param>
|
||||
/// <returns>被比较的对象是否与自身相等。</returns>
|
||||
public bool Equals(TypeNamePair value)
|
||||
{
|
||||
return m_Type == value.m_Type && m_Name == value.m_Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个对象是否相等。
|
||||
/// </summary>
|
||||
/// <param name="a">值 a。</param>
|
||||
/// <param name="b">值 b。</param>
|
||||
/// <returns>两个对象是否相等。</returns>
|
||||
public static bool operator ==(TypeNamePair a, TypeNamePair b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个对象是否不相等。
|
||||
/// </summary>
|
||||
/// <param name="a">值 a。</param>
|
||||
/// <param name="b">值 b。</param>
|
||||
/// <returns>两个对象是否不相等。</returns>
|
||||
public static bool operator !=(TypeNamePair a, TypeNamePair b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f54e79c7318be544a8ef0a6df8bb7d4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/EventPool.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/EventPool.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80a6209ec21b02243a1d968bee8f4ef6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件基类。
|
||||
/// </summary>
|
||||
public abstract class BaseEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取类型编号。
|
||||
/// </summary>
|
||||
public abstract int Id
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2bb7b5749660084abe94c6416d4057e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,50 @@
|
||||
namespace Axibug
|
||||
{
|
||||
internal sealed partial class EventPool<T> where T : BaseEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件结点。
|
||||
/// </summary>
|
||||
private sealed class Event : IReference
|
||||
{
|
||||
private object m_Sender;
|
||||
private T m_EventArgs;
|
||||
|
||||
public Event()
|
||||
{
|
||||
m_Sender = null;
|
||||
m_EventArgs = null;
|
||||
}
|
||||
|
||||
public object Sender
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Sender;
|
||||
}
|
||||
}
|
||||
|
||||
public T LogicEventArgs
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EventArgs;
|
||||
}
|
||||
}
|
||||
|
||||
public static Event Create(object sender, T e)
|
||||
{
|
||||
Event eventNode = ReferencePool.Acquire<Event>();
|
||||
eventNode.m_Sender = sender;
|
||||
eventNode.m_EventArgs = e;
|
||||
return eventNode;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Sender = null;
|
||||
m_EventArgs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51212960beaee9546838b2c17233caeb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
278
Assets/Axibug/Libraries/Axibug/Base/EventPool/EventPool.cs
Normal file
278
Assets/Axibug/Libraries/Axibug/Base/EventPool/EventPool.cs
Normal file
@ -0,0 +1,278 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件池。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">事件类型。</typeparam>
|
||||
internal sealed partial class EventPool<T> where T : BaseEventArgs
|
||||
{
|
||||
private readonly GameMultiDictionary<int, EventHandler<T>> m_EventHandlers;
|
||||
private readonly Queue<Event> m_Events;
|
||||
private readonly Dictionary<object, LinkedListNode<EventHandler<T>>> m_CachedNodes;
|
||||
private readonly Dictionary<object, LinkedListNode<EventHandler<T>>> m_TempNodes;
|
||||
private readonly EventPoolMode m_EventPoolMode;
|
||||
private EventHandler<T> m_DefaultHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化事件池的新实例。
|
||||
/// </summary>
|
||||
/// <param name="mode">事件池模式。</param>
|
||||
public EventPool(EventPoolMode mode)
|
||||
{
|
||||
m_EventHandlers = new GameMultiDictionary<int, EventHandler<T>>();
|
||||
m_Events = new Queue<Event>();
|
||||
m_CachedNodes = new Dictionary<object, LinkedListNode<EventHandler<T>>>();
|
||||
m_TempNodes = new Dictionary<object, LinkedListNode<EventHandler<T>>>();
|
||||
m_EventPoolMode = mode;
|
||||
m_DefaultHandler = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
public int EventHandlerCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EventHandlers.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件数量。
|
||||
/// </summary>
|
||||
public int EventCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Events.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件池轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
lock (m_Events)
|
||||
{
|
||||
while (m_Events.Count > 0)
|
||||
{
|
||||
Event eventNode = m_Events.Dequeue();
|
||||
HandleEvent(eventNode.Sender, eventNode.LogicEventArgs);
|
||||
ReferencePool.Release(eventNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理事件池。
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
Clear();
|
||||
m_EventHandlers.Clear();
|
||||
m_CachedNodes.Clear();
|
||||
m_TempNodes.Clear();
|
||||
m_DefaultHandler = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理事件。
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
lock (m_Events)
|
||||
{
|
||||
m_Events.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <returns>事件处理函数的数量。</returns>
|
||||
public int Count(int id)
|
||||
{
|
||||
GameLinkedListRange<EventHandler<T>> range = default(GameLinkedListRange<EventHandler<T>>);
|
||||
if (m_EventHandlers.TryGetValue(id, out range))
|
||||
{
|
||||
return range.Count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要检查的事件处理函数。</param>
|
||||
/// <returns>是否存在事件处理函数。</returns>
|
||||
public bool Check(int id, EventHandler<T> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
throw new GameException("Event handler is invalid.");
|
||||
}
|
||||
|
||||
return m_EventHandlers.Contains(id, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要订阅的事件处理函数。</param>
|
||||
public void Subscribe(int id, EventHandler<T> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
throw new GameException("Event handler is invalid.");
|
||||
}
|
||||
|
||||
if (!m_EventHandlers.Contains(id))
|
||||
{
|
||||
m_EventHandlers.Add(id, handler);
|
||||
}
|
||||
else if ((m_EventPoolMode & EventPoolMode.AllowMultiHandler) != EventPoolMode.AllowMultiHandler)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Event '{0}' not allow multi handler.", id));
|
||||
}
|
||||
else if ((m_EventPoolMode & EventPoolMode.AllowDuplicateHandler) != EventPoolMode.AllowDuplicateHandler && Check(id, handler))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Event '{0}' not allow duplicate handler.", id));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_EventHandlers.Add(id, handler);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要取消订阅的事件处理函数。</param>
|
||||
public void Unsubscribe(int id, EventHandler<T> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
throw new GameException("Event handler is invalid.");
|
||||
}
|
||||
|
||||
if (m_CachedNodes.Count > 0)
|
||||
{
|
||||
foreach (KeyValuePair<object, LinkedListNode<EventHandler<T>>> cachedNode in m_CachedNodes)
|
||||
{
|
||||
if (cachedNode.Value != null && cachedNode.Value.Value == handler)
|
||||
{
|
||||
m_TempNodes.Add(cachedNode.Key, cachedNode.Value.Next);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_TempNodes.Count > 0)
|
||||
{
|
||||
foreach (KeyValuePair<object, LinkedListNode<EventHandler<T>>> cachedNode in m_TempNodes)
|
||||
{
|
||||
m_CachedNodes[cachedNode.Key] = cachedNode.Value;
|
||||
}
|
||||
|
||||
m_TempNodes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_EventHandlers.Remove(id, handler))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Event '{0}' not exists specified handler.", id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="handler">要设置的默认事件处理函数。</param>
|
||||
public void SetDefaultHandler(EventHandler<T> handler)
|
||||
{
|
||||
m_DefaultHandler = handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
public void Fire(object sender, T e)
|
||||
{
|
||||
if (e == null)
|
||||
{
|
||||
throw new GameException("Event is invalid.");
|
||||
}
|
||||
|
||||
Event eventNode = Event.Create(sender, e);
|
||||
lock (m_Events)
|
||||
{
|
||||
m_Events.Enqueue(eventNode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
public void FireNow(object sender, T e)
|
||||
{
|
||||
if (e == null)
|
||||
{
|
||||
throw new GameException("Event is invalid.");
|
||||
}
|
||||
|
||||
HandleEvent(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理事件结点。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
private void HandleEvent(object sender, T e)
|
||||
{
|
||||
bool noHandlerException = false;
|
||||
GameLinkedListRange<EventHandler<T>> range = default(GameLinkedListRange<EventHandler<T>>);
|
||||
if (m_EventHandlers.TryGetValue(e.Id, out range))
|
||||
{
|
||||
LinkedListNode<EventHandler<T>> current = range.First;
|
||||
while (current != null && current != range.Terminal)
|
||||
{
|
||||
m_CachedNodes[e] = current.Next != range.Terminal ? current.Next : null;
|
||||
current.Value(sender, e);
|
||||
current = m_CachedNodes[e];
|
||||
}
|
||||
|
||||
m_CachedNodes.Remove(e);
|
||||
}
|
||||
else if (m_DefaultHandler != null)
|
||||
{
|
||||
m_DefaultHandler(sender, e);
|
||||
}
|
||||
else if ((m_EventPoolMode & EventPoolMode.AllowNoHandler) == 0)
|
||||
{
|
||||
noHandlerException = true;
|
||||
}
|
||||
|
||||
ReferencePool.Release(e);
|
||||
|
||||
if (noHandlerException)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Event '{0}' not allow no handler.", e.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6bfbcd98fa1ba14e94330d21f33beb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,33 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件池模式。
|
||||
/// </summary>
|
||||
[Flags]
|
||||
internal enum EventPoolMode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认事件池模式,即必须存在有且只有一个事件处理函数。
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 允许不存在事件处理函数。
|
||||
/// </summary>
|
||||
AllowNoHandler = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 允许存在多个事件处理函数。
|
||||
/// </summary>
|
||||
AllowMultiHandler = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 允许存在重复的事件处理函数。
|
||||
/// </summary>
|
||||
AllowDuplicateHandler = 4
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436424ea8e985d84ca725b445d5287d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
127
Assets/Axibug/Libraries/Axibug/Base/FrameworkEntry.cs
Normal file
127
Assets/Axibug/Libraries/Axibug/Base/FrameworkEntry.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架入口。
|
||||
/// </summary>
|
||||
//[DoNotRenameAttribute]
|
||||
public static class FrameworkEntry
|
||||
{
|
||||
private static readonly GameLinkedList<GameModule> s_Modules = new GameLinkedList<GameModule>();
|
||||
|
||||
/// <summary>
|
||||
/// 所有游戏框架模块轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public static void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
foreach (GameModule module in s_Modules)
|
||||
{
|
||||
module.Update(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理所有游戏框架模块。
|
||||
/// </summary>
|
||||
public static void Shutdown()
|
||||
{
|
||||
for (LinkedListNode<GameModule> current = s_Modules.Last; current != null; current = current.Previous)
|
||||
{
|
||||
current.Value.Shutdown();
|
||||
}
|
||||
|
||||
s_Modules.Clear();
|
||||
ReferencePool.ClearAll();
|
||||
Utility.Marshal.FreeCachedHGlobal();
|
||||
AxibugLog.SetLogHelper(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要获取的游戏框架模块类型。</typeparam>
|
||||
/// <returns>要获取的游戏框架模块。</returns>
|
||||
/// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
|
||||
public static T GetModule<T>() where T : class
|
||||
{
|
||||
Type interfaceType = typeof(T);
|
||||
if (!interfaceType.IsInterface)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName));
|
||||
}
|
||||
|
||||
if (!interfaceType.FullName.StartsWith("Axibug.", StringComparison.Ordinal))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("You must get a Axibug module, but '{0}' is not.", interfaceType.FullName));
|
||||
}
|
||||
|
||||
string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1));
|
||||
Type moduleType = Type.GetType(moduleName);
|
||||
if (moduleType == null)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Can not find Axibug module type '{0}'.", moduleName));
|
||||
}
|
||||
|
||||
return GetModule(moduleType) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块。
|
||||
/// </summary>
|
||||
/// <param name="moduleType">要获取的游戏框架模块类型。</param>
|
||||
/// <returns>要获取的游戏框架模块。</returns>
|
||||
/// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
|
||||
private static GameModule GetModule(Type moduleType)
|
||||
{
|
||||
foreach (GameModule module in s_Modules)
|
||||
{
|
||||
if (module.GetType() == moduleType)
|
||||
{
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
return CreateModule(moduleType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建游戏框架模块。
|
||||
/// </summary>
|
||||
/// <param name="moduleType">要创建的游戏框架模块类型。</param>
|
||||
/// <returns>要创建的游戏框架模块。</returns>
|
||||
private static GameModule CreateModule(Type moduleType)
|
||||
{
|
||||
GameModule module = (GameModule)Activator.CreateInstance(moduleType);
|
||||
if (module == null)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Can not create module '{0}'.", moduleType.FullName));
|
||||
}
|
||||
|
||||
LinkedListNode<GameModule> current = s_Modules.First;
|
||||
while (current != null)
|
||||
{
|
||||
if (module.Priority > current.Value.Priority)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
current = current.Next;
|
||||
}
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
s_Modules.AddBefore(current, module);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_Modules.AddLast(module);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/FrameworkEntry.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/FrameworkEntry.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53bbabd9500cc6e4e819b7599dd75f09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
359
Assets/Axibug/Libraries/Axibug/Base/GameAction.cs
Normal file
359
Assets/Axibug/Libraries/Axibug/Base/GameAction.cs
Normal file
@ -0,0 +1,359 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法不具有参数并且不返回值。
|
||||
/// </summary>
|
||||
public delegate void GameAction();
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法只有一个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">此委托封装的方法的参数类型。</typeparam>
|
||||
/// <param name="obj">此委托封装的方法的参数。</param>
|
||||
public delegate void GameAction<in T>(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有两个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2>(T1 arg1, T2 arg2);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有三个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3>(T1 arg1, T2 arg2, T3 arg3);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有四个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有五个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有六个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有七个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有八个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有九个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十一个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十二个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T12">此委托封装的方法的第十二个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
/// <param name="arg12">此委托封装的方法的第十二个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十三个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T12">此委托封装的方法的第十二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T13">此委托封装的方法的第十三个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
/// <param name="arg12">此委托封装的方法的第十二个参数。</param>
|
||||
/// <param name="arg13">此委托封装的方法的第十三个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十四个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T12">此委托封装的方法的第十二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T13">此委托封装的方法的第十三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T14">此委托封装的方法的第十四个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
/// <param name="arg12">此委托封装的方法的第十二个参数。</param>
|
||||
/// <param name="arg13">此委托封装的方法的第十三个参数。</param>
|
||||
/// <param name="arg14">此委托封装的方法的第十四个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十五个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T12">此委托封装的方法的第十二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T13">此委托封装的方法的第十三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T14">此委托封装的方法的第十四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T15">此委托封装的方法的第十五个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
/// <param name="arg12">此委托封装的方法的第十二个参数。</param>
|
||||
/// <param name="arg13">此委托封装的方法的第十三个参数。</param>
|
||||
/// <param name="arg14">此委托封装的方法的第十四个参数。</param>
|
||||
/// <param name="arg15">此委托封装的方法的第十五个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
|
||||
|
||||
/// <summary>
|
||||
/// 封装一个方法,该方法具有十六个参数并且不返回值。
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">此委托封装的方法的第一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T2">此委托封装的方法的第二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T3">此委托封装的方法的第三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T4">此委托封装的方法的第四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T5">此委托封装的方法的第五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T6">此委托封装的方法的第六个参数的类型。</typeparam>
|
||||
/// <typeparam name="T7">此委托封装的方法的第七个参数的类型。</typeparam>
|
||||
/// <typeparam name="T8">此委托封装的方法的第八个参数的类型。</typeparam>
|
||||
/// <typeparam name="T9">此委托封装的方法的第九个参数的类型。</typeparam>
|
||||
/// <typeparam name="T10">此委托封装的方法的第十个参数的类型。</typeparam>
|
||||
/// <typeparam name="T11">此委托封装的方法的第十一个参数的类型。</typeparam>
|
||||
/// <typeparam name="T12">此委托封装的方法的第十二个参数的类型。</typeparam>
|
||||
/// <typeparam name="T13">此委托封装的方法的第十三个参数的类型。</typeparam>
|
||||
/// <typeparam name="T14">此委托封装的方法的第十四个参数的类型。</typeparam>
|
||||
/// <typeparam name="T15">此委托封装的方法的第十五个参数的类型。</typeparam>
|
||||
/// <typeparam name="T16">此委托封装的方法的第十六个参数的类型。</typeparam>
|
||||
/// <param name="arg1">此委托封装的方法的第一个参数。</param>
|
||||
/// <param name="arg2">此委托封装的方法的第二个参数。</param>
|
||||
/// <param name="arg3">此委托封装的方法的第三个参数。</param>
|
||||
/// <param name="arg4">此委托封装的方法的第四个参数。</param>
|
||||
/// <param name="arg5">此委托封装的方法的第五个参数。</param>
|
||||
/// <param name="arg6">此委托封装的方法的第六个参数。</param>
|
||||
/// <param name="arg7">此委托封装的方法的第七个参数。</param>
|
||||
/// <param name="arg8">此委托封装的方法的第八个参数。</param>
|
||||
/// <param name="arg9">此委托封装的方法的第九个参数。</param>
|
||||
/// <param name="arg10">此委托封装的方法的第十个参数。</param>
|
||||
/// <param name="arg11">此委托封装的方法的第十一个参数。</param>
|
||||
/// <param name="arg12">此委托封装的方法的第十二个参数。</param>
|
||||
/// <param name="arg13">此委托封装的方法的第十三个参数。</param>
|
||||
/// <param name="arg14">此委托封装的方法的第十四个参数。</param>
|
||||
/// <param name="arg15">此委托封装的方法的第十五个参数。</param>
|
||||
/// <param name="arg16">此委托封装的方法的第十六个参数。</param>
|
||||
public delegate void GameAction<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/GameAction.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/GameAction.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b08b20d7e9c47842b628b207eb4c503
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Assets/Axibug/Libraries/Axibug/Base/GameEventArgs.cs
Normal file
22
Assets/Axibug/Libraries/Axibug/Base/GameEventArgs.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架中包含事件数据的类的基类。
|
||||
/// </summary>
|
||||
public abstract class GameEventArgs : EventArgs, IReference
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化游戏框架中包含事件数据的类的新实例。
|
||||
/// </summary>
|
||||
public GameEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理引用。
|
||||
/// </summary>
|
||||
public abstract void Clear();
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/GameEventArgs.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/GameEventArgs.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d32c6eeb4dad0184d92f3bb7757e1c62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
49
Assets/Axibug/Libraries/Axibug/Base/GameException.cs
Normal file
49
Assets/Axibug/Libraries/Axibug/Base/GameException.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架异常类。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class GameException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化游戏框架异常类的新实例。
|
||||
/// </summary>
|
||||
public GameException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用指定错误消息初始化游戏框架异常类的新实例。
|
||||
/// </summary>
|
||||
/// <param name="message">描述错误的消息。</param>
|
||||
public GameException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用指定错误消息和对作为此异常原因的内部异常的引用来初始化游戏框架异常类的新实例。
|
||||
/// </summary>
|
||||
/// <param name="message">解释异常原因的错误消息。</param>
|
||||
/// <param name="innerException">导致当前异常的异常。如果 innerException 参数不为空引用,则在处理内部异常的 catch 块中引发当前异常。</param>
|
||||
public GameException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用序列化数据初始化游戏框架异常类的新实例。
|
||||
/// </summary>
|
||||
/// <param name="info">存有有关所引发异常的序列化的对象数据。</param>
|
||||
/// <param name="context">包含有关源或目标的上下文信息。</param>
|
||||
protected GameException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/GameException.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/GameException.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 803f6e6ff55674140aa669317a1bc923
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
446
Assets/Axibug/Libraries/Axibug/Base/GameLinkedList.cs
Normal file
446
Assets/Axibug/Libraries/Axibug/Base/GameLinkedList.cs
Normal file
@ -0,0 +1,446 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架链表类。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">指定链表的元素类型。</typeparam>
|
||||
public sealed class GameLinkedList<T> : ICollection<T>, IEnumerable<T>, ICollection, IEnumerable
|
||||
{
|
||||
private readonly LinkedList<T> m_LinkedList;
|
||||
private readonly Queue<LinkedListNode<T>> m_CachedNodes;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化游戏框架链表类的新实例。
|
||||
/// </summary>
|
||||
public GameLinkedList()
|
||||
{
|
||||
m_LinkedList = new LinkedList<T>();
|
||||
m_CachedNodes = new Queue<LinkedListNode<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表中实际包含的结点数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_LinkedList.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表结点缓存数量。
|
||||
/// </summary>
|
||||
public int CachedNodeCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CachedNodes.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表的第一个结点。
|
||||
/// </summary>
|
||||
public LinkedListNode<T> First
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_LinkedList.First;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表的最后一个结点。
|
||||
/// </summary>
|
||||
public LinkedListNode<T> Last
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_LinkedList.Last;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示 ICollection`1 是否为只读。
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((ICollection<T>)m_LinkedList).IsReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用于同步对 ICollection 的访问的对象。
|
||||
/// </summary>
|
||||
public object SyncRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((ICollection)m_LinkedList).SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。
|
||||
/// </summary>
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((ICollection)m_LinkedList).IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表中指定的现有结点后添加包含指定值的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的现有结点。</param>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>包含指定值的新结点。</returns>
|
||||
public LinkedListNode<T> AddAfter(LinkedListNode<T> node, T value)
|
||||
{
|
||||
LinkedListNode<T> newNode = AcquireNode(value);
|
||||
m_LinkedList.AddAfter(node, newNode);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表中指定的现有结点后添加指定的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的现有结点。</param>
|
||||
/// <param name="newNode">指定的新结点。</param>
|
||||
public void AddAfter(LinkedListNode<T> node, LinkedListNode<T> newNode)
|
||||
{
|
||||
m_LinkedList.AddAfter(node, newNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表中指定的现有结点前添加包含指定值的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的现有结点。</param>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>包含指定值的新结点。</returns>
|
||||
public LinkedListNode<T> AddBefore(LinkedListNode<T> node, T value)
|
||||
{
|
||||
LinkedListNode<T> newNode = AcquireNode(value);
|
||||
m_LinkedList.AddBefore(node, newNode);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表中指定的现有结点前添加指定的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的现有结点。</param>
|
||||
/// <param name="newNode">指定的新结点。</param>
|
||||
public void AddBefore(LinkedListNode<T> node, LinkedListNode<T> newNode)
|
||||
{
|
||||
m_LinkedList.AddBefore(node, newNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表的开头处添加包含指定值的新结点。
|
||||
/// </summary>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>包含指定值的新结点。</returns>
|
||||
public LinkedListNode<T> AddFirst(T value)
|
||||
{
|
||||
LinkedListNode<T> node = AcquireNode(value);
|
||||
m_LinkedList.AddFirst(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表的开头处添加指定的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的新结点。</param>
|
||||
public void AddFirst(LinkedListNode<T> node)
|
||||
{
|
||||
m_LinkedList.AddFirst(node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表的结尾处添加包含指定值的新结点。
|
||||
/// </summary>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>包含指定值的新结点。</returns>
|
||||
public LinkedListNode<T> AddLast(T value)
|
||||
{
|
||||
LinkedListNode<T> node = AcquireNode(value);
|
||||
m_LinkedList.AddLast(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表的结尾处添加指定的新结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的新结点。</param>
|
||||
public void AddLast(LinkedListNode<T> node)
|
||||
{
|
||||
m_LinkedList.AddLast(node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从链表中移除所有结点。
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
LinkedListNode<T> current = m_LinkedList.First;
|
||||
while (current != null)
|
||||
{
|
||||
ReleaseNode(current);
|
||||
current = current.Next;
|
||||
}
|
||||
|
||||
m_LinkedList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除链表结点缓存。
|
||||
/// </summary>
|
||||
public void ClearCachedNodes()
|
||||
{
|
||||
m_CachedNodes.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确定某值是否在链表中。
|
||||
/// </summary>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>某值是否在链表中。</returns>
|
||||
public bool Contains(T value)
|
||||
{
|
||||
return m_LinkedList.Contains(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从目标数组的指定索引处开始将整个链表复制到兼容的一维数组。
|
||||
/// </summary>
|
||||
/// <param name="array">一维数组,它是从链表复制的元素的目标。数组必须具有从零开始的索引。</param>
|
||||
/// <param name="index">array 中从零开始的索引,从此处开始复制。</param>
|
||||
public void CopyTo(T[] array, int index)
|
||||
{
|
||||
m_LinkedList.CopyTo(array, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从特定的 ICollection 索引开始,将数组的元素复制到一个数组中。
|
||||
/// </summary>
|
||||
/// <param name="array">一维数组,它是从 ICollection 复制的元素的目标。数组必须具有从零开始的索引。</param>
|
||||
/// <param name="index">array 中从零开始的索引,从此处开始复制。</param>
|
||||
public void CopyTo(Array array, int index)
|
||||
{
|
||||
((ICollection)m_LinkedList).CopyTo(array, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找包含指定值的第一个结点。
|
||||
/// </summary>
|
||||
/// <param name="value">要查找的指定值。</param>
|
||||
/// <returns>包含指定值的第一个结点。</returns>
|
||||
public LinkedListNode<T> Find(T value)
|
||||
{
|
||||
return m_LinkedList.Find(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找包含指定值的最后一个结点。
|
||||
/// </summary>
|
||||
/// <param name="value">要查找的指定值。</param>
|
||||
/// <returns>包含指定值的最后一个结点。</returns>
|
||||
public LinkedListNode<T> FindLast(T value)
|
||||
{
|
||||
return m_LinkedList.FindLast(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从链表中移除指定值的第一个匹配项。
|
||||
/// </summary>
|
||||
/// <param name="value">指定值。</param>
|
||||
/// <returns>是否移除成功。</returns>
|
||||
public bool Remove(T value)
|
||||
{
|
||||
LinkedListNode<T> node = m_LinkedList.Find(value);
|
||||
if (node != null)
|
||||
{
|
||||
m_LinkedList.Remove(node);
|
||||
ReleaseNode(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从链表中移除指定的结点。
|
||||
/// </summary>
|
||||
/// <param name="node">指定的结点。</param>
|
||||
public void Remove(LinkedListNode<T> node)
|
||||
{
|
||||
m_LinkedList.Remove(node);
|
||||
ReleaseNode(node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除位于链表开头处的结点。
|
||||
/// </summary>
|
||||
public void RemoveFirst()
|
||||
{
|
||||
LinkedListNode<T> first = m_LinkedList.First;
|
||||
if (first == null)
|
||||
{
|
||||
throw new GameException("First is invalid.");
|
||||
}
|
||||
|
||||
m_LinkedList.RemoveFirst();
|
||||
ReleaseNode(first);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除位于链表结尾处的结点。
|
||||
/// </summary>
|
||||
public void RemoveLast()
|
||||
{
|
||||
LinkedListNode<T> last = m_LinkedList.Last;
|
||||
if (last == null)
|
||||
{
|
||||
throw new GameException("Last is invalid.");
|
||||
}
|
||||
|
||||
m_LinkedList.RemoveLast();
|
||||
ReleaseNode(last);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(m_LinkedList);
|
||||
}
|
||||
|
||||
private LinkedListNode<T> AcquireNode(T value)
|
||||
{
|
||||
LinkedListNode<T> node = null;
|
||||
if (m_CachedNodes.Count > 0)
|
||||
{
|
||||
node = m_CachedNodes.Dequeue();
|
||||
node.Value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new LinkedListNode<T>(value);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private void ReleaseNode(LinkedListNode<T> node)
|
||||
{
|
||||
node.Value = default(T);
|
||||
m_CachedNodes.Enqueue(node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将值添加到 ICollection`1 的结尾处。
|
||||
/// </summary>
|
||||
/// <param name="value">要添加的值。</param>
|
||||
void ICollection<T>.Add(T value)
|
||||
{
|
||||
AddLast(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct Enumerator : IEnumerator<T>, IEnumerator
|
||||
{
|
||||
private LinkedList<T>.Enumerator m_Enumerator;
|
||||
|
||||
internal Enumerator(LinkedList<T> linkedList)
|
||||
{
|
||||
if (linkedList == null)
|
||||
{
|
||||
throw new GameException("Linked list is invalid.");
|
||||
}
|
||||
|
||||
m_Enumerator = linkedList.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前结点。
|
||||
/// </summary>
|
||||
public T Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前的枚举数。
|
||||
/// </summary>
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理枚举数。
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
m_Enumerator.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个结点。
|
||||
/// </summary>
|
||||
/// <returns>返回下一个结点。</returns>
|
||||
public bool MoveNext()
|
||||
{
|
||||
return m_Enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置枚举数。
|
||||
/// </summary>
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
((IEnumerator<T>)m_Enumerator).Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/GameLinkedList.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/GameLinkedList.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fcc61c1c32cf3a4384ba527dd3190b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
210
Assets/Axibug/Libraries/Axibug/Base/GameLinkedListRange.cs
Normal file
210
Assets/Axibug/Libraries/Axibug/Base/GameLinkedListRange.cs
Normal file
@ -0,0 +1,210 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架链表范围。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">指定链表范围的元素类型。</typeparam>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct GameLinkedListRange<T> : IEnumerable<T>, IEnumerable
|
||||
{
|
||||
private readonly LinkedListNode<T> m_First;
|
||||
private readonly LinkedListNode<T> m_Terminal;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化游戏框架链表范围的新实例。
|
||||
/// </summary>
|
||||
/// <param name="first">链表范围的开始结点。</param>
|
||||
/// <param name="terminal">链表范围的终结标记结点。</param>
|
||||
public GameLinkedListRange(LinkedListNode<T> first, LinkedListNode<T> terminal)
|
||||
{
|
||||
if (first == null || terminal == null || first == terminal)
|
||||
{
|
||||
throw new GameException("Range is invalid.");
|
||||
}
|
||||
|
||||
m_First = first;
|
||||
m_Terminal = terminal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表范围是否有效。
|
||||
/// </summary>
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_First != null && m_Terminal != null && m_First != m_Terminal;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表范围的开始结点。
|
||||
/// </summary>
|
||||
public LinkedListNode<T> First
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_First;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表范围的终结标记结点。
|
||||
/// </summary>
|
||||
public LinkedListNode<T> Terminal
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Terminal;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取链表范围的结点数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsValid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (LinkedListNode<T> current = m_First; current != null && current != m_Terminal; current = current.Next)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否包含指定值。
|
||||
/// </summary>
|
||||
/// <param name="value">要检查的值。</param>
|
||||
/// <returns>是否包含指定值。</returns>
|
||||
public bool Contains(T value)
|
||||
{
|
||||
for (LinkedListNode<T> current = m_First; current != null && current != m_Terminal; current = current.Next)
|
||||
{
|
||||
if (current.Value.Equals(value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct Enumerator : IEnumerator<T>, IEnumerator
|
||||
{
|
||||
private readonly GameLinkedListRange<T> m_GameFrameworkLinkedListRange;
|
||||
private LinkedListNode<T> m_Current;
|
||||
private T m_CurrentValue;
|
||||
|
||||
internal Enumerator(GameLinkedListRange<T> range)
|
||||
{
|
||||
if (!range.IsValid)
|
||||
{
|
||||
throw new GameException("Range is invalid.");
|
||||
}
|
||||
|
||||
m_GameFrameworkLinkedListRange = range;
|
||||
m_Current = m_GameFrameworkLinkedListRange.m_First;
|
||||
m_CurrentValue = default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前结点。
|
||||
/// </summary>
|
||||
public T Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前的枚举数。
|
||||
/// </summary>
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理枚举数。
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个结点。
|
||||
/// </summary>
|
||||
/// <returns>返回下一个结点。</returns>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (m_Current == null || m_Current == m_GameFrameworkLinkedListRange.m_Terminal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_CurrentValue = m_Current.Value;
|
||||
m_Current = m_Current.Next;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置枚举数。
|
||||
/// </summary>
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
m_Current = m_GameFrameworkLinkedListRange.m_First;
|
||||
m_CurrentValue = default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe62e6247c1922748a605d6a34346b94
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/Axibug/Libraries/Axibug/Base/GameModule.cs
Normal file
32
Assets/Axibug/Libraries/Axibug/Base/GameModule.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架模块抽象类。
|
||||
/// </summary>
|
||||
internal abstract class GameModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块优先级。
|
||||
/// </summary>
|
||||
/// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
|
||||
internal virtual int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架模块轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
internal abstract void Update(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理游戏框架模块。
|
||||
/// </summary>
|
||||
internal abstract void Shutdown();
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/GameModule.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/GameModule.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e934b400da8f634cb84326c619db43f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
276
Assets/Axibug/Libraries/Axibug/Base/GameMultiDictionary.cs
Normal file
276
Assets/Axibug/Libraries/Axibug/Base/GameMultiDictionary.cs
Normal file
@ -0,0 +1,276 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架多值字典类。
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">指定多值字典的主键类型。</typeparam>
|
||||
/// <typeparam name="TValue">指定多值字典的值类型。</typeparam>
|
||||
public sealed class GameMultiDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, GameLinkedListRange<TValue>>>, IEnumerable
|
||||
{
|
||||
private readonly GameLinkedList<TValue> m_LinkedList;
|
||||
private readonly Dictionary<TKey, GameLinkedListRange<TValue>> m_Dictionary;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化游戏框架多值字典类的新实例。
|
||||
/// </summary>
|
||||
public GameMultiDictionary()
|
||||
{
|
||||
m_LinkedList = new GameLinkedList<TValue>();
|
||||
m_Dictionary = new Dictionary<TKey, GameLinkedListRange<TValue>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多值字典中实际包含的主键数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Dictionary.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多值字典中指定主键的范围。
|
||||
/// </summary>
|
||||
/// <param name="key">指定的主键。</param>
|
||||
/// <returns>指定主键的范围。</returns>
|
||||
public GameLinkedListRange<TValue> this[TKey key]
|
||||
{
|
||||
get
|
||||
{
|
||||
GameLinkedListRange<TValue> range = default(GameLinkedListRange<TValue>);
|
||||
m_Dictionary.TryGetValue(key, out range);
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理多值字典。
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
m_Dictionary.Clear();
|
||||
m_LinkedList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查多值字典中是否包含指定主键。
|
||||
/// </summary>
|
||||
/// <param name="key">要检查的主键。</param>
|
||||
/// <returns>多值字典中是否包含指定主键。</returns>
|
||||
public bool Contains(TKey key)
|
||||
{
|
||||
return m_Dictionary.ContainsKey(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查多值字典中是否包含指定值。
|
||||
/// </summary>
|
||||
/// <param name="key">要检查的主键。</param>
|
||||
/// <param name="value">要检查的值。</param>
|
||||
/// <returns>多值字典中是否包含指定值。</returns>
|
||||
public bool Contains(TKey key, TValue value)
|
||||
{
|
||||
GameLinkedListRange<TValue> range = default(GameLinkedListRange<TValue>);
|
||||
if (m_Dictionary.TryGetValue(key, out range))
|
||||
{
|
||||
return range.Contains(value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取多值字典中指定主键的范围。
|
||||
/// </summary>
|
||||
/// <param name="key">指定的主键。</param>
|
||||
/// <param name="range">指定主键的范围。</param>
|
||||
/// <returns>是否获取成功。</returns>
|
||||
public bool TryGetValue(TKey key, out GameLinkedListRange<TValue> range)
|
||||
{
|
||||
return m_Dictionary.TryGetValue(key, out range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向指定的主键增加指定的值。
|
||||
/// </summary>
|
||||
/// <param name="key">指定的主键。</param>
|
||||
/// <param name="value">指定的值。</param>
|
||||
public void Add(TKey key, TValue value)
|
||||
{
|
||||
GameLinkedListRange<TValue> range = default(GameLinkedListRange<TValue>);
|
||||
if (m_Dictionary.TryGetValue(key, out range))
|
||||
{
|
||||
m_LinkedList.AddBefore(range.Terminal, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
LinkedListNode<TValue> first = m_LinkedList.AddLast(value);
|
||||
LinkedListNode<TValue> terminal = m_LinkedList.AddLast(default(TValue));
|
||||
m_Dictionary.Add(key, new GameLinkedListRange<TValue>(first, terminal));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定的主键中移除指定的值。
|
||||
/// </summary>
|
||||
/// <param name="key">指定的主键。</param>
|
||||
/// <param name="value">指定的值。</param>
|
||||
/// <returns>是否移除成功。</returns>
|
||||
public bool Remove(TKey key, TValue value)
|
||||
{
|
||||
GameLinkedListRange<TValue> range = default(GameLinkedListRange<TValue>);
|
||||
if (m_Dictionary.TryGetValue(key, out range))
|
||||
{
|
||||
for (LinkedListNode<TValue> current = range.First; current != null && current != range.Terminal; current = current.Next)
|
||||
{
|
||||
if (current.Value.Equals(value))
|
||||
{
|
||||
if (current == range.First)
|
||||
{
|
||||
LinkedListNode<TValue> next = current.Next;
|
||||
if (next == range.Terminal)
|
||||
{
|
||||
m_LinkedList.Remove(next);
|
||||
m_Dictionary.Remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Dictionary[key] = new GameLinkedListRange<TValue>(next, range.Terminal);
|
||||
}
|
||||
}
|
||||
|
||||
m_LinkedList.Remove(current);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定的主键中移除所有的值。
|
||||
/// </summary>
|
||||
/// <param name="key">指定的主键。</param>
|
||||
/// <returns>是否移除成功。</returns>
|
||||
public bool RemoveAll(TKey key)
|
||||
{
|
||||
GameLinkedListRange<TValue> range = default(GameLinkedListRange<TValue>);
|
||||
if (m_Dictionary.TryGetValue(key, out range))
|
||||
{
|
||||
m_Dictionary.Remove(key);
|
||||
|
||||
LinkedListNode<TValue> current = range.First;
|
||||
while (current != null)
|
||||
{
|
||||
LinkedListNode<TValue> next = current != range.Terminal ? current.Next : null;
|
||||
m_LinkedList.Remove(current);
|
||||
current = next;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(m_Dictionary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator<KeyValuePair<TKey, GameLinkedListRange<TValue>>> IEnumerable<KeyValuePair<TKey, GameLinkedListRange<TValue>>>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
/// <returns>循环访问集合的枚举数。</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 循环访问集合的枚举数。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct Enumerator : IEnumerator<KeyValuePair<TKey, GameLinkedListRange<TValue>>>, IEnumerator
|
||||
{
|
||||
private Dictionary<TKey, GameLinkedListRange<TValue>>.Enumerator m_Enumerator;
|
||||
|
||||
internal Enumerator(Dictionary<TKey, GameLinkedListRange<TValue>> dictionary)
|
||||
{
|
||||
if (dictionary == null)
|
||||
{
|
||||
throw new GameException("Dictionary is invalid.");
|
||||
}
|
||||
|
||||
m_Enumerator = dictionary.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前结点。
|
||||
/// </summary>
|
||||
public KeyValuePair<TKey, GameLinkedListRange<TValue>> Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前的枚举数。
|
||||
/// </summary>
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理枚举数。
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
m_Enumerator.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个结点。
|
||||
/// </summary>
|
||||
/// <returns>返回下一个结点。</returns>
|
||||
public bool MoveNext()
|
||||
{
|
||||
return m_Enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置枚举数。
|
||||
/// </summary>
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
((IEnumerator<KeyValuePair<TKey, GameLinkedListRange<TValue>>>)m_Enumerator).Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8516f3fc9c4be99459c1a747453f52a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/ReferencePool.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/ReferencePool.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f902a9373313b1408eef975f3ee55a8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,13 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 引用接口。
|
||||
/// </summary>
|
||||
public interface IReference
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理引用。
|
||||
/// </summary>
|
||||
void Clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 134df7dfcc37c714cb549f61b87278d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
public static partial class ReferencePool
|
||||
{
|
||||
private sealed class ReferenceCollection
|
||||
{
|
||||
private readonly Queue<IReference> m_References;
|
||||
private readonly Type m_ReferenceType;
|
||||
private int m_UsingReferenceCount;
|
||||
private int m_AcquireReferenceCount;
|
||||
private int m_ReleaseReferenceCount;
|
||||
private int m_AddReferenceCount;
|
||||
private int m_RemoveReferenceCount;
|
||||
|
||||
public ReferenceCollection(Type referenceType)
|
||||
{
|
||||
m_References = new Queue<IReference>();
|
||||
m_ReferenceType = referenceType;
|
||||
m_UsingReferenceCount = 0;
|
||||
m_AcquireReferenceCount = 0;
|
||||
m_ReleaseReferenceCount = 0;
|
||||
m_AddReferenceCount = 0;
|
||||
m_RemoveReferenceCount = 0;
|
||||
}
|
||||
|
||||
public Type ReferenceType
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ReferenceType;
|
||||
}
|
||||
}
|
||||
|
||||
public int UnusedReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_References.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public int UsingReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UsingReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
public int AcquireReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AcquireReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
public int ReleaseReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ReleaseReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
public int AddReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AddReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
public int RemoveReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_RemoveReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
public T Acquire<T>() where T : class, IReference, new()
|
||||
{
|
||||
if (typeof(T) != m_ReferenceType)
|
||||
{
|
||||
throw new GameException("Type is invalid.");
|
||||
}
|
||||
|
||||
m_UsingReferenceCount++;
|
||||
m_AcquireReferenceCount++;
|
||||
lock (m_References)
|
||||
{
|
||||
if (m_References.Count > 0)
|
||||
{
|
||||
return (T)m_References.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
m_AddReferenceCount++;
|
||||
return new T();
|
||||
}
|
||||
|
||||
public IReference Acquire()
|
||||
{
|
||||
m_UsingReferenceCount++;
|
||||
m_AcquireReferenceCount++;
|
||||
lock (m_References)
|
||||
{
|
||||
if (m_References.Count > 0)
|
||||
{
|
||||
return m_References.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
m_AddReferenceCount++;
|
||||
return (IReference)Activator.CreateInstance(m_ReferenceType);
|
||||
}
|
||||
|
||||
public void Release(IReference reference)
|
||||
{
|
||||
reference.Clear();
|
||||
lock (m_References)
|
||||
{
|
||||
if (m_EnableStrictCheck && m_References.Contains(reference))
|
||||
{
|
||||
throw new GameException("The reference has been released.");
|
||||
}
|
||||
|
||||
m_References.Enqueue(reference);
|
||||
}
|
||||
|
||||
m_ReleaseReferenceCount++;
|
||||
m_UsingReferenceCount--;
|
||||
}
|
||||
|
||||
public void Add<T>(int count) where T : class, IReference, new()
|
||||
{
|
||||
if (typeof(T) != m_ReferenceType)
|
||||
{
|
||||
throw new GameException("Type is invalid.");
|
||||
}
|
||||
|
||||
lock (m_References)
|
||||
{
|
||||
m_AddReferenceCount += count;
|
||||
while (count-- > 0)
|
||||
{
|
||||
m_References.Enqueue(new T());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(int count)
|
||||
{
|
||||
lock (m_References)
|
||||
{
|
||||
m_AddReferenceCount += count;
|
||||
while (count-- > 0)
|
||||
{
|
||||
m_References.Enqueue((IReference)Activator.CreateInstance(m_ReferenceType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(int count)
|
||||
{
|
||||
lock (m_References)
|
||||
{
|
||||
if (count > m_References.Count)
|
||||
{
|
||||
count = m_References.Count;
|
||||
}
|
||||
|
||||
m_RemoveReferenceCount += count;
|
||||
while (count-- > 0)
|
||||
{
|
||||
m_References.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
lock (m_References)
|
||||
{
|
||||
m_RemoveReferenceCount += m_References.Count;
|
||||
m_References.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3abbc2af3b8748549a346ee683178cb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 引用池。
|
||||
/// </summary>
|
||||
public static partial class ReferencePool
|
||||
{
|
||||
private static readonly Dictionary<Type, ReferenceCollection> s_ReferenceCollections = new Dictionary<Type, ReferenceCollection>();
|
||||
private static bool m_EnableStrictCheck = false;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否开启强制检查。
|
||||
/// </summary>
|
||||
public static bool EnableStrictCheck
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EnableStrictCheck;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_EnableStrictCheck = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取引用池的数量。
|
||||
/// </summary>
|
||||
public static int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_ReferenceCollections.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有引用池的信息。
|
||||
/// </summary>
|
||||
/// <returns>所有引用池的信息。</returns>
|
||||
public static ReferencePoolInfo[] GetAllReferencePoolInfos()
|
||||
{
|
||||
int index = 0;
|
||||
ReferencePoolInfo[] results = null;
|
||||
|
||||
lock (s_ReferenceCollections)
|
||||
{
|
||||
results = new ReferencePoolInfo[s_ReferenceCollections.Count];
|
||||
foreach (KeyValuePair<Type, ReferenceCollection> referenceCollection in s_ReferenceCollections)
|
||||
{
|
||||
results[index++] = new ReferencePoolInfo(referenceCollection.Key, referenceCollection.Value.UnusedReferenceCount, referenceCollection.Value.UsingReferenceCount, referenceCollection.Value.AcquireReferenceCount, referenceCollection.Value.ReleaseReferenceCount, referenceCollection.Value.AddReferenceCount, referenceCollection.Value.RemoveReferenceCount);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有引用池。
|
||||
/// </summary>
|
||||
public static void ClearAll()
|
||||
{
|
||||
lock (s_ReferenceCollections)
|
||||
{
|
||||
foreach (KeyValuePair<Type, ReferenceCollection> referenceCollection in s_ReferenceCollections)
|
||||
{
|
||||
referenceCollection.Value.RemoveAll();
|
||||
}
|
||||
|
||||
s_ReferenceCollections.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池获取引用。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">引用类型。</typeparam>
|
||||
/// <returns>引用。</returns>
|
||||
public static T Acquire<T>() where T : class, IReference, new()
|
||||
{
|
||||
return GetReferenceCollection(typeof(T)).Acquire<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池获取引用。
|
||||
/// </summary>
|
||||
/// <param name="referenceType">引用类型。</param>
|
||||
/// <returns>引用。</returns>
|
||||
public static IReference Acquire(Type referenceType)
|
||||
{
|
||||
InternalCheckReferenceType(referenceType);
|
||||
return GetReferenceCollection(referenceType).Acquire();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将引用归还引用池。
|
||||
/// </summary>
|
||||
/// <param name="reference">引用。</param>
|
||||
public static void Release(IReference reference)
|
||||
{
|
||||
if (reference == null)
|
||||
{
|
||||
throw new GameException("Reference is invalid.");
|
||||
}
|
||||
|
||||
Type referenceType = reference.GetType();
|
||||
InternalCheckReferenceType(referenceType);
|
||||
GetReferenceCollection(referenceType).Release(reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向引用池中追加指定数量的引用。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">引用类型。</typeparam>
|
||||
/// <param name="count">追加数量。</param>
|
||||
public static void Add<T>(int count) where T : class, IReference, new()
|
||||
{
|
||||
GetReferenceCollection(typeof(T)).Add<T>(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向引用池中追加指定数量的引用。
|
||||
/// </summary>
|
||||
/// <param name="referenceType">引用类型。</param>
|
||||
/// <param name="count">追加数量。</param>
|
||||
public static void Add(Type referenceType, int count)
|
||||
{
|
||||
InternalCheckReferenceType(referenceType);
|
||||
GetReferenceCollection(referenceType).Add(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池中移除指定数量的引用。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">引用类型。</typeparam>
|
||||
/// <param name="count">移除数量。</param>
|
||||
public static void Remove<T>(int count) where T : class, IReference
|
||||
{
|
||||
GetReferenceCollection(typeof(T)).Remove(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池中移除指定数量的引用。
|
||||
/// </summary>
|
||||
/// <param name="referenceType">引用类型。</param>
|
||||
/// <param name="count">移除数量。</param>
|
||||
public static void Remove(Type referenceType, int count)
|
||||
{
|
||||
InternalCheckReferenceType(referenceType);
|
||||
GetReferenceCollection(referenceType).Remove(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池中移除所有的引用。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">引用类型。</typeparam>
|
||||
public static void RemoveAll<T>() where T : class, IReference
|
||||
{
|
||||
GetReferenceCollection(typeof(T)).RemoveAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从引用池中移除所有的引用。
|
||||
/// </summary>
|
||||
/// <param name="referenceType">引用类型。</param>
|
||||
public static void RemoveAll(Type referenceType)
|
||||
{
|
||||
InternalCheckReferenceType(referenceType);
|
||||
GetReferenceCollection(referenceType).RemoveAll();
|
||||
}
|
||||
|
||||
private static void InternalCheckReferenceType(Type referenceType)
|
||||
{
|
||||
if (!m_EnableStrictCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (referenceType == null)
|
||||
{
|
||||
throw new GameException("Reference type is invalid.");
|
||||
}
|
||||
|
||||
if (!referenceType.IsClass || referenceType.IsAbstract)
|
||||
{
|
||||
throw new GameException("Reference type is not a non-abstract class type.");
|
||||
}
|
||||
|
||||
if (!typeof(IReference).IsAssignableFrom(referenceType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Reference type '{0}' is invalid.", referenceType.FullName));
|
||||
}
|
||||
}
|
||||
|
||||
private static ReferenceCollection GetReferenceCollection(Type referenceType)
|
||||
{
|
||||
if (referenceType == null)
|
||||
{
|
||||
throw new GameException("ReferenceType is invalid.");
|
||||
}
|
||||
|
||||
ReferenceCollection referenceCollection = null;
|
||||
lock (s_ReferenceCollections)
|
||||
{
|
||||
if (!s_ReferenceCollections.TryGetValue(referenceType, out referenceCollection))
|
||||
{
|
||||
referenceCollection = new ReferenceCollection(referenceType);
|
||||
s_ReferenceCollections.Add(referenceType, referenceCollection);
|
||||
}
|
||||
}
|
||||
|
||||
return referenceCollection;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b626f29f609759a45b2febc7dcef8bd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 引用池信息。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct ReferencePoolInfo
|
||||
{
|
||||
private readonly Type m_Type;
|
||||
private readonly int m_UnusedReferenceCount;
|
||||
private readonly int m_UsingReferenceCount;
|
||||
private readonly int m_AcquireReferenceCount;
|
||||
private readonly int m_ReleaseReferenceCount;
|
||||
private readonly int m_AddReferenceCount;
|
||||
private readonly int m_RemoveReferenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化引用池信息的新实例。
|
||||
/// </summary>
|
||||
/// <param name="type">引用池类型。</param>
|
||||
/// <param name="unusedReferenceCount">未使用引用数量。</param>
|
||||
/// <param name="usingReferenceCount">正在使用引用数量。</param>
|
||||
/// <param name="acquireReferenceCount">获取引用数量。</param>
|
||||
/// <param name="releaseReferenceCount">归还引用数量。</param>
|
||||
/// <param name="addReferenceCount">增加引用数量。</param>
|
||||
/// <param name="removeReferenceCount">移除引用数量。</param>
|
||||
public ReferencePoolInfo(Type type, int unusedReferenceCount, int usingReferenceCount, int acquireReferenceCount, int releaseReferenceCount, int addReferenceCount, int removeReferenceCount)
|
||||
{
|
||||
m_Type = type;
|
||||
m_UnusedReferenceCount = unusedReferenceCount;
|
||||
m_UsingReferenceCount = usingReferenceCount;
|
||||
m_AcquireReferenceCount = acquireReferenceCount;
|
||||
m_ReleaseReferenceCount = releaseReferenceCount;
|
||||
m_AddReferenceCount = addReferenceCount;
|
||||
m_RemoveReferenceCount = removeReferenceCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取引用池类型。
|
||||
/// </summary>
|
||||
public Type Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未使用引用数量。
|
||||
/// </summary>
|
||||
public int UnusedReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UnusedReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取正在使用引用数量。
|
||||
/// </summary>
|
||||
public int UsingReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UsingReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取获取引用数量。
|
||||
/// </summary>
|
||||
public int AcquireReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AcquireReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取归还引用数量。
|
||||
/// </summary>
|
||||
public int ReleaseReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ReleaseReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取增加引用数量。
|
||||
/// </summary>
|
||||
public int AddReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AddReferenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取移除引用数量。
|
||||
/// </summary>
|
||||
public int RemoveReferenceCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_RemoveReferenceCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 776630f236433f44d83d51f7516ada89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/TaskPool.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/TaskPool.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27b231869b9b4424687b7a5ad74caf5d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Axibug/Libraries/Axibug/Base/TaskPool/ITaskAgent.cs
Normal file
46
Assets/Axibug/Libraries/Axibug/Base/TaskPool/ITaskAgent.cs
Normal file
@ -0,0 +1,46 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务代理接口。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">任务类型。</typeparam>
|
||||
internal interface ITaskAgent<T> where T : TaskBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取任务。
|
||||
/// </summary>
|
||||
T Task
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化任务代理。
|
||||
/// </summary>
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// 任务代理轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
void Update(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理任务代理。
|
||||
/// </summary>
|
||||
void Shutdown();
|
||||
|
||||
/// <summary>
|
||||
/// 开始处理任务。
|
||||
/// </summary>
|
||||
/// <param name="task">要处理的任务。</param>
|
||||
/// <returns>开始处理任务的状态。</returns>
|
||||
StartTaskStatus Start(T task);
|
||||
|
||||
/// <summary>
|
||||
/// 停止正在处理的任务并重置任务代理。
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 466edb2a2f949ba4e88932507f0b1513
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,28 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 开始处理任务的状态。
|
||||
/// </summary>
|
||||
public enum StartTaskStatus : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// 可以立刻处理完成此任务。
|
||||
/// </summary>
|
||||
Done = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 可以继续处理此任务。
|
||||
/// </summary>
|
||||
CanResume,
|
||||
|
||||
/// <summary>
|
||||
/// 不能继续处理此任务,需等待其它任务执行完成。
|
||||
/// </summary>
|
||||
HasToWait,
|
||||
|
||||
/// <summary>
|
||||
/// 不能继续处理此任务,出现未知错误。
|
||||
/// </summary>
|
||||
UnknownError
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 939e0fd71752d5f46ba51e63f772fb69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
130
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskBase.cs
Normal file
130
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskBase.cs
Normal file
@ -0,0 +1,130 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务基类。
|
||||
/// </summary>
|
||||
internal abstract class TaskBase : IReference
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务默认优先级。
|
||||
/// </summary>
|
||||
public const int DefaultPriority = 0;
|
||||
|
||||
private int m_SerialId;
|
||||
private string m_Tag;
|
||||
private int m_Priority;
|
||||
private object m_UserData;
|
||||
|
||||
private bool m_Done;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化任务基类的新实例。
|
||||
/// </summary>
|
||||
public TaskBase()
|
||||
{
|
||||
m_SerialId = 0;
|
||||
m_Tag = null;
|
||||
m_Priority = DefaultPriority;
|
||||
m_Done = false;
|
||||
m_UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的序列编号。
|
||||
/// </summary>
|
||||
public int SerialId
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SerialId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的标签。
|
||||
/// </summary>
|
||||
public string Tag
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的优先级。
|
||||
/// </summary>
|
||||
public int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Priority;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UserData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务是否完成。
|
||||
/// </summary>
|
||||
public bool Done
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Done;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Done = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务描述。
|
||||
/// </summary>
|
||||
public virtual string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化任务基类。
|
||||
/// </summary>
|
||||
/// <param name="serialId">任务的序列编号。</param>
|
||||
/// <param name="tag">任务的标签。</param>
|
||||
/// <param name="priority">任务的优先级。</param>
|
||||
/// <param name="userData">任务的用户自定义数据。</param>
|
||||
internal void Initialize(int serialId, string tag, int priority, object userData)
|
||||
{
|
||||
m_SerialId = serialId;
|
||||
m_Tag = tag;
|
||||
m_Priority = priority;
|
||||
m_UserData = userData;
|
||||
m_Done = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理任务基类。
|
||||
/// </summary>
|
||||
public virtual void Clear()
|
||||
{
|
||||
m_SerialId = 0;
|
||||
m_Tag = null;
|
||||
m_Priority = DefaultPriority;
|
||||
m_UserData = null;
|
||||
m_Done = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f082e98ffd5ffc4e8164c1b975719bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
146
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskInfo.cs
Normal file
146
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskInfo.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务信息。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct TaskInfo
|
||||
{
|
||||
private readonly bool m_IsValid;
|
||||
private readonly int m_SerialId;
|
||||
private readonly string m_Tag;
|
||||
private readonly int m_Priority;
|
||||
private readonly object m_UserData;
|
||||
private readonly TaskStatus m_Status;
|
||||
private readonly string m_Description;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化任务信息的新实例。
|
||||
/// </summary>
|
||||
/// <param name="serialId">任务的序列编号。</param>
|
||||
/// <param name="tag">任务的标签。</param>
|
||||
/// <param name="priority">任务的优先级。</param>
|
||||
/// <param name="userData">任务的用户自定义数据。</param>
|
||||
/// <param name="status">任务状态。</param>
|
||||
/// <param name="description">任务描述。</param>
|
||||
public TaskInfo(int serialId, string tag, int priority, object userData, TaskStatus status, string description)
|
||||
{
|
||||
m_IsValid = true;
|
||||
m_SerialId = serialId;
|
||||
m_Tag = tag;
|
||||
m_Priority = priority;
|
||||
m_UserData = userData;
|
||||
m_Status = status;
|
||||
m_Description = description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务信息是否有效。
|
||||
/// </summary>
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_IsValid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的序列编号。
|
||||
/// </summary>
|
||||
public int SerialId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_SerialId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的标签。
|
||||
/// </summary>
|
||||
public string Tag
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_Tag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的优先级。
|
||||
/// </summary>
|
||||
public int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_Priority;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务的用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_UserData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务状态。
|
||||
/// </summary>
|
||||
public TaskStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_Status;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务描述。
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_IsValid)
|
||||
{
|
||||
throw new GameException("Data is invalid.");
|
||||
}
|
||||
|
||||
return m_Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87ba8bb79ba02324dafdca71bb721ae0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
437
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskPool.cs
Normal file
437
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskPool.cs
Normal file
@ -0,0 +1,437 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务池。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">任务类型。</typeparam>
|
||||
internal sealed class TaskPool<T> where T : TaskBase
|
||||
{
|
||||
private readonly Stack<ITaskAgent<T>> m_FreeAgents;
|
||||
private readonly GameLinkedList<ITaskAgent<T>> m_WorkingAgents;
|
||||
private readonly GameLinkedList<T> m_WaitingTasks;
|
||||
private bool m_Paused;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化任务池的新实例。
|
||||
/// </summary>
|
||||
public TaskPool()
|
||||
{
|
||||
m_FreeAgents = new Stack<ITaskAgent<T>>();
|
||||
m_WorkingAgents = new GameLinkedList<ITaskAgent<T>>();
|
||||
m_WaitingTasks = new GameLinkedList<T>();
|
||||
m_Paused = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务池是否被暂停。
|
||||
/// </summary>
|
||||
public bool Paused
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Paused;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Paused = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取任务代理总数量。
|
||||
/// </summary>
|
||||
public int TotalAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return FreeAgentCount + WorkingAgentCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用任务代理数量。
|
||||
/// </summary>
|
||||
public int FreeAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_FreeAgents.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取工作中任务代理数量。
|
||||
/// </summary>
|
||||
public int WorkingAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WorkingAgents.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取等待任务数量。
|
||||
/// </summary>
|
||||
public int WaitingTaskCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WaitingTasks.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务池轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (m_Paused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessRunningTasks(elapseSeconds, realElapseSeconds);
|
||||
ProcessWaitingTasks(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理任务池。
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
RemoveAllTasks();
|
||||
|
||||
while (FreeAgentCount > 0)
|
||||
{
|
||||
m_FreeAgents.Pop().Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加任务代理。
|
||||
/// </summary>
|
||||
/// <param name="agent">要增加的任务代理。</param>
|
||||
public void AddAgent(ITaskAgent<T> agent)
|
||||
{
|
||||
if (agent == null)
|
||||
{
|
||||
throw new GameException("Task agent is invalid.");
|
||||
}
|
||||
|
||||
agent.Initialize();
|
||||
m_FreeAgents.Push(agent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务的序列编号获取任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="serialId">要获取信息的任务的序列编号。</param>
|
||||
/// <returns>任务的信息。</returns>
|
||||
public TaskInfo GetTaskInfo(int serialId)
|
||||
{
|
||||
foreach (ITaskAgent<T> workingAgent in m_WorkingAgents)
|
||||
{
|
||||
T workingTask = workingAgent.Task;
|
||||
if (workingTask.SerialId == serialId)
|
||||
{
|
||||
return new TaskInfo(workingTask.SerialId, workingTask.Tag, workingTask.Priority, workingTask.UserData, workingTask.Done ? TaskStatus.Done : TaskStatus.Doing, workingTask.Description);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (T waitingTask in m_WaitingTasks)
|
||||
{
|
||||
if (waitingTask.SerialId == serialId)
|
||||
{
|
||||
return new TaskInfo(waitingTask.SerialId, waitingTask.Tag, waitingTask.Priority, waitingTask.UserData, TaskStatus.Todo, waitingTask.Description);
|
||||
}
|
||||
}
|
||||
|
||||
return default(TaskInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务的标签获取任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="tag">要获取信息的任务的标签。</param>
|
||||
/// <returns>任务的信息。</returns>
|
||||
public TaskInfo[] GetTaskInfos(string tag)
|
||||
{
|
||||
List<TaskInfo> results = new List<TaskInfo>();
|
||||
GetTaskInfos(tag, results);
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务的标签获取任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="tag">要获取信息的任务的标签。</param>
|
||||
/// <param name="results">任务的信息。</param>
|
||||
public void GetTaskInfos(string tag, List<TaskInfo> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new GameException("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (ITaskAgent<T> workingAgent in m_WorkingAgents)
|
||||
{
|
||||
T workingTask = workingAgent.Task;
|
||||
if (workingTask.Tag == tag)
|
||||
{
|
||||
results.Add(new TaskInfo(workingTask.SerialId, workingTask.Tag, workingTask.Priority, workingTask.UserData, workingTask.Done ? TaskStatus.Done : TaskStatus.Doing, workingTask.Description));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (T waitingTask in m_WaitingTasks)
|
||||
{
|
||||
if (waitingTask.Tag == tag)
|
||||
{
|
||||
results.Add(new TaskInfo(waitingTask.SerialId, waitingTask.Tag, waitingTask.Priority, waitingTask.UserData, TaskStatus.Todo, waitingTask.Description));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有任务的信息。
|
||||
/// </summary>
|
||||
/// <returns>所有任务的信息。</returns>
|
||||
public TaskInfo[] GetAllTaskInfos()
|
||||
{
|
||||
int index = 0;
|
||||
TaskInfo[] results = new TaskInfo[m_WorkingAgents.Count + m_WaitingTasks.Count];
|
||||
foreach (ITaskAgent<T> workingAgent in m_WorkingAgents)
|
||||
{
|
||||
T workingTask = workingAgent.Task;
|
||||
results[index++] = new TaskInfo(workingTask.SerialId, workingTask.Tag, workingTask.Priority, workingTask.UserData, workingTask.Done ? TaskStatus.Done : TaskStatus.Doing, workingTask.Description);
|
||||
}
|
||||
|
||||
foreach (T waitingTask in m_WaitingTasks)
|
||||
{
|
||||
results[index++] = new TaskInfo(waitingTask.SerialId, waitingTask.Tag, waitingTask.Priority, waitingTask.UserData, TaskStatus.Todo, waitingTask.Description);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="results">所有任务的信息。</param>
|
||||
public void GetAllTaskInfos(List<TaskInfo> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new GameException("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (ITaskAgent<T> workingAgent in m_WorkingAgents)
|
||||
{
|
||||
T workingTask = workingAgent.Task;
|
||||
results.Add(new TaskInfo(workingTask.SerialId, workingTask.Tag, workingTask.Priority, workingTask.UserData, workingTask.Done ? TaskStatus.Done : TaskStatus.Doing, workingTask.Description));
|
||||
}
|
||||
|
||||
foreach (T waitingTask in m_WaitingTasks)
|
||||
{
|
||||
results.Add(new TaskInfo(waitingTask.SerialId, waitingTask.Tag, waitingTask.Priority, waitingTask.UserData, TaskStatus.Todo, waitingTask.Description));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加任务。
|
||||
/// </summary>
|
||||
/// <param name="task">要增加的任务。</param>
|
||||
public void AddTask(T task)
|
||||
{
|
||||
LinkedListNode<T> current = m_WaitingTasks.Last;
|
||||
while (current != null)
|
||||
{
|
||||
if (task.Priority <= current.Value.Priority)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
current = current.Previous;
|
||||
}
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
m_WaitingTasks.AddAfter(current, task);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_WaitingTasks.AddFirst(task);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务的序列编号移除任务。
|
||||
/// </summary>
|
||||
/// <param name="serialId">要移除任务的序列编号。</param>
|
||||
/// <returns>是否移除任务成功。</returns>
|
||||
public bool RemoveTask(int serialId)
|
||||
{
|
||||
foreach (T task in m_WaitingTasks)
|
||||
{
|
||||
if (task.SerialId == serialId)
|
||||
{
|
||||
m_WaitingTasks.Remove(task);
|
||||
ReferencePool.Release(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
LinkedListNode<ITaskAgent<T>> currentWorkingAgent = m_WorkingAgents.First;
|
||||
while (currentWorkingAgent != null)
|
||||
{
|
||||
LinkedListNode<ITaskAgent<T>> next = currentWorkingAgent.Next;
|
||||
ITaskAgent<T> workingAgent = currentWorkingAgent.Value;
|
||||
T task = workingAgent.Task;
|
||||
if (task.SerialId == serialId)
|
||||
{
|
||||
workingAgent.Reset();
|
||||
m_FreeAgents.Push(workingAgent);
|
||||
m_WorkingAgents.Remove(currentWorkingAgent);
|
||||
ReferencePool.Release(task);
|
||||
return true;
|
||||
}
|
||||
|
||||
currentWorkingAgent = next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务的标签移除任务。
|
||||
/// </summary>
|
||||
/// <param name="tag">要移除任务的标签。</param>
|
||||
/// <returns>移除任务的数量。</returns>
|
||||
public int RemoveTasks(string tag)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
LinkedListNode<T> currentWaitingTask = m_WaitingTasks.First;
|
||||
while (currentWaitingTask != null)
|
||||
{
|
||||
LinkedListNode<T> next = currentWaitingTask.Next;
|
||||
T task = currentWaitingTask.Value;
|
||||
if (task.Tag == tag)
|
||||
{
|
||||
m_WaitingTasks.Remove(currentWaitingTask);
|
||||
ReferencePool.Release(task);
|
||||
count++;
|
||||
}
|
||||
|
||||
currentWaitingTask = next;
|
||||
}
|
||||
|
||||
LinkedListNode<ITaskAgent<T>> currentWorkingAgent = m_WorkingAgents.First;
|
||||
while (currentWorkingAgent != null)
|
||||
{
|
||||
LinkedListNode<ITaskAgent<T>> next = currentWorkingAgent.Next;
|
||||
ITaskAgent<T> workingAgent = currentWorkingAgent.Value;
|
||||
T task = workingAgent.Task;
|
||||
if (task.Tag == tag)
|
||||
{
|
||||
workingAgent.Reset();
|
||||
m_FreeAgents.Push(workingAgent);
|
||||
m_WorkingAgents.Remove(currentWorkingAgent);
|
||||
ReferencePool.Release(task);
|
||||
count++;
|
||||
}
|
||||
|
||||
currentWorkingAgent = next;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除所有任务。
|
||||
/// </summary>
|
||||
/// <returns>移除任务的数量。</returns>
|
||||
public int RemoveAllTasks()
|
||||
{
|
||||
int count = m_WaitingTasks.Count + m_WorkingAgents.Count;
|
||||
|
||||
foreach (T task in m_WaitingTasks)
|
||||
{
|
||||
ReferencePool.Release(task);
|
||||
}
|
||||
|
||||
m_WaitingTasks.Clear();
|
||||
|
||||
foreach (ITaskAgent<T> workingAgent in m_WorkingAgents)
|
||||
{
|
||||
T task = workingAgent.Task;
|
||||
workingAgent.Reset();
|
||||
m_FreeAgents.Push(workingAgent);
|
||||
ReferencePool.Release(task);
|
||||
}
|
||||
|
||||
m_WorkingAgents.Clear();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private void ProcessRunningTasks(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
LinkedListNode<ITaskAgent<T>> current = m_WorkingAgents.First;
|
||||
while (current != null)
|
||||
{
|
||||
T task = current.Value.Task;
|
||||
if (!task.Done)
|
||||
{
|
||||
current.Value.Update(elapseSeconds, realElapseSeconds);
|
||||
current = current.Next;
|
||||
continue;
|
||||
}
|
||||
|
||||
LinkedListNode<ITaskAgent<T>> next = current.Next;
|
||||
current.Value.Reset();
|
||||
m_FreeAgents.Push(current.Value);
|
||||
m_WorkingAgents.Remove(current);
|
||||
ReferencePool.Release(task);
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessWaitingTasks(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
LinkedListNode<T> current = m_WaitingTasks.First;
|
||||
while (current != null && FreeAgentCount > 0)
|
||||
{
|
||||
ITaskAgent<T> agent = m_FreeAgents.Pop();
|
||||
LinkedListNode<ITaskAgent<T>> agentNode = m_WorkingAgents.AddLast(agent);
|
||||
T task = current.Value;
|
||||
LinkedListNode<T> next = current.Next;
|
||||
StartTaskStatus status = agent.Start(task);
|
||||
if (status == StartTaskStatus.Done || status == StartTaskStatus.HasToWait || status == StartTaskStatus.UnknownError)
|
||||
{
|
||||
agent.Reset();
|
||||
m_FreeAgents.Push(agent);
|
||||
m_WorkingAgents.Remove(agentNode);
|
||||
}
|
||||
|
||||
if (status == StartTaskStatus.Done || status == StartTaskStatus.CanResume || status == StartTaskStatus.UnknownError)
|
||||
{
|
||||
m_WaitingTasks.Remove(current);
|
||||
}
|
||||
|
||||
if (status == StartTaskStatus.Done || status == StartTaskStatus.UnknownError)
|
||||
{
|
||||
ReferencePool.Release(task);
|
||||
}
|
||||
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2329744baad6104bb812730c480609d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskStatus.cs
Normal file
23
Assets/Axibug/Libraries/Axibug/Base/TaskPool/TaskStatus.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务状态。
|
||||
/// </summary>
|
||||
public enum TaskStatus : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// 未开始。
|
||||
/// </summary>
|
||||
Todo = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 执行中。
|
||||
/// </summary>
|
||||
Doing,
|
||||
|
||||
/// <summary>
|
||||
/// 完成。
|
||||
/// </summary>
|
||||
Done
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 173124ca9decfde44aee2a7e53210fdd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/Variable.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/Variable.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 736eebe7987d3504daa1707d182d4c60
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">变量类型。</typeparam>
|
||||
public abstract class Variable<T> : Variable
|
||||
{
|
||||
private T m_Value;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化变量的新实例。
|
||||
/// </summary>
|
||||
public Variable()
|
||||
{
|
||||
m_Value = default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量类型。
|
||||
/// </summary>
|
||||
public override Type Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(T);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量值。
|
||||
/// </summary>
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量值。
|
||||
/// </summary>
|
||||
/// <returns>变量值。</returns>
|
||||
public override object GetValue()
|
||||
{
|
||||
return m_Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置变量值。
|
||||
/// </summary>
|
||||
/// <param name="value">变量值。</param>
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
m_Value = (T)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理变量值。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
m_Value = default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量字符串。
|
||||
/// </summary>
|
||||
/// <returns>变量字符串。</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return (m_Value != null) ? m_Value.ToString() : "<Null>";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d50141a6c0d62048925d43e36c7b9e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
42
Assets/Axibug/Libraries/Axibug/Base/Variable/Variable.cs
Normal file
42
Assets/Axibug/Libraries/Axibug/Base/Variable/Variable.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量。
|
||||
/// </summary>
|
||||
public abstract class Variable : IReference
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化变量的新实例。
|
||||
/// </summary>
|
||||
public Variable()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量类型。
|
||||
/// </summary>
|
||||
public abstract Type Type
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量值。
|
||||
/// </summary>
|
||||
/// <returns>变量值。</returns>
|
||||
public abstract object GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// 设置变量值。
|
||||
/// </summary>
|
||||
/// <param name="value">变量值。</param>
|
||||
public abstract void SetValue(object value);
|
||||
|
||||
/// <summary>
|
||||
/// 清理变量值。
|
||||
/// </summary>
|
||||
public abstract void Clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db655d0d167ebc54693014e1e00508c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Base/Version.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Base/Version.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10bee13c022589041896a681911de3ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,27 @@
|
||||
namespace Axibug
|
||||
{
|
||||
public static partial class Version
|
||||
{
|
||||
/// <summary>
|
||||
/// 版本号辅助器接口。
|
||||
/// </summary>
|
||||
public interface IVersionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取游戏版本号。
|
||||
/// </summary>
|
||||
string GameVersion
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取内部游戏版本号。
|
||||
/// </summary>
|
||||
int InternalGameVersion
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac0584aa02079bc48a38a5e31b16ad42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
64
Assets/Axibug/Libraries/Axibug/Base/Version/Version.cs
Normal file
64
Assets/Axibug/Libraries/Axibug/Base/Version/Version.cs
Normal file
@ -0,0 +1,64 @@
|
||||
namespace Axibug
|
||||
{
|
||||
/// <summary>
|
||||
/// 版本号类。
|
||||
/// </summary>
|
||||
public static partial class Version
|
||||
{
|
||||
private const string GameFrameworkVersionString = "2021.05.31";
|
||||
|
||||
private static IVersionHelper s_VersionHelper = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架版本号。
|
||||
/// </summary>
|
||||
public static string GameFrameworkVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return GameFrameworkVersionString;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏版本号。
|
||||
/// </summary>
|
||||
public static string GameVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_VersionHelper == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return s_VersionHelper.GameVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取内部游戏版本号。
|
||||
/// </summary>
|
||||
public static int InternalGameVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_VersionHelper == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return s_VersionHelper.InternalGameVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置版本号辅助器。
|
||||
/// </summary>
|
||||
/// <param name="versionHelper">要设置的版本号辅助器。</param>
|
||||
public static void SetVersionHelper(IVersionHelper versionHelper)
|
||||
{
|
||||
s_VersionHelper = versionHelper;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Base/Version/Version.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Base/Version/Version.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b98a2efa24d1e864ca481022c96114a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Debugger.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Debugger.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14058a47d09a54e4ca1b2f1e7a87e69f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,300 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug.Debugger
|
||||
{
|
||||
internal sealed partial class DebuggerManager : GameModule, IDebuggerManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试器窗口组。
|
||||
/// </summary>
|
||||
private sealed class DebuggerWindowGroup : IDebuggerWindowGroup
|
||||
{
|
||||
private readonly List<KeyValuePair<string, IDebuggerWindow>> m_DebuggerWindows;
|
||||
private int m_SelectedIndex;
|
||||
private string[] m_DebuggerWindowNames;
|
||||
|
||||
public DebuggerWindowGroup()
|
||||
{
|
||||
m_DebuggerWindows = new List<KeyValuePair<string, IDebuggerWindow>>();
|
||||
m_SelectedIndex = 0;
|
||||
m_DebuggerWindowNames = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试器窗口数量。
|
||||
/// </summary>
|
||||
public int DebuggerWindowCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DebuggerWindows.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置当前选中的调试器窗口索引。
|
||||
/// </summary>
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前选中的调试器窗口。
|
||||
/// </summary>
|
||||
public IDebuggerWindow SelectedWindow
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SelectedIndex >= m_DebuggerWindows.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return m_DebuggerWindows[m_SelectedIndex].Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化调试组。
|
||||
/// </summary>
|
||||
/// <param name="args">初始化调试组参数。</param>
|
||||
public void Initialize(params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭调试组。
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
|
||||
{
|
||||
debuggerWindow.Value.Shutdown();
|
||||
}
|
||||
|
||||
m_DebuggerWindows.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入调试器窗口。
|
||||
/// </summary>
|
||||
public void OnEnter()
|
||||
{
|
||||
SelectedWindow.OnEnter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离开调试器窗口。
|
||||
/// </summary>
|
||||
public void OnLeave()
|
||||
{
|
||||
SelectedWindow.OnLeave();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试组轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
SelectedWindow.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试器窗口绘制。
|
||||
/// </summary>
|
||||
public void OnDraw()
|
||||
{
|
||||
}
|
||||
|
||||
private void RefreshDebuggerWindowNames()
|
||||
{
|
||||
int index = 0;
|
||||
m_DebuggerWindowNames = new string[m_DebuggerWindows.Count];
|
||||
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
|
||||
{
|
||||
m_DebuggerWindowNames[index++] = debuggerWindow.Key;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试组的调试器窗口名称集合。
|
||||
/// </summary>
|
||||
public string[] GetDebuggerWindowNames()
|
||||
{
|
||||
return m_DebuggerWindowNames;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>要获取的调试器窗口。</returns>
|
||||
public IDebuggerWindow GetDebuggerWindow(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int pos = path.IndexOf('/');
|
||||
if (pos < 0 || pos >= path.Length - 1)
|
||||
{
|
||||
return InternalGetDebuggerWindow(path);
|
||||
}
|
||||
|
||||
string debuggerWindowGroupName = path.Substring(0, pos);
|
||||
string leftPath = path.Substring(pos + 1);
|
||||
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
|
||||
if (debuggerWindowGroup == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return debuggerWindowGroup.GetDebuggerWindow(leftPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否成功选中调试器窗口。</returns>
|
||||
public bool SelectDebuggerWindow(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int pos = path.IndexOf('/');
|
||||
if (pos < 0 || pos >= path.Length - 1)
|
||||
{
|
||||
return InternalSelectDebuggerWindow(path);
|
||||
}
|
||||
|
||||
string debuggerWindowGroupName = path.Substring(0, pos);
|
||||
string leftPath = path.Substring(pos + 1);
|
||||
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
|
||||
if (debuggerWindowGroup == null || !InternalSelectDebuggerWindow(debuggerWindowGroupName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return debuggerWindowGroup.SelectDebuggerWindow(leftPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <param name="debuggerWindow">要注册的调试器窗口。</param>
|
||||
public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new GameException("Path is invalid.");
|
||||
}
|
||||
|
||||
int pos = path.IndexOf('/');
|
||||
if (pos < 0 || pos >= path.Length - 1)
|
||||
{
|
||||
if (InternalGetDebuggerWindow(path) != null)
|
||||
{
|
||||
throw new GameException("Debugger window has been registered.");
|
||||
}
|
||||
|
||||
m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(path, debuggerWindow));
|
||||
RefreshDebuggerWindowNames();
|
||||
}
|
||||
else
|
||||
{
|
||||
string debuggerWindowGroupName = path.Substring(0, pos);
|
||||
string leftPath = path.Substring(pos + 1);
|
||||
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
|
||||
if (debuggerWindowGroup == null)
|
||||
{
|
||||
if (InternalGetDebuggerWindow(debuggerWindowGroupName) != null)
|
||||
{
|
||||
throw new GameException("Debugger window has been registered, can not create debugger window group.");
|
||||
}
|
||||
|
||||
debuggerWindowGroup = new DebuggerWindowGroup();
|
||||
m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(debuggerWindowGroupName, debuggerWindowGroup));
|
||||
RefreshDebuggerWindowNames();
|
||||
}
|
||||
|
||||
debuggerWindowGroup.RegisterDebuggerWindow(leftPath, debuggerWindow);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否解除注册调试器窗口成功。</returns>
|
||||
public bool UnregisterDebuggerWindow(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int pos = path.IndexOf('/');
|
||||
if (pos < 0 || pos >= path.Length - 1)
|
||||
{
|
||||
IDebuggerWindow debuggerWindow = InternalGetDebuggerWindow(path);
|
||||
bool result = m_DebuggerWindows.Remove(new KeyValuePair<string, IDebuggerWindow>(path, debuggerWindow));
|
||||
debuggerWindow.Shutdown();
|
||||
RefreshDebuggerWindowNames();
|
||||
return result;
|
||||
}
|
||||
|
||||
string debuggerWindowGroupName = path.Substring(0, pos);
|
||||
string leftPath = path.Substring(pos + 1);
|
||||
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
|
||||
if (debuggerWindowGroup == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return debuggerWindowGroup.UnregisterDebuggerWindow(leftPath);
|
||||
}
|
||||
|
||||
private IDebuggerWindow InternalGetDebuggerWindow(string name)
|
||||
{
|
||||
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
|
||||
{
|
||||
if (debuggerWindow.Key == name)
|
||||
{
|
||||
return debuggerWindow.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool InternalSelectDebuggerWindow(string name)
|
||||
{
|
||||
for (int i = 0; i < m_DebuggerWindows.Count; i++)
|
||||
{
|
||||
if (m_DebuggerWindows[i].Key == name)
|
||||
{
|
||||
m_SelectedIndex = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f84ddb434cdd47145bafcb5a50218c42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
134
Assets/Axibug/Libraries/Axibug/Debugger/DebuggerManager.cs
Normal file
134
Assets/Axibug/Libraries/Axibug/Debugger/DebuggerManager.cs
Normal file
@ -0,0 +1,134 @@
|
||||
namespace Axibug.Debugger
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试器管理器。
|
||||
/// </summary>
|
||||
internal sealed partial class DebuggerManager : GameModule, IDebuggerManager
|
||||
{
|
||||
private readonly DebuggerWindowGroup m_DebuggerWindowRoot;
|
||||
private bool m_ActiveWindow;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化调试器管理器的新实例。
|
||||
/// </summary>
|
||||
public DebuggerManager()
|
||||
{
|
||||
m_DebuggerWindowRoot = new DebuggerWindowGroup();
|
||||
m_ActiveWindow = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块优先级。
|
||||
/// </summary>
|
||||
/// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
|
||||
internal override int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置调试器窗口是否激活。
|
||||
/// </summary>
|
||||
public bool ActiveWindow
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ActiveWindow;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_ActiveWindow = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试器窗口根结点。
|
||||
/// </summary>
|
||||
public IDebuggerWindowGroup DebuggerWindowRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DebuggerWindowRoot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试器管理器轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
internal override void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (!m_ActiveWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_DebuggerWindowRoot.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理调试器管理器。
|
||||
/// </summary>
|
||||
internal override void Shutdown()
|
||||
{
|
||||
m_ActiveWindow = false;
|
||||
m_DebuggerWindowRoot.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <param name="debuggerWindow">要注册的调试器窗口。</param>
|
||||
/// <param name="args">初始化调试器窗口参数。</param>
|
||||
public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow, params object[] args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new GameException("Path is invalid.");
|
||||
}
|
||||
|
||||
if (debuggerWindow == null)
|
||||
{
|
||||
throw new GameException("Debugger window is invalid.");
|
||||
}
|
||||
|
||||
m_DebuggerWindowRoot.RegisterDebuggerWindow(path, debuggerWindow);
|
||||
debuggerWindow.Initialize(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否解除注册调试器窗口成功。</returns>
|
||||
public bool UnregisterDebuggerWindow(string path)
|
||||
{
|
||||
return m_DebuggerWindowRoot.UnregisterDebuggerWindow(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>要获取的调试器窗口。</returns>
|
||||
public IDebuggerWindow GetDebuggerWindow(string path)
|
||||
{
|
||||
return m_DebuggerWindowRoot.GetDebuggerWindow(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否成功选中调试器窗口。</returns>
|
||||
public bool SelectDebuggerWindow(string path)
|
||||
{
|
||||
return m_DebuggerWindowRoot.SelectDebuggerWindow(path);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55342ca22acfabe449d51bcee1d091f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Axibug/Libraries/Axibug/Debugger/IDebuggerManager.cs
Normal file
54
Assets/Axibug/Libraries/Axibug/Debugger/IDebuggerManager.cs
Normal file
@ -0,0 +1,54 @@
|
||||
namespace Axibug.Debugger
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试器管理器接口。
|
||||
/// </summary>
|
||||
public interface IDebuggerManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置调试器窗口是否激活。
|
||||
/// </summary>
|
||||
bool ActiveWindow
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试器窗口根结点。
|
||||
/// </summary>
|
||||
IDebuggerWindowGroup DebuggerWindowRoot
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <param name="debuggerWindow">要注册的调试器窗口。</param>
|
||||
/// <param name="args">初始化调试器窗口参数。</param>
|
||||
void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// 解除注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否解除注册调试器窗口成功。</returns>
|
||||
bool UnregisterDebuggerWindow(string path);
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>要获取的调试器窗口。</returns>
|
||||
IDebuggerWindow GetDebuggerWindow(string path);
|
||||
|
||||
/// <summary>
|
||||
/// 选中调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>是否成功选中调试器窗口。</returns>
|
||||
bool SelectDebuggerWindow(string path);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64e80edcb6fcf584185c2466c163e013
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
41
Assets/Axibug/Libraries/Axibug/Debugger/IDebuggerWindow.cs
Normal file
41
Assets/Axibug/Libraries/Axibug/Debugger/IDebuggerWindow.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace Axibug.Debugger
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试器窗口接口。
|
||||
/// </summary>
|
||||
public interface IDebuggerWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="args">初始化调试器窗口参数。</param>
|
||||
void Initialize(params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// 关闭调试器窗口。
|
||||
/// </summary>
|
||||
void Shutdown();
|
||||
|
||||
/// <summary>
|
||||
/// 进入调试器窗口。
|
||||
/// </summary>
|
||||
void OnEnter();
|
||||
|
||||
/// <summary>
|
||||
/// 离开调试器窗口。
|
||||
/// </summary>
|
||||
void OnLeave();
|
||||
|
||||
/// <summary>
|
||||
/// 调试器窗口轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
void OnUpdate(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// 调试器窗口绘制。
|
||||
/// </summary>
|
||||
void OnDraw();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a79ea5887a03924b9a1de7709d2b185
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,52 @@
|
||||
namespace Axibug.Debugger
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试器窗口组接口。
|
||||
/// </summary>
|
||||
public interface IDebuggerWindowGroup : IDebuggerWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取调试器窗口数量。
|
||||
/// </summary>
|
||||
int DebuggerWindowCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置当前选中的调试器窗口索引。
|
||||
/// </summary>
|
||||
int SelectedIndex
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前选中的调试器窗口。
|
||||
/// </summary>
|
||||
IDebuggerWindow SelectedWindow
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试组的调试器窗口名称集合。
|
||||
/// </summary>
|
||||
string[] GetDebuggerWindowNames();
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <returns>要获取的调试器窗口。</returns>
|
||||
IDebuggerWindow GetDebuggerWindow(string path);
|
||||
|
||||
/// <summary>
|
||||
/// 注册调试器窗口。
|
||||
/// </summary>
|
||||
/// <param name="path">调试器窗口路径。</param>
|
||||
/// <param name="debuggerWindow">要注册的调试器窗口。</param>
|
||||
void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc4316aad580c940a13904c115e75f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Event.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Event.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 396ed48f1c71fae4c9fb296c6c40cea3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
142
Assets/Axibug/Libraries/Axibug/Event/EventManager.cs
Normal file
142
Assets/Axibug/Libraries/Axibug/Event/EventManager.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug.Event
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件管理器。
|
||||
/// </summary>
|
||||
internal sealed class EventManager : GameModule, IEventManager
|
||||
{
|
||||
private readonly EventPool<LogicEventArgs> m_EventPool;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化事件管理器的新实例。
|
||||
/// </summary>
|
||||
public EventManager()
|
||||
{
|
||||
m_EventPool = new EventPool<LogicEventArgs>(EventPoolMode.AllowNoHandler | EventPoolMode.AllowMultiHandler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
public int EventHandlerCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EventPool.EventHandlerCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件数量。
|
||||
/// </summary>
|
||||
public int EventCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EventPool.EventCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块优先级。
|
||||
/// </summary>
|
||||
/// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
|
||||
internal override int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件管理器轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
internal override void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
m_EventPool.Update(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理事件管理器。
|
||||
/// </summary>
|
||||
internal override void Shutdown()
|
||||
{
|
||||
m_EventPool.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <returns>事件处理函数的数量。</returns>
|
||||
public int Count(int id)
|
||||
{
|
||||
return m_EventPool.Count(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要检查的事件处理函数。</param>
|
||||
/// <returns>是否存在事件处理函数。</returns>
|
||||
public bool Check(int id, EventHandler<LogicEventArgs> handler)
|
||||
{
|
||||
return m_EventPool.Check(id, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要订阅的事件处理函数。</param>
|
||||
public void Subscribe(int id, EventHandler<LogicEventArgs> handler)
|
||||
{
|
||||
m_EventPool.Subscribe(id, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要取消订阅的事件处理函数。</param>
|
||||
public void Unsubscribe(int id, EventHandler<LogicEventArgs> handler)
|
||||
{
|
||||
m_EventPool.Unsubscribe(id, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="handler">要设置的默认事件处理函数。</param>
|
||||
public void SetDefaultHandler(EventHandler<LogicEventArgs> handler)
|
||||
{
|
||||
m_EventPool.SetDefaultHandler(handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
public void Fire(object sender, LogicEventArgs e)
|
||||
{
|
||||
m_EventPool.Fire(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
public void FireNow(object sender, LogicEventArgs e)
|
||||
{
|
||||
m_EventPool.FireNow(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Event/EventManager.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Event/EventManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60d8b9124f6820f41b86c0b19ece2cae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
75
Assets/Axibug/Libraries/Axibug/Event/IEventManager.cs
Normal file
75
Assets/Axibug/Libraries/Axibug/Event/IEventManager.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug.Event
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件管理器接口。
|
||||
/// </summary>
|
||||
public interface IEventManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
int EventHandlerCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件数量。
|
||||
/// </summary>
|
||||
int EventCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件处理函数的数量。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <returns>事件处理函数的数量。</returns>
|
||||
int Count(int id);
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要检查的事件处理函数。</param>
|
||||
/// <returns>是否存在事件处理函数。</returns>
|
||||
bool Check(int id, EventHandler<LogicEventArgs> handler);
|
||||
|
||||
/// <summary>
|
||||
/// 订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要订阅的事件处理函数。</param>
|
||||
void Subscribe(int id, EventHandler<LogicEventArgs> handler);
|
||||
|
||||
/// <summary>
|
||||
/// 取消订阅事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="id">事件类型编号。</param>
|
||||
/// <param name="handler">要取消订阅的事件处理函数。</param>
|
||||
void Unsubscribe(int id, EventHandler<LogicEventArgs> handler);
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认事件处理函数。
|
||||
/// </summary>
|
||||
/// <param name="handler">要设置的默认事件处理函数。</param>
|
||||
void SetDefaultHandler(EventHandler<LogicEventArgs> handler);
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
void Fire(object sender, LogicEventArgs e);
|
||||
|
||||
/// <summary>
|
||||
/// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
|
||||
/// </summary>
|
||||
/// <param name="sender">事件源。</param>
|
||||
/// <param name="e">事件参数。</param>
|
||||
void FireNow(object sender, LogicEventArgs e);
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Event/IEventManager.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Event/IEventManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a4ce65c36a418b47a58978a237374e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Axibug/Libraries/Axibug/Event/LogicEventArgs.cs
Normal file
10
Assets/Axibug/Libraries/Axibug/Event/LogicEventArgs.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Axibug.Event
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏逻辑事件基类。
|
||||
/// </summary>
|
||||
public abstract class LogicEventArgs : BaseEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Event/LogicEventArgs.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Event/LogicEventArgs.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ed28d5303b0aee4bae5978fe96b41a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Axibug/Libraries/Axibug/Fsm.meta
Normal file
8
Assets/Axibug/Libraries/Axibug/Fsm.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e34dd4f238dcc2468248079cb986fa4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
581
Assets/Axibug/Libraries/Axibug/Fsm/Fsm.cs
Normal file
581
Assets/Axibug/Libraries/Axibug/Fsm/Fsm.cs
Normal file
@ -0,0 +1,581 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
internal sealed class Fsm<T> : FsmBase, IReference, IFsm<T> where T : class
|
||||
{
|
||||
private T m_Owner;
|
||||
private readonly Dictionary<Type, FsmState<T>> m_States;
|
||||
private Dictionary<string, Variable> m_Datas;
|
||||
private FsmState<T> m_CurrentState;
|
||||
private float m_CurrentStateTime;
|
||||
private bool m_IsDestroyed;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化有限状态机的新实例。
|
||||
/// </summary>
|
||||
public Fsm()
|
||||
{
|
||||
m_Owner = null;
|
||||
m_States = new Dictionary<Type, FsmState<T>>();
|
||||
m_Datas = null;
|
||||
m_CurrentState = null;
|
||||
m_CurrentStateTime = 0f;
|
||||
m_IsDestroyed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机持有者。
|
||||
/// </summary>
|
||||
public T Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Owner;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机持有者类型。
|
||||
/// </summary>
|
||||
public override Type OwnerType
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(T);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机中状态的数量。
|
||||
/// </summary>
|
||||
public override int FsmStateCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_States.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否正在运行。
|
||||
/// </summary>
|
||||
public override bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentState != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否被销毁。
|
||||
/// </summary>
|
||||
public override bool IsDestroyed
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_IsDestroyed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态。
|
||||
/// </summary>
|
||||
public FsmState<T> CurrentState
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态名称。
|
||||
/// </summary>
|
||||
public override string CurrentStateName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentState != null ? m_CurrentState.GetType().FullName : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态持续时间。
|
||||
/// </summary>
|
||||
public override float CurrentStateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CurrentStateTime;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>创建的有限状态机。</returns>
|
||||
public static Fsm<T> Create(string name, T owner, params FsmState<T>[] states)
|
||||
{
|
||||
if (owner == null)
|
||||
{
|
||||
throw new GameException("FSM owner is invalid.");
|
||||
}
|
||||
|
||||
if (states == null || states.Length < 1)
|
||||
{
|
||||
throw new GameException("FSM states is invalid.");
|
||||
}
|
||||
|
||||
Fsm<T> fsm = ReferencePool.Acquire<Fsm<T>>();
|
||||
fsm.Name = name;
|
||||
fsm.m_Owner = owner;
|
||||
fsm.m_IsDestroyed = false;
|
||||
foreach (FsmState<T> state in states)
|
||||
{
|
||||
if (state == null)
|
||||
{
|
||||
throw new GameException("FSM states is invalid.");
|
||||
}
|
||||
|
||||
Type stateType = state.GetType();
|
||||
if (fsm.m_States.ContainsKey(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("FSM '{0}' state '{1}' is already exist.", new TypeNamePair(typeof(T), name), stateType.FullName));
|
||||
}
|
||||
|
||||
fsm.m_States.Add(stateType, state);
|
||||
state.OnInit(fsm);
|
||||
}
|
||||
|
||||
return fsm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>创建的有限状态机。</returns>
|
||||
public static Fsm<T> Create(string name, T owner, List<FsmState<T>> states)
|
||||
{
|
||||
if (owner == null)
|
||||
{
|
||||
throw new GameException("FSM owner is invalid.");
|
||||
}
|
||||
|
||||
if (states == null || states.Count < 1)
|
||||
{
|
||||
throw new GameException("FSM states is invalid.");
|
||||
}
|
||||
|
||||
Fsm<T> fsm = ReferencePool.Acquire<Fsm<T>>();
|
||||
fsm.Name = name;
|
||||
fsm.m_Owner = owner;
|
||||
fsm.m_IsDestroyed = false;
|
||||
foreach (FsmState<T> state in states)
|
||||
{
|
||||
if (state == null)
|
||||
{
|
||||
throw new GameException("FSM states is invalid.");
|
||||
}
|
||||
|
||||
Type stateType = state.GetType();
|
||||
if (fsm.m_States.ContainsKey(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("FSM '{0}' state '{1}' is already exist.", new TypeNamePair(typeof(T), name), stateType.FullName));
|
||||
}
|
||||
|
||||
fsm.m_States.Add(stateType, state);
|
||||
state.OnInit(fsm);
|
||||
}
|
||||
|
||||
return fsm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理有限状态机。
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
if (m_CurrentState != null)
|
||||
{
|
||||
m_CurrentState.OnLeave(this, true);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<Type, FsmState<T>> state in m_States)
|
||||
{
|
||||
state.Value.OnDestroy(this);
|
||||
}
|
||||
|
||||
Name = null;
|
||||
m_Owner = null;
|
||||
m_States.Clear();
|
||||
|
||||
if (m_Datas != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, Variable> data in m_Datas)
|
||||
{
|
||||
if (data.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ReferencePool.Release(data.Value);
|
||||
}
|
||||
|
||||
m_Datas.Clear();
|
||||
}
|
||||
|
||||
m_CurrentState = null;
|
||||
m_CurrentStateTime = 0f;
|
||||
m_IsDestroyed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要开始的有限状态机状态类型。</typeparam>
|
||||
public void Start<TState>() where TState : FsmState<T>
|
||||
{
|
||||
if (IsRunning)
|
||||
{
|
||||
throw new GameException("FSM is running, can not start again.");
|
||||
}
|
||||
|
||||
FsmState<T> state = GetState<TState>();
|
||||
if (state == null)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("FSM '{0}' can not start state '{1}' which is not exist.", new TypeNamePair(typeof(T), Name), typeof(TState).FullName));
|
||||
}
|
||||
|
||||
m_CurrentStateTime = 0f;
|
||||
m_CurrentState = state;
|
||||
m_CurrentState.OnEnter(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要开始的有限状态机状态类型。</param>
|
||||
public void Start(Type stateType)
|
||||
{
|
||||
if (IsRunning)
|
||||
{
|
||||
throw new GameException("FSM is running, can not start again.");
|
||||
}
|
||||
|
||||
if (stateType == null)
|
||||
{
|
||||
throw new GameException("State type is invalid.");
|
||||
}
|
||||
|
||||
if (!typeof(FsmState<T>).IsAssignableFrom(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("State type '{0}' is invalid.", stateType.FullName));
|
||||
}
|
||||
|
||||
FsmState<T> state = GetState(stateType);
|
||||
if (state == null)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("FSM '{0}' can not start state '{1}' which is not exist.", new TypeNamePair(typeof(T), Name), stateType.FullName));
|
||||
}
|
||||
|
||||
m_CurrentStateTime = 0f;
|
||||
m_CurrentState = state;
|
||||
m_CurrentState.OnEnter(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要检查的有限状态机状态类型。</typeparam>
|
||||
/// <returns>是否存在有限状态机状态。</returns>
|
||||
public bool HasState<TState>() where TState : FsmState<T>
|
||||
{
|
||||
return m_States.ContainsKey(typeof(TState));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要检查的有限状态机状态类型。</param>
|
||||
/// <returns>是否存在有限状态机状态。</returns>
|
||||
public bool HasState(Type stateType)
|
||||
{
|
||||
if (stateType == null)
|
||||
{
|
||||
throw new GameException("State type is invalid.");
|
||||
}
|
||||
|
||||
if (!typeof(FsmState<T>).IsAssignableFrom(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("State type '{0}' is invalid.", stateType.FullName));
|
||||
}
|
||||
|
||||
return m_States.ContainsKey(stateType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要获取的有限状态机状态类型。</typeparam>
|
||||
/// <returns>要获取的有限状态机状态。</returns>
|
||||
public TState GetState<TState>() where TState : FsmState<T>
|
||||
{
|
||||
FsmState<T> state = null;
|
||||
if (m_States.TryGetValue(typeof(TState), out state))
|
||||
{
|
||||
return (TState)state;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要获取的有限状态机状态类型。</param>
|
||||
/// <returns>要获取的有限状态机状态。</returns>
|
||||
public FsmState<T> GetState(Type stateType)
|
||||
{
|
||||
if (stateType == null)
|
||||
{
|
||||
throw new GameException("State type is invalid.");
|
||||
}
|
||||
|
||||
if (!typeof(FsmState<T>).IsAssignableFrom(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("State type '{0}' is invalid.", stateType.FullName));
|
||||
}
|
||||
|
||||
FsmState<T> state = null;
|
||||
if (m_States.TryGetValue(stateType, out state))
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机的所有状态。
|
||||
/// </summary>
|
||||
/// <returns>有限状态机的所有状态。</returns>
|
||||
public FsmState<T>[] GetAllStates()
|
||||
{
|
||||
int index = 0;
|
||||
FsmState<T>[] results = new FsmState<T>[m_States.Count];
|
||||
foreach (KeyValuePair<Type, FsmState<T>> state in m_States)
|
||||
{
|
||||
results[index++] = state.Value;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机的所有状态。
|
||||
/// </summary>
|
||||
/// <param name="results">有限状态机的所有状态。</param>
|
||||
public void GetAllStates(List<FsmState<T>> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new GameException("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (KeyValuePair<Type, FsmState<T>> state in m_States)
|
||||
{
|
||||
results.Add(state.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>有限状态机数据是否存在。</returns>
|
||||
public bool HasData(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new GameException("Data name is invalid.");
|
||||
}
|
||||
|
||||
if (m_Datas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_Datas.ContainsKey(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机数据。
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">要获取的有限状态机数据的类型。</typeparam>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>要获取的有限状态机数据。</returns>
|
||||
public TData GetData<TData>(string name) where TData : Variable
|
||||
{
|
||||
return (TData)GetData(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>要获取的有限状态机数据。</returns>
|
||||
public Variable GetData(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new GameException("Data name is invalid.");
|
||||
}
|
||||
|
||||
if (m_Datas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Variable data = null;
|
||||
if (m_Datas.TryGetValue(name, out data))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置有限状态机数据。
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">要设置的有限状态机数据的类型。</typeparam>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <param name="data">要设置的有限状态机数据。</param>
|
||||
public void SetData<TData>(string name, TData data) where TData : Variable
|
||||
{
|
||||
SetData(name, (Variable)data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <param name="data">要设置的有限状态机数据。</param>
|
||||
public void SetData(string name, Variable data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new GameException("Data name is invalid.");
|
||||
}
|
||||
|
||||
if (m_Datas == null)
|
||||
{
|
||||
m_Datas = new Dictionary<string, Variable>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
Variable oldData = GetData(name);
|
||||
if (oldData != null)
|
||||
{
|
||||
ReferencePool.Release(oldData);
|
||||
}
|
||||
|
||||
m_Datas[name] = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>是否移除有限状态机数据成功。</returns>
|
||||
public bool RemoveData(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new GameException("Data name is invalid.");
|
||||
}
|
||||
|
||||
if (m_Datas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Variable oldData = GetData(name);
|
||||
if (oldData != null)
|
||||
{
|
||||
ReferencePool.Release(oldData);
|
||||
}
|
||||
|
||||
return m_Datas.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
internal override void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (m_CurrentState == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentStateTime += elapseSeconds;
|
||||
m_CurrentState.OnUpdate(this, elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理有限状态机。
|
||||
/// </summary>
|
||||
internal override void Shutdown()
|
||||
{
|
||||
ReferencePool.Release(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换当前有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam>
|
||||
internal void ChangeState<TState>() where TState : FsmState<T>
|
||||
{
|
||||
ChangeState(typeof(TState));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换当前有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要切换到的有限状态机状态类型。</param>
|
||||
internal void ChangeState(Type stateType)
|
||||
{
|
||||
if (m_CurrentState == null)
|
||||
{
|
||||
throw new GameException("Current state is invalid.");
|
||||
}
|
||||
|
||||
FsmState<T> state = GetState(stateType);
|
||||
if (state == null)
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("FSM '{0}' can not change state to '{1}' which is not exist.", new TypeNamePair(typeof(T), Name), stateType.FullName));
|
||||
}
|
||||
|
||||
m_CurrentState.OnLeave(this, false);
|
||||
m_CurrentStateTime = 0f;
|
||||
m_CurrentState = state;
|
||||
m_CurrentState.OnEnter(this);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/Fsm.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/Fsm.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 216cac4bb3c555849ac2d653e5cc4e0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
106
Assets/Axibug/Libraries/Axibug/Fsm/FsmBase.cs
Normal file
106
Assets/Axibug/Libraries/Axibug/Fsm/FsmBase.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机基类。
|
||||
/// </summary>
|
||||
public abstract class FsmBase
|
||||
{
|
||||
private string m_Name;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化有限状态机基类的新实例。
|
||||
/// </summary>
|
||||
public FsmBase()
|
||||
{
|
||||
m_Name = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机名称。
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
protected set
|
||||
{
|
||||
m_Name = value ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机完整名称。
|
||||
/// </summary>
|
||||
public string FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TypeNamePair(OwnerType, m_Name).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机持有者类型。
|
||||
/// </summary>
|
||||
public abstract Type OwnerType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机中状态的数量。
|
||||
/// </summary>
|
||||
public abstract int FsmStateCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否正在运行。
|
||||
/// </summary>
|
||||
public abstract bool IsRunning
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否被销毁。
|
||||
/// </summary>
|
||||
public abstract bool IsDestroyed
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态名称。
|
||||
/// </summary>
|
||||
public abstract string CurrentStateName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态持续时间。
|
||||
/// </summary>
|
||||
public abstract float CurrentStateTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">当前已流逝时间,以秒为单位。</param>
|
||||
internal abstract void Update(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理有限状态机。
|
||||
/// </summary>
|
||||
internal abstract void Shutdown();
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmBase.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmBase.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8dfebf07449b5b7448dcd7f607e4aa2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
404
Assets/Axibug/Libraries/Axibug/Fsm/FsmManager.cs
Normal file
404
Assets/Axibug/Libraries/Axibug/Fsm/FsmManager.cs
Normal file
@ -0,0 +1,404 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机管理器。
|
||||
/// </summary>
|
||||
internal sealed class FsmManager : GameModule, IFsmManager
|
||||
{
|
||||
private readonly Dictionary<TypeNamePair, FsmBase> m_Fsms;
|
||||
private readonly List<FsmBase> m_TempFsms;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化有限状态机管理器的新实例。
|
||||
/// </summary>
|
||||
public FsmManager()
|
||||
{
|
||||
m_Fsms = new Dictionary<TypeNamePair, FsmBase>();
|
||||
m_TempFsms = new List<FsmBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块优先级。
|
||||
/// </summary>
|
||||
/// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
|
||||
internal override int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Fsms.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机管理器轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
internal override void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
m_TempFsms.Clear();
|
||||
if (m_Fsms.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
|
||||
{
|
||||
m_TempFsms.Add(fsm.Value);
|
||||
}
|
||||
|
||||
foreach (FsmBase fsm in m_TempFsms)
|
||||
{
|
||||
if (fsm.IsDestroyed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fsm.Update(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理有限状态机管理器。
|
||||
/// </summary>
|
||||
internal override void Shutdown()
|
||||
{
|
||||
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
|
||||
{
|
||||
fsm.Value.Shutdown();
|
||||
}
|
||||
|
||||
m_Fsms.Clear();
|
||||
m_TempFsms.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
public bool HasFsm<T>() where T : class
|
||||
{
|
||||
return InternalHasFsm(new TypeNamePair(typeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
public bool HasFsm(Type ownerType)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalHasFsm(new TypeNamePair(ownerType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
public bool HasFsm<T>(string name) where T : class
|
||||
{
|
||||
return InternalHasFsm(new TypeNamePair(typeof(T), name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
public bool HasFsm(Type ownerType, string name)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalHasFsm(new TypeNamePair(ownerType, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
public IFsm<T> GetFsm<T>() where T : class
|
||||
{
|
||||
return (IFsm<T>)InternalGetFsm(new TypeNamePair(typeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
public FsmBase GetFsm(Type ownerType)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalGetFsm(new TypeNamePair(ownerType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
public IFsm<T> GetFsm<T>(string name) where T : class
|
||||
{
|
||||
return (IFsm<T>)InternalGetFsm(new TypeNamePair(typeof(T), name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
public FsmBase GetFsm(Type ownerType, string name)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalGetFsm(new TypeNamePair(ownerType, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有有限状态机。
|
||||
/// </summary>
|
||||
/// <returns>所有有限状态机。</returns>
|
||||
public FsmBase[] GetAllFsms()
|
||||
{
|
||||
int index = 0;
|
||||
FsmBase[] results = new FsmBase[m_Fsms.Count];
|
||||
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
|
||||
{
|
||||
results[index++] = fsm.Value;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="results">所有有限状态机。</param>
|
||||
public void GetAllFsms(List<FsmBase> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new GameException("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
|
||||
{
|
||||
results.Add(fsm.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
public IFsm<T> CreateFsm<T>(T owner, params FsmState<T>[] states) where T : class
|
||||
{
|
||||
return CreateFsm(string.Empty, owner, states);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
public IFsm<T> CreateFsm<T>(string name, T owner, params FsmState<T>[] states) where T : class
|
||||
{
|
||||
TypeNamePair typeNamePair = new TypeNamePair(typeof(T), name);
|
||||
if (HasFsm<T>(name))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Already exist FSM '{0}'.", typeNamePair));
|
||||
}
|
||||
|
||||
Fsm<T> fsm = Fsm<T>.Create(name, owner, states);
|
||||
m_Fsms.Add(typeNamePair, fsm);
|
||||
return fsm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
public IFsm<T> CreateFsm<T>(T owner, List<FsmState<T>> states) where T : class
|
||||
{
|
||||
return CreateFsm(string.Empty, owner, states);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
public IFsm<T> CreateFsm<T>(string name, T owner, List<FsmState<T>> states) where T : class
|
||||
{
|
||||
TypeNamePair typeNamePair = new TypeNamePair(typeof(T), name);
|
||||
if (HasFsm<T>(name))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("Already exist FSM '{0}'.", typeNamePair));
|
||||
}
|
||||
|
||||
Fsm<T> fsm = Fsm<T>.Create(name, owner, states);
|
||||
m_Fsms.Add(typeNamePair, fsm);
|
||||
return fsm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm<T>() where T : class
|
||||
{
|
||||
return InternalDestroyFsm(new TypeNamePair(typeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm(Type ownerType)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalDestroyFsm(new TypeNamePair(ownerType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">要销毁的有限状态机名称。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm<T>(string name) where T : class
|
||||
{
|
||||
return InternalDestroyFsm(new TypeNamePair(typeof(T), name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">要销毁的有限状态机名称。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm(Type ownerType, string name)
|
||||
{
|
||||
if (ownerType == null)
|
||||
{
|
||||
throw new GameException("Owner type is invalid.");
|
||||
}
|
||||
|
||||
return InternalDestroyFsm(new TypeNamePair(ownerType, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="fsm">要销毁的有限状态机。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm<T>(IFsm<T> fsm) where T : class
|
||||
{
|
||||
if (fsm == null)
|
||||
{
|
||||
throw new GameException("FSM is invalid.");
|
||||
}
|
||||
|
||||
return InternalDestroyFsm(new TypeNamePair(typeof(T), fsm.Name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="fsm">要销毁的有限状态机。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
public bool DestroyFsm(FsmBase fsm)
|
||||
{
|
||||
if (fsm == null)
|
||||
{
|
||||
throw new GameException("FSM is invalid.");
|
||||
}
|
||||
|
||||
return InternalDestroyFsm(new TypeNamePair(fsm.OwnerType, fsm.Name));
|
||||
}
|
||||
|
||||
private bool InternalHasFsm(TypeNamePair typeNamePair)
|
||||
{
|
||||
return m_Fsms.ContainsKey(typeNamePair);
|
||||
}
|
||||
|
||||
private FsmBase InternalGetFsm(TypeNamePair typeNamePair)
|
||||
{
|
||||
FsmBase fsm = null;
|
||||
if (m_Fsms.TryGetValue(typeNamePair, out fsm))
|
||||
{
|
||||
return fsm;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool InternalDestroyFsm(TypeNamePair typeNamePair)
|
||||
{
|
||||
FsmBase fsm = null;
|
||||
if (m_Fsms.TryGetValue(typeNamePair, out fsm))
|
||||
{
|
||||
fsm.Shutdown();
|
||||
return m_Fsms.Remove(typeNamePair);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmManager.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c51415653769a284da32c47405fe01d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
103
Assets/Axibug/Libraries/Axibug/Fsm/FsmState.cs
Normal file
103
Assets/Axibug/Libraries/Axibug/Fsm/FsmState.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机状态基类。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
public abstract class FsmState<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化有限状态机状态基类的新实例。
|
||||
/// </summary>
|
||||
public FsmState()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机状态初始化时调用。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
protected internal virtual void OnInit(IFsm<T> fsm)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机状态进入时调用。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
protected internal virtual void OnEnter(IFsm<T> fsm)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机状态轮询时调用。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
protected internal virtual void OnUpdate(IFsm<T> fsm, float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机状态离开时调用。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
/// <param name="isShutdown">是否是关闭有限状态机时触发。</param>
|
||||
protected internal virtual void OnLeave(IFsm<T> fsm, bool isShutdown)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有限状态机状态销毁时调用。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
protected internal virtual void OnDestroy(IFsm<T> fsm)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换当前有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
protected void ChangeState<TState>(IFsm<T> fsm) where TState : FsmState<T>
|
||||
{
|
||||
Fsm<T> fsmImplement = (Fsm<T>)fsm;
|
||||
if (fsmImplement == null)
|
||||
{
|
||||
throw new GameException("FSM is invalid.");
|
||||
}
|
||||
|
||||
fsmImplement.ChangeState<TState>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换当前有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="fsm">有限状态机引用。</param>
|
||||
/// <param name="stateType">要切换到的有限状态机状态类型。</param>
|
||||
protected void ChangeState(IFsm<T> fsm, Type stateType)
|
||||
{
|
||||
Fsm<T> fsmImplement = (Fsm<T>)fsm;
|
||||
if (fsmImplement == null)
|
||||
{
|
||||
throw new GameException("FSM is invalid.");
|
||||
}
|
||||
|
||||
if (stateType == null)
|
||||
{
|
||||
throw new GameException("State type is invalid.");
|
||||
}
|
||||
|
||||
if (!typeof(FsmState<T>).IsAssignableFrom(stateType))
|
||||
{
|
||||
throw new GameException(Utility.Text.Format("State type '{0}' is invalid.", stateType.FullName));
|
||||
}
|
||||
|
||||
fsmImplement.ChangeState(stateType);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmState.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/FsmState.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d1866a2a9b1abb4896d9e67fd657fb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
172
Assets/Axibug/Libraries/Axibug/Fsm/IFsm.cs
Normal file
172
Assets/Axibug/Libraries/Axibug/Fsm/IFsm.cs
Normal file
@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机接口。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
public interface IFsm<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取有限状态机名称。
|
||||
/// </summary>
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机完整名称。
|
||||
/// </summary>
|
||||
string FullName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机持有者。
|
||||
/// </summary>
|
||||
T Owner
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机中状态的数量。
|
||||
/// </summary>
|
||||
int FsmStateCount
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否正在运行。
|
||||
/// </summary>
|
||||
bool IsRunning
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机是否被销毁。
|
||||
/// </summary>
|
||||
bool IsDestroyed
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态。
|
||||
/// </summary>
|
||||
FsmState<T> CurrentState
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前有限状态机状态持续时间。
|
||||
/// </summary>
|
||||
float CurrentStateTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要开始的有限状态机状态类型。</typeparam>
|
||||
void Start<TState>() where TState : FsmState<T>;
|
||||
|
||||
/// <summary>
|
||||
/// 开始有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要开始的有限状态机状态类型。</param>
|
||||
void Start(Type stateType);
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要检查的有限状态机状态类型。</typeparam>
|
||||
/// <returns>是否存在有限状态机状态。</returns>
|
||||
bool HasState<TState>() where TState : FsmState<T>;
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要检查的有限状态机状态类型。</param>
|
||||
/// <returns>是否存在有限状态机状态。</returns>
|
||||
bool HasState(Type stateType);
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机状态。
|
||||
/// </summary>
|
||||
/// <typeparam name="TState">要获取的有限状态机状态类型。</typeparam>
|
||||
/// <returns>要获取的有限状态机状态。</returns>
|
||||
TState GetState<TState>() where TState : FsmState<T>;
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机状态。
|
||||
/// </summary>
|
||||
/// <param name="stateType">要获取的有限状态机状态类型。</param>
|
||||
/// <returns>要获取的有限状态机状态。</returns>
|
||||
FsmState<T> GetState(Type stateType);
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机的所有状态。
|
||||
/// </summary>
|
||||
/// <returns>有限状态机的所有状态。</returns>
|
||||
FsmState<T>[] GetAllStates();
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机的所有状态。
|
||||
/// </summary>
|
||||
/// <param name="results">有限状态机的所有状态。</param>
|
||||
void GetAllStates(List<FsmState<T>> results);
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>有限状态机数据是否存在。</returns>
|
||||
bool HasData(string name);
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机数据。
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">要获取的有限状态机数据的类型。</typeparam>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>要获取的有限状态机数据。</returns>
|
||||
TData GetData<TData>(string name) where TData : Variable;
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>要获取的有限状态机数据。</returns>
|
||||
Variable GetData(string name);
|
||||
|
||||
/// <summary>
|
||||
/// 设置有限状态机数据。
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">要设置的有限状态机数据的类型。</typeparam>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <param name="data">要设置的有限状态机数据。</param>
|
||||
void SetData<TData>(string name, TData data) where TData : Variable;
|
||||
|
||||
/// <summary>
|
||||
/// 设置有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <param name="data">要设置的有限状态机数据。</param>
|
||||
void SetData(string name, Variable data);
|
||||
|
||||
/// <summary>
|
||||
/// 移除有限状态机数据。
|
||||
/// </summary>
|
||||
/// <param name="name">有限状态机数据名称。</param>
|
||||
/// <returns>是否移除有限状态机数据成功。</returns>
|
||||
bool RemoveData(string name);
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/IFsm.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/IFsm.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c32db6178847ec048b68011a9fa700d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
174
Assets/Axibug/Libraries/Axibug/Fsm/IFsmManager.cs
Normal file
174
Assets/Axibug/Libraries/Axibug/Fsm/IFsmManager.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axibug.Fsm
|
||||
{
|
||||
/// <summary>
|
||||
/// 有限状态机管理器。
|
||||
/// </summary>
|
||||
public interface IFsmManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取有限状态机数量。
|
||||
/// </summary>
|
||||
int Count
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
bool HasFsm<T>() where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
bool HasFsm(Type ownerType);
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
bool HasFsm<T>(string name) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>是否存在有限状态机。</returns>
|
||||
bool HasFsm(Type ownerType, string name);
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
IFsm<T> GetFsm<T>() where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
FsmBase GetFsm(Type ownerType);
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
IFsm<T> GetFsm<T>(string name) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <returns>要获取的有限状态机。</returns>
|
||||
FsmBase GetFsm(Type ownerType, string name);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有有限状态机。
|
||||
/// </summary>
|
||||
/// <returns>所有有限状态机。</returns>
|
||||
FsmBase[] GetAllFsms();
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="results">所有有限状态机。</param>
|
||||
void GetAllFsms(List<FsmBase> results);
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
IFsm<T> CreateFsm<T>(T owner, params FsmState<T>[] states) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
IFsm<T> CreateFsm<T>(string name, T owner, params FsmState<T>[] states) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
IFsm<T> CreateFsm<T>(T owner, List<FsmState<T>> states) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 创建有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">有限状态机名称。</param>
|
||||
/// <param name="owner">有限状态机持有者。</param>
|
||||
/// <param name="states">有限状态机状态集合。</param>
|
||||
/// <returns>要创建的有限状态机。</returns>
|
||||
IFsm<T> CreateFsm<T>(string name, T owner, List<FsmState<T>> states) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm<T>() where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm(Type ownerType);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="name">要销毁的有限状态机名称。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm<T>(string name) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="ownerType">有限状态机持有者类型。</param>
|
||||
/// <param name="name">要销毁的有限状态机名称。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm(Type ownerType, string name);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
|
||||
/// <param name="fsm">要销毁的有限状态机。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm<T>(IFsm<T> fsm) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 销毁有限状态机。
|
||||
/// </summary>
|
||||
/// <param name="fsm">要销毁的有限状态机。</param>
|
||||
/// <returns>是否销毁有限状态机成功。</returns>
|
||||
bool DestroyFsm(FsmBase fsm);
|
||||
}
|
||||
}
|
11
Assets/Axibug/Libraries/Axibug/Fsm/IFsmManager.cs.meta
Normal file
11
Assets/Axibug/Libraries/Axibug/Fsm/IFsmManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d84fdf0c321f484a920fdc255a7982a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user