当前位置: 首页 > news >正文

unity自己对象池的使用

unity出了自己的对象池 这里记录一下用法

  • 命名空间就是这个
    在这里插入图片描述

  • 一般有两种用法,第一种是在using里面获取,脱离这个域就释放。第二种是在Get和Release配合使用

 // This version will only be returned to the pool if we call Release on it.//只有使用Release才会释放var simplifiedPoints = ListPool<Vector2>.Get();
//这种只要脱离了Scope就会自动释放// Copy the points into a temp list so we can pass them into the Simplify method// When the pooled object leaves the scope it will be Disposed and returned to the pool automatically.// This version is ideal for working with temporary lists.using (var pooledObject = ListPool<Vector2>.Get(out List<Vector2> tempList)){for (int i = 0; i < points.Length; ++i){tempList.Add(points[i]);}LineUtility.Simplify(tempList, 1.5f, simplifiedPoints);}return simplifiedPoints;
  • 一般比较常用的就几个集合类和下面这个,可以对自己的类进行一个池子回收。
using UnityEngine.Pool;public class GenericPoolExample
{class MyClass{public int someValue;public string someString;}void GetPooled(){// Get an instancevar instance = GenericPool<MyClass>.Get();// Return the instanceGenericPool<MyClass>.Release(instance);}
}
  • 对于一些unity中的GameObject对象可以使用ObjectPool
http://www.lryc.cn/news/173952.html

相关文章:

  • el-image 和 el-table冲突层级冲突问题
  • 6年Android开发前10月的总结,写给正在求职的安卓开发
  • ConcurrentHashMap 的并发度是什么?
  • Redis 面霸篇:从高频问题透视核心原理
  • 【100天精通Python】Day69:Python可视化_实战:导航定位中预测轨迹和实际轨迹的3D动画,示例+代码
  • MySQL中对varchar类型的列进行统计分析
  • mysql索引最左前缀法则、使用场景
  • LeetCode75-06:移动零
  • C/C++统计满足条件的4位数个数 2023年5月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
  • python+nodejs+php+springboot+vue 校园安全车辆人员出入安全管理系统
  • 针对discuz3.2的渗透测试
  • python的中秋之美
  • ClickHouse与Elasticsearch比较总结
  • 辅助驾驶功能开发-功能对标篇(12)-NOA领航辅助系统-合众
  • Vue项目中使用element-plus的el-table组件-组件使用-样式修改
  • JavaBean字符串训练(支票大写)
  • Java 核心技术卷 I —— 第2章 Java 编程环境
  • 外汇天眼:英国FCA引入新规定,强化金融广告审核标准!
  • 【python】Seaborn画热力图,只显示第一行数字---seaborn与matplotlib版本问题
  • VMware CentOS7 Docker入门
  • C++ Primer 第5章 语句
  • 【C++】bitset位图的简单模拟实现及常见面试题
  • 十六、MySql的MVCC机制CONNECT(收官!)
  • 194、SpringBoot -- 下载和安装 Erlang 、 RabbitMQ
  • Linux0.11——第二回 从0x7c00到0x90000
  • 封装了一个中间放大效果的iOS轮播视图
  • 趣解设计模式之《小王的糖果售卖机》
  • Redis 哨兵模式模式搭建教程
  • 41. Linux系统配置FTP服务器并在QT中使用QFtp实现文件上传
  • 【新版】系统架构设计师 - 案例分析 - 架构设计<架构风格和质量属性>