简单对象池
来源:互联网 发布:wix链接国内域名 编辑:程序博客网 时间:2024/06/01 09:23
///// <summary> ///// 放在对象池里面的对象必须实现的接口 ///// </summary> //public interface IPoolObject //{ // /// <summary> // /// Object初始化时调用 // /// </summary> // void Init(); // /// <summary> // /// Object回收时调用 // /// </summary> // void Release(); //} //using UnityEngine; //using System.Collections; //public class BasePoolObject : MonoBehaviour, IPoolObject //{ // public void Init() // { // Debug.Log("初始化对象,比如位置"); // } // public void Release() // { // Debug.Log("释放对象"); // } //} //using UnityEngine; //using System.Collections; //using System.Collections.Generic; //public class ObjectPool : MonoBehaviour //{ // /// <summary> // /// 预生成的个数 // /// </summary> // public int preNum; // /// <summary> // /// 对象列表 // /// </summary> // public Queue<GameObject> pool = new Queue<GameObject>(); // /// <summary> // ///要放入的对象的预置 // /// </summary> // public GameObject poolObjectPefab; // void InitPool() // { // for (int i = 0; i < preNum; i++) // { // GameObject obj = GameObject.Instantiate(poolObjectPefab); // IPoolObject comp = obj.GetComponent<IPoolObject>(); // if (comp == null) // { // Debug.LogError("预置上必须绑有实现了IPoolObject接口的类"); // } // comp.Init(); // pool.Enqueue(obj); // obj.SetActive(false); // } // } // /// <summary> // /// 创建一个对象 // /// </summary> // /// <returns>从池里取出对象.</returns> // public GameObject RequestObject() // { // GameObject obj; // if (pool.Count != 0) // { // obj = pool.Dequeue(); // } // else // { // obj = GameObject.Instantiate(poolObjectPefab); // } // IPoolObject comp = obj.GetComponent<IPoolObject>(); // if (comp == null) // { // Debug.LogError("预置上必须绑有实现了IPoolObject接口的类"); // } // obj.SetActive(true); // comp.Init(); // return obj; // } // /// <summary> // /// 回收对象 // /// </summary> // /// <param name="obj">Object.</param> // public void RecoverObject(GameObject obj) // { // IPoolObject comp = obj.GetComponent<IPoolObject>(); // if (comp == null) // { // Debug.LogError("预置上必须绑有实现了IPoolObject接口的类"); // } // pool.Enqueue(obj); // comp.Release(); // obj.SetActive(false); // } // void Awake() // { // InitPool(); // } //}
0 0
- 简单对象池
- 对象池简单理解
- 简单实现对象池
- 一个简单的对象池
- 一个简单的对象池
- 简单的内存对象池
- 简单的对象池实现
- Unity 对象池简单使用
- Golang简单的对象池
- Unity_简单对象池_032
- 简单易懂的对象池
- 一个简单的java专用对象池
- AS3中简单的一般对象池
- C++实现简单的对象池
- 简单的对象池技术实现 DEMO
- 对象池的应用的简单Demo
- 【Unity开发】简单的对象池实现
- 基于Unity引擎的简单对象池
- 简单工厂模式 (Simple Factory Pattern) / 静态工厂方法(Static Factory Method)模式
- nginx安装
- Spring中IoC的入门实例
- 外观模式/门面模式
- 观察者模式 /发布-订阅(Publish/Subscribe)/模型-视图(Model/View)/源-监听器(Source/Listener)/从属者(Dependents) 模式
- 简单对象池
- (spring-第4回【IoC基础篇】)spring基于注解的配置
- 今年不要考虑钱的事情
- Spring学习3—控制反转(IOC)基于Annotation(注解)的依赖注入实现
- Android 6.0 动态权限申请
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- C++ primer 第五版 12.3文本查询程序完整版
- 比特币源码学习笔记(一)
- 从SHAttered事件谈安全