新增实验框架

This commit is contained in:
2025-11-14 17:13:10 +08:00
parent 1a28eb62a8
commit 6d72129bae
4 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace Convention.Experimental.Modules
{
public class ConfigManager : PublicType.GameModule
{
public readonly ProjectConfig m_ProjectConfig = new();
public bool IsSavePropertiesWhenShutdown = false;
internal override void Shutdown()
{
if (IsSavePropertiesWhenShutdown)
m_ProjectConfig.SaveProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eae9830d96a5f184b832846bf67c4b59
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using System.Collections.Generic;
using UnityEngine;
namespace Convention.Experimental.Modules
{
public class ObjectPoolManager : PublicType.GameModule
{
public interface IPawn
{
void Release();
}
private readonly Dictionary<GameObject, Stack<GameObject>> ObjectPools = new();
private readonly Dictionary<GameObject, GameObject> LeavePoolObjects = new();
public GameObject Spawn(GameObject prefab)
{
if (!ObjectPools.ContainsKey(prefab))
{
ObjectPools[prefab] = new();
}
var pool = ObjectPools[prefab];
GameObject instance;
if (pool.Count > 0)
{
instance = pool.Pop();
instance.SetActive(true);
instance.transform.SetParent(null);
}
else
{
instance = GameObject.Instantiate(prefab);
}
LeavePoolObjects[instance] = prefab;
return instance;
}
public void BackPool(GameObject instance)
{
if(LeavePoolObjects.TryGetValue(instance,out var prefab))
{
var releaser = instance.GetComponents<IPawn>();
foreach (var r in releaser)
{
r.Release();
}
instance.SetActive(false);
instance.transform.SetParent(ConventionUtility.Singleton.transform);
ObjectPools[prefab].Push(instance);
LeavePoolObjects.Remove(instance);
}
else
{
throw new PublicType.GameException("This object does not belong to any pool.");
}
}
public void ClearPool(GameObject prefab)
{
if (ObjectPools.TryGetValue(prefab, out var pool))
{
while (pool.Count > 0)
{
var instance = pool.Pop();
GameObject.Destroy(instance);
}
}
else
{
throw new PublicType.GameException("This pool does not exist.");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 912f3c1afd07d714d83cd965f3a0f7e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: