准备对粒子效果等生成性效果进行优化

This commit is contained in:
2025-12-04 17:51:00 +08:00
parent 59183167cc
commit 3d83ae0837
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using Convention;
using Convention.Experimental.Modules;
using System;
using System.Collections.Generic;
using static Convention.Experimental.Architecture;
namespace Demo.Game
{
public class GameObjectPool : MonoSingleton<GameObjectPool>
{
private Dictionary<Func<ScriptableObject>, ScriptableObject> Pool = new();
public ScriptableObject Spawn(Func<ScriptableObject> creater)
{
if (Pool.TryGetValue(creater, out var prefab) == false)
{
prefab = Pool[creater] = creater();
prefab.gameObject.SetActive(false);
prefab.transform.SetParent(transform);
}
if (prefab is CameraObject)
{
return prefab;
}
else
{
var result = GetModule<GameObjectPoolManager>().Spawn(prefab.gameObject).GetComponent<ScriptableObject>();
result.gameObject.SetActive(true);
return result;
}
}
public void Unspawn(ScriptableObject obj)
{
if (obj is CameraObject camera)
{
camera.gameObject.SetActive(false);
camera.transform.SetParent(transform);
}
else if (obj is RootObject)
return;
else
{
GetModule<GameObjectPoolManager>().Unspawn(obj.gameObject);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 94ffe9340adcc294c9d67b9f0bb825eb