关于使用PoolManager 的教程(心得).doc

关于使用PoolManager 的教程(心得).doc

ID:53114369

大小:111.00 KB

页数:6页

时间:2020-04-01

关于使用PoolManager 的教程(心得).doc_第1页
关于使用PoolManager 的教程(心得).doc_第2页
关于使用PoolManager 的教程(心得).doc_第3页
关于使用PoolManager 的教程(心得).doc_第4页
关于使用PoolManager 的教程(心得).doc_第5页
资源描述:

《关于使用PoolManager 的教程(心得).doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、关于使用PoolManager的教程(心得)       在开发项目中使用 unity3d只带的Resource.Load在游戏中频繁加载游戏资,必然导致游戏卡顿。于是就有了使用PoolManager的想法,但是怎么使用好PoolManager特别是通过代码来管理。这里给出一个例子。现在模拟 3个场景A B C  A 是游戏进入画面,B是游戏登录后的主界面,C是游戏战斗场景等....【界面展示】------------------------------【创建过程】A场景中 A挂上脚本 [code]csharpcode:publicclassALoader:Mon

2、oBehaviour{voidOnGUI(){if(GUILayout.Button("Start!"))Application.LoadLevel("B");}}A场景ClinetApp 加上脚本--来自狗刨学习网[code]csharpcode:publicclassClientApp:MonoBehaviour{//UsethisforinitializationvoidStart(){GamePoolManager.Instance();DontDestroyOnLoad(this);}}B场景B挂上脚本&&绑定cube预制[code]csharpcode

3、:publicclassBLoader:MonoBehaviour{publicGameObjectcube;inti=0;//UsethisforinitializationvoidStart(){LoadData();}//UpdateiscalledonceperframevoidUpdate(){if(i<100000){GamePoolManager.Instance().Spawn("Cube");i++;}}voidOnGUI() {if(GUILayout.Button("B->C")){GamePoolManager.Instance().Des

4、troyAll();Application.LoadLevel("C");}}privatevoidLoadData() {if(null!=cube)GamePoolManager.Instance().createPref(cube.transform,"Cube");}}C场景C挂上脚本&&绑定cube预制[code]csharpcode:usingUnityEngine;usingSystem.Collections;publicclassCLoader:MonoBehaviour{publicGameObjectcube;inti=0;//Usethis

5、forinitializationvoidStart(){LoadData();}//UpdateiscalledonceperframevoidUpdate(){if(i<10000){GamePoolManager.Instance().Spawn("Sphere");i++;}}voidOnGUI() {if(GUILayout.Button("C->B")){GamePoolManager.Instance().DestroyAll();Application.LoadLevel("B");}}privatevoidLoadData() {if(null!

6、=cube)GamePoolManager.Instance().createPref(cube.transform,"Sphere");}}最后组要GamePool单例脚本[code]csharpcode:publicclassGamePoolManager{privatestaticGamePoolManager_instance;privateSpawnPool_spawnPool;publicGameObjectgo;privateSystem.Collections.Generic.Dictionary_dir;pri

7、vateGamePoolManager() {go=newGameObject("fight");go.AddComponent();_spawnPool=go.AddComponent();_spawnPool.name="fight";_dir=newSystem.Collections.Generic.Dictionary(); }publicTransformSpawn(stringname){Transformtr=null;if(string.IsNullOrEmpty(

8、name)

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。