Unity 对象池之ObjectPool
来源:互联网 发布:淘宝听诊器 编辑:程序博客网 时间:2024/06/04 19:17
using System;using System.Collections.Generic;using UnityEngine;using System.Text;public class ObjectPool{ //资源目录 public string ResourseDir = ""; //字典 Dictionary<string, SubPool> m_pools = new Dictionary<string, SubPool>(); //取对象 public GameObject Spwan(string name) { if(!m_pools.ContainsKey(name)) { RegisterNew(name); } SubPool pool = m_pools[name]; return pool.OnSpwan(); } //回收对象 public void UnSpawn(GameObject go) { SubPool pool = null; foreach(SubPool p in m_pools.Values) { if(p.Contains(go)) { pool = p; break; } } pool.OnUnSpwan(go); } //回收所有对象 public void UnSpwanAll() { foreach(SubPool p in m_pools.Values) { p.SwpanAll(); } } //创建新子对象池 void RegisterNew(string name) { //预设路径 string Path = ""; if (string.IsNullOrEmpty(ResourseDir)) { Path = name; } else { Path = "/" + name; } //加载预设 GameObject perfab = Resources.Load<GameObject>(Path); //创建子对象池 SubPool pool = new SubPool(perfab); m_pools.Add(pool.Name, pool); }}
阅读全文
0 0
- Unity 对象池之ObjectPool
- Unity 内存管理之 ObjectPool
- Unity 内存管理之 ObjectPool
- ObjectPool 对象池程序
- java对象池ObjectPool
- java对象池ObjectPool
- Unity优化之ObjectPool-关于初始化
- Unity3d中对象池(ObjectPool)的实现
- 什么情况下应该使用对象池(ObjectPool)
- Unity3d中对象池(ObjectPool)的实现思路
- 使用对象池(ObjectPool)方式处理子弹的发射逻辑
- Unity3d中对象池(ObjectPool)的概念和用法
- Unity3D对象池技术(ObjectPool)小例子
- Common(十四)—— ObjectPool对象池
- UNITY之对象池
- ObjectPool
- ObjectPool
- ObjectPool
- jQuery()和$()区别?
- (重要)游山有感2017.10.17
- C++切换windows默认音频设备 (播放或录制)
- [ 数据结构 ] DS链表—学生宿舍管理
- springmvc对RESTful支持
- Unity 对象池之ObjectPool
- virsh的详细命令解析
- pip 安装任意库时,均出现一个ASCII编码的问题
- 银魂
- Systemd 入门与实战
- 51NOD 1419
- 文档字符串
- 阿里云高级技术专家空见: CDN的数据化之路
- day71_oracle01笔记