新增实验框架
This commit is contained in:
17
Convention/[Architecture]/Modules/ConfigManager.cs
Normal file
17
Convention/[Architecture]/Modules/ConfigManager.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Convention/[Architecture]/Modules/ConfigManager.cs.meta
Normal file
11
Convention/[Architecture]/Modules/ConfigManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eae9830d96a5f184b832846bf67c4b59
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
74
Convention/[Architecture]/Modules/ObjectPoolManager.cs
Normal file
74
Convention/[Architecture]/Modules/ObjectPoolManager.cs
Normal 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Convention/[Architecture]/Modules/ObjectPoolManager.cs.meta
Normal file
11
Convention/[Architecture]/Modules/ObjectPoolManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 912f3c1afd07d714d83cd965f3a0f7e4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user