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

站长之家alexa排名怎么看什么什么设计英文网站

站长之家alexa排名怎么看,什么什么设计英文网站,网上引流推广怎么做,西安网站前言 之前写过一篇关于对象池的文章#xff0c;现在来看写的并不是很好#xff0c;所以来考虑优化下。 现在来看一年前写的代码#xff0c;越看越不能入目hhh Unity学习笔记–如何优雅简便地利用对象池生成游戏对象 前置知识 Unity学习笔记–使用 C# 开发一个 LRU 代码实…前言 之前写过一篇关于对象池的文章现在来看写的并不是很好所以来考虑优化下。 现在来看一年前写的代码越看越不能入目hhh Unity学习笔记–如何优雅简便地利用对象池生成游戏对象 前置知识 Unity学习笔记–使用 C# 开发一个 LRU 代码实现 PoolManager.cs using System; using System.Collections.Generic; using Factory;namespace ToolManager {public class PoolManager{private Dictionarystring, LinkedListNodeTuplestring, Pool lru_dict; // Key : pool_name obj_nameprivate LinkedListTuplestring, Pool cache;private int capacity;public PoolManager(int capacity_in 64){capacity capacity_in;cache new LinkedListTuplestring, Pool();lru_dict new Dictionarystring, LinkedListNodeTuplestring, Pool();}public bool HasPool(string path){return lru_dict.ContainsKey(path);}public bool AddPool(BaseFactory factory, int init_count 0){string pool_name factory.GetObjPath();if (HasPool(pool_name)){return false;}Pool pool new Pool(this, pool_name, factory, init_count);LinkedListNodeTuplestring, Pool node new LinkedListNodeTuplestring, Pool(Tuple.Create(pool_name, pool));LRUAdd(node);return true;}public bool DelPool(string name){if (!HasPool(name)){return false;}var node lru_dict[name];GetPool(node).ReleasePool();LRURemove(node);return true;}public object PopOne(string name){object res null;if (HasPool(name)){var node lru_dict[name];LRUChange(node);Pool pool GetPool(node);res pool.PopOne();LRURemove(node);}return res;}public object[] Pop(string name, int count){object[] res null;if (HasPool(name)){var node lru_dict[name];LRUChange(node);Pool pool GetPool(node);res pool.Pop(count);LRURemove(node);}return res;}public void PushOne(string name, object obj){if (HasPool(name)){var node lru_dict[name];LRUChange(node);GetPool(node).PushOne(obj);RefreshLRU();}}public void Push(string name, object[] objs){if (HasPool(name)){var node lru_dict[name];LRUChange(node);GetPool(node).Push(objs);RefreshLRU();}}private Pool GetPool(LinkedListNodeTuplestring, Pool node){return node.Value.Item2;}// ------------------------- LRU Function -------------------------private void LRUChange(LinkedListNodeTuplestring, Pool node){cache.Remove(node);cache.AddLast(node);}private void LRUAdd(LinkedListNodeTuplestring, Pool node){lru_dict.Add(node.Value.Item1, node);cache.AddLast(node);}private void LRURemove(LinkedListNodeTuplestring, Pool node){cache.Remove(node);lru_dict.Remove(node.Value.Item1);}private void RefreshLRU(){int lru_count LRUCacheCount;while (lru_count capacity){Pool pool GetPool(cache.First);int n_objects_to_remove Math.Min(pool.PoolCount, lru_count - capacity);for (int i 0; i n_objects_to_remove; i){pool.ReleaseOne();}if(pool.PoolCount 0){DelPool(pool.pool_name);}lru_count LRUCacheCount;}}private int LRUCacheCount{get{int count 0;foreach (var node in lru_dict.Values){count node.Value.Item2.PoolCount;}return count;}}private class Pool{private PoolManager pool_mgr;private BaseFactory factory;private Queueobject queue;public string pool_name;public Pool(PoolManager pool_mgr_in, string pool_name_in, BaseFactory factory_in, int init_count_in){pool_mgr pool_mgr_in;pool_name pool_name_in;factory factory_in;queue new Queueobject();InitPool(init_count_in);}private void InitPool(int init_count){for (int i 0; i init_count; i){queue.Enqueue(factory.CreateObject());}}public void ReleasePool(){foreach (var obj in queue){factory.DestroyObject(obj);}queue.Clear();factory.ReleaseFactory();}public object PopOne(){if (queue.Count 0){object obj queue.Dequeue();factory.ResetObject(obj);return obj;}return factory.CreateObject();}public object[] Pop(int count){object[] objs new object[count];for (int i 0; i count; i){objs[i] PopOne();}return objs;}public void PushOne(object obj){factory.RecycleObject(obj);queue.Enqueue(obj);}public void Push(object[] objs){foreach (var obj in objs){PushOne(obj);}}public void ReleaseOne(){factory.DestroyObject(queue.Dequeue());}public int PoolCount { get queue.Count; }}} } BaseFactory.cs namespace Factory {public abstract class BaseFactory{protected string obj_path;public BaseFactory(string obj_path_in){obj_path obj_path_in;}public abstract object CreateObject();public abstract void ResetObject(object obj);public abstract void RecycleObject(object obj);public abstract void DestroyObject(object obj);public abstract void ReleaseFactory();public virtual string GetObjPath(){return obj_path;}} }使用 创建 Factory using Factory;public class BulletFactory : BaseFactory {public BulletFactory(string obj_path_in) : base(obj_path_in){}public override object CreateObject(){Bullet bullet new Bullet(obj_path);bullet.ReuseInit();return bullet;}public override void DestroyObject(object obj){((Bullet)obj).Destroy();}public override void RecycleObject(object obj){((Bullet)obj).Recycle();}public override void ReleaseFactory(){}public override void ResetObject(object obj){((Bullet)obj).ReuseInit();} } 创建 object using System.Collections; using System.Collections.Generic; using UnityEngine;public class Bullet {private GameObject go;private string path;private static GameObject prefab;public Bullet(string path_in){path path_in;if (prefab null){prefab (GameObject) Resources.Load(path);}}public void ReuseInit(){if (go){go.SetActive(true);}else{go GameObject.Instantiate(prefab);}go.GetComponentRecycleMe().DelayCall(1, Func);}public void Destroy(){GameObject.Destroy(go);}public void Recycle(){go.SetActive(false);}private void Func(){BulletManager.Ins.PushOne(path, this);} } 创建 BulletManager BulletManager.cs using System.Collections; using System.Collections.Generic; using UnityEngine; using ToolManager;public class BulletManager : MonoBehaviour {private PoolManager pool_mgr;private static BulletManager _ins;public static BulletManager Ins{get _ins;}private void Awake(){Init();}private void Init(){_ins this;pool_mgr new PoolManager();}public void PushOne(string path, Bullet obj){if (!pool_mgr.HasPool(path)){pool_mgr.AddPool(new BulletFactory(path));}pool_mgr.PushOne(path, obj);}public Bullet PopOne(string path){if (!pool_mgr.HasPool(path)){pool_mgr.AddPool(new BulletFactory(path));}Bullet bullet (Bullet)pool_mgr.PopOne(path);return bullet;} } 验证 为了验证我写了一个 ShootManager.cs using System.Collections; using System.Collections.Generic; using UnityEngine;public class ShootManager : MonoBehaviour {private ListBullet bullet_list;private string path Bullet;private static ShootManager _ins;public static ShootManager Ins{get _ins;}private void Awake(){Init();}private void Init(){_ins this;bullet_list new ListBullet();}private void Update(){if (Input.GetMouseButtonDown(0)){bullet_list.Add(BulletManager.Ins.PopOne(path));}} } 创建之后过 1s 之后回收自己。 RecycleMe.cs using System; using System.Collections; using System.Collections.Generic; using UnityEngine;public class RecycleMe : MonoBehaviour {public void DelayCall(float delay, Action func){StartCoroutine(DestroyAfterDelayCoroutine(delay, func));}IEnumerator DestroyAfterDelayCoroutine(float delay, Action func){yield return new WaitForSeconds(delay);func.Invoke();}} 效果 LRUPool
http://www.hkea.cn/news/14540832/

