新增实验框架
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
using Convention;
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using Convention.Experimental.PublicType;
|
using Convention.Experimental.PublicType;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Convention.Experimental
|
namespace Convention.Experimental
|
||||||
{
|
{
|
||||||
@@ -16,14 +13,23 @@ namespace Convention.Experimental
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="moduleType">Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/><3E><><EFBFBD><EFBFBD></param>
|
/// <param name="moduleType">Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/><3E><><EFBFBD><EFBFBD></param>
|
||||||
/// <returns>Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/></returns>
|
/// <returns>Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/></returns>
|
||||||
private static GameModule CreateModule(Type moduleType)
|
private static GameModule CreateModule(Type moduleType, int stackLayer = 0)
|
||||||
{
|
{
|
||||||
|
if (stackLayer >= 100)
|
||||||
|
{
|
||||||
|
throw new GameException($"Create module '{moduleType.FullName}' failed, recursion too deep, there may be a circular dependency.");
|
||||||
|
}
|
||||||
|
|
||||||
GameModule module = (GameModule)Activator.CreateInstance(moduleType);
|
GameModule module = (GameModule)Activator.CreateInstance(moduleType);
|
||||||
if (module == null)
|
if (module == null)
|
||||||
{
|
{
|
||||||
throw new GameException($"Can not create module '{moduleType.FullName}'");
|
throw new GameException($"Can not create module '{moduleType.FullName}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <20>ݹ鴴<DDB9><E9B4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||||
|
foreach (var dependenceType in module.Dependences())
|
||||||
|
_ = GetModule(dependenceType, stackLayer + 1);
|
||||||
|
|
||||||
LinkedListNode<GameModule> current = s_GameFrameworkModules.First;
|
LinkedListNode<GameModule> current = s_GameFrameworkModules.First;
|
||||||
while (current != null)
|
while (current != null)
|
||||||
{
|
{
|
||||||
@@ -53,7 +59,7 @@ namespace Convention.Experimental
|
|||||||
/// <param name="moduleType">Ҫ<><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/></param>
|
/// <param name="moduleType">Ҫ<><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/></param>
|
||||||
/// <returns>Ҫ<><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/></returns>
|
/// <returns>Ҫ<><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/></returns>
|
||||||
/// <remarks><3E><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/><3E><><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/>ʵ<><CAB5><EFBFBD><EFBFBD></remarks>
|
/// <remarks><3E><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><see cref="GameModule"/><3E><><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><see cref="GameModule"/>ʵ<><CAB5><EFBFBD><EFBFBD></remarks>
|
||||||
private static GameModule GetModule(Type moduleType)
|
private static GameModule GetModule(Type moduleType, int stackLayer = 0)
|
||||||
{
|
{
|
||||||
foreach (GameModule module in s_GameFrameworkModules)
|
foreach (GameModule module in s_GameFrameworkModules)
|
||||||
{
|
{
|
||||||
@@ -63,7 +69,7 @@ namespace Convention.Experimental
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateModule(moduleType);
|
return CreateModule(moduleType, stackLayer + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
8
Convention/[Architecture]/Modules.meta
Normal file
8
Convention/[Architecture]/Modules.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 591a2c63cd01a22408284eeaa811e930
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Convention.Experimental.PublicType
|
namespace Convention.Experimental.PublicType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ࡣ
|
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GameModule
|
public abstract class GameModule
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><>ȡ<EFBFBD><C8A1>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD><EFBFBD>
|
/// <20><>ȡ<EFBFBD><C8A1>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks><3E><><EFBFBD>ȼ<EFBFBD><C8BC>ϸߵ<CFB8>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>ҹرղ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD></remarks>
|
/// <remarks><3E><><EFBFBD>ȼ<EFBFBD><C8BC>ϸߵ<CFB8>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD>ϵ͵<EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD></remarks>
|
||||||
internal virtual int Priority
|
internal virtual int Priority
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -22,15 +21,20 @@ namespace Convention.Experimental.PublicType
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>
|
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ѯ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="elapseSeconds"><3E><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><EFBFBD></param>
|
/// <param name="elapseSeconds"><3E><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ</param>
|
||||||
/// <param name="realElapseSeconds"><3E><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><EFBFBD></param>
|
/// <param name="realElapseSeconds"><3E><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ</param>
|
||||||
internal abstract void Update(float elapseSeconds, float realElapseSeconds);
|
internal virtual void Update(float elapseSeconds, float realElapseSeconds) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20>رղ<D8B1><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD>顣
|
/// <20>رղ<D8B1><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract void Shutdown();
|
internal virtual void Shutdown() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
internal virtual IEnumerable<Type> Dependences() => Array.Empty<Type>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
491
Convention/[Architecture]/PublicType/ReferencePool.cs
Normal file
491
Convention/[Architecture]/PublicType/ReferencePool.cs
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Unity.VisualScripting;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Convention.Experimental.PublicType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD>ýӿڡ<D3BF>
|
||||||
|
/// </summary>
|
||||||
|
public interface IReference
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
void Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD>ó<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public static partial class ReferencePool
|
||||||
|
{
|
||||||
|
private static bool m_EnableStrictCheck = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public static bool EnableStrictCheck
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_EnableStrictCheck;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
m_EnableStrictCheck = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Dictionary<Type, ReferenceCollection> s_ReferenceCollections = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>óص<C3B3><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public static int Count
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return s_ReferenceCollections.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD>Ϣ
|
||||||
|
/// </summary>
|
||||||
|
[StructLayout(LayoutKind.Auto)]
|
||||||
|
public readonly struct ReferencePoolInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly Type Type;
|
||||||
|
/// <summary>
|
||||||
|
/// δʹ<CEB4><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int UnusedReferenceCount;
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int UsingReferenceCount;
|
||||||
|
/// <summary>
|
||||||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int AcquireReferenceCount;
|
||||||
|
/// <summary>
|
||||||
|
/// <20>黹<EFBFBD><E9BBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int ReleaseReferenceCount;
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int AddReferenceCount;
|
||||||
|
/// <summary>
|
||||||
|
/// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public readonly int RemoveReferenceCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"><3E><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>͡<EFBFBD></param>
|
||||||
|
/// <param name="unusedReferenceCount">δʹ<CEB4><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="usingReferenceCount"><3E><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="acquireReferenceCount"><3E><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="releaseReferenceCount"><3E>黹<EFBFBD><E9BBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="addReferenceCount"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="removeReferenceCount"><3E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
public ReferencePoolInfo(Type type,
|
||||||
|
int unusedReferenceCount,
|
||||||
|
int usingReferenceCount,
|
||||||
|
int acquireReferenceCount,
|
||||||
|
int releaseReferenceCount,
|
||||||
|
int addReferenceCount,
|
||||||
|
int removeReferenceCount)
|
||||||
|
{
|
||||||
|
this.Type = type;
|
||||||
|
this.UnusedReferenceCount = unusedReferenceCount;
|
||||||
|
this.UsingReferenceCount = usingReferenceCount;
|
||||||
|
this.AcquireReferenceCount = acquireReferenceCount;
|
||||||
|
this.ReleaseReferenceCount = releaseReferenceCount;
|
||||||
|
this.AddReferenceCount = addReferenceCount;
|
||||||
|
this.RemoveReferenceCount = removeReferenceCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>óص<C3B3><D8B5><EFBFBD>Ϣ
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>óص<C3B3><D8B5><EFBFBD>Ϣ</returns>
|
||||||
|
public static ReferencePoolInfo[] GetAllReferencePoolInfos()
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
ReferencePoolInfo[] results = null;
|
||||||
|
|
||||||
|
lock (s_ReferenceCollections)
|
||||||
|
{
|
||||||
|
results = new ReferencePoolInfo[s_ReferenceCollections.Count];
|
||||||
|
foreach (var (key,value) in s_ReferenceCollections)
|
||||||
|
{
|
||||||
|
results[index++] = new ReferencePoolInfo(key,
|
||||||
|
value.UnusedReferenceCount,
|
||||||
|
value.UsingReferenceCount,
|
||||||
|
value.AcquireReferenceCount,
|
||||||
|
value.ReleaseReferenceCount,
|
||||||
|
value.AddReferenceCount,
|
||||||
|
value.RemoveReferenceCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public static void ClearAll()
|
||||||
|
{
|
||||||
|
lock (s_ReferenceCollections)
|
||||||
|
{
|
||||||
|
foreach (var (_, value) in s_ReferenceCollections)
|
||||||
|
{
|
||||||
|
value.RemoveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
s_ReferenceCollections.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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($"Reference type '{referenceType.FullName}' is invalid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>óػ<C3B3>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceType"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <returns><3E><><EFBFBD><EFBFBD></returns>
|
||||||
|
public static IReference Acquire(Type referenceType)
|
||||||
|
{
|
||||||
|
InternalCheckReferenceType(referenceType);
|
||||||
|
return GetReferenceCollection(referenceType).Acquire();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>óػ<C3B3>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
||||||
|
/// <returns><3E><><EFBFBD><EFBFBD></returns>
|
||||||
|
public static T Acquire<T>() where T : class, IReference, new()
|
||||||
|
{
|
||||||
|
return GetReferenceCollection(typeof(T)).Acquire<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ù黹<C3B9><E9BBB9><EFBFBD>ó<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reference"><3E><><EFBFBD><EFBFBD></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>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><D7B7>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
||||||
|
/// <param name="count"><><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
public static void Add<T>(int count) where T : class, IReference, new()
|
||||||
|
{
|
||||||
|
GetReferenceCollection(typeof(T)).Add<T>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><D7B7>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceType"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="count"><><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
public static void Add(Type referenceType, int count)
|
||||||
|
{
|
||||||
|
InternalCheckReferenceType(referenceType);
|
||||||
|
GetReferenceCollection(referenceType).Add(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ƴ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
||||||
|
/// <param name="count"><3E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
public static void Remove<T>(int count) where T : class, IReference
|
||||||
|
{
|
||||||
|
GetReferenceCollection(typeof(T)).Remove(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ƴ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceType"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
/// <param name="count"><3E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD></param>
|
||||||
|
public static void Remove(Type referenceType, int count)
|
||||||
|
{
|
||||||
|
InternalCheckReferenceType(referenceType);
|
||||||
|
GetReferenceCollection(referenceType).Remove(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
||||||
|
public static void RemoveAll<T>() where T : class, IReference
|
||||||
|
{
|
||||||
|
GetReferenceCollection(typeof(T)).RemoveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>á<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceType"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD></param>
|
||||||
|
public static void RemoveAll(Type referenceType)
|
||||||
|
{
|
||||||
|
InternalCheckReferenceType(referenceType);
|
||||||
|
GetReferenceCollection(referenceType).RemoveAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Convention/[Architecture]/PublicType/ReferencePool.cs.meta
Normal file
11
Convention/[Architecture]/PublicType/ReferencePool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7a8ec3e4cc6e7e242b158fc02010c774
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1285,6 +1285,7 @@ namespace Convention
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static CoroutineMonoStarterUtil CoroutineStarter;
|
private static CoroutineMonoStarterUtil CoroutineStarter;
|
||||||
|
public static GameObject Singleton => CoroutineStarter.gameObject;
|
||||||
|
|
||||||
private class CoroutineMonoStarterUtil : MonoBehaviour
|
private class CoroutineMonoStarterUtil : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user