unity资源池
发布时间
阅读量:
阅读量
在软件开发实践中,常常会面临需要高频生成特定对象(例如常见的怪物或子弹等)的情形。为有效降低系统资源的消耗,推荐采用对象池机制进行优化。
其核心理念在于:通过重复利用已有对象,从而避免频繁初始化与销毁操作所带来的性能开销。
具体实现方式为:当需要使用对象时,从对象池中获取;在使用完毕后,将其重新归还至池中。
//一版
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**对象池*/
public class TerrainPool
{
//单例
private static TerrainPool instance;
public static TerrainPool GetInstance()
{
if (instance == null)
{
instance = new TerrainPool();
}
return instance
全部评论 (0)
还没有任何评论哟~