相关文章:

  • 网站开发员的工作内容wordpress与阿里服务器区分
  • 广州网站建设与实验重庆百度网络推广
  • 自助广告位网站源码wordpress粒子插件
  • 移动网站制作公司小程序制作一个需要多少钱?
  • 福州网站制作公司做宣传 为什么要做网站那
  • 网络游戏加盟合作郑州官网seo技术
  • 云南建设厅和网站免费怎么制作公司网站
  • 做网页收款网站家政类网站开发成本
  • 马关住房和城乡建设局网站什么类型客户做网站
  • wordpress更改站点ip网站发展阶段怎么做
  • 万网放网站万互网站建站
  • 南京个人做网站网站建设的公司好做吗
  • 自己做的网站怎么放上网工作态度
  • 安达市建设局网站大数据营销的典型案例
  • 网站源码建站教程网页设计与制作考试试题及答案
  • 制作网页和网站有啥不同安装文件出现乱码
  • 站群论坛iis 建设网站
  • 网站开发框架拓扑妇科医生免费咨询
  • 如何做好外贸网站建设企业网站建设综合实训学习体会
  • 长春做企业网站多少钱有什么网站可以做投票功能
  • 在一个网站上面发布广告怎么做最近网站不收录
  • 演讲网站开发背景手机网站用什么程序做
  • vs2010 c 网站开发tag 网站托管公司
  • 网站建设项目进度表网页设计去除下划线代码
  • 北京网站制作合肥美食网页设计模板中文
  • 免费稳定的网站空间功能型网站建设
  • 免费大气网站模板wordpress企业类模板下载
  • 使用iis搭建网站辽宁建设工程信息网昂
  • 嘉峪关网站seowordpress 短信登录密码错误
  • 寮步营销型网站建设wordpress 彩色序号