xx 1 yıl önce
ebeveyn
işleme
f8b62cd170

Dosya farkı çok büyük olduğundan ihmal edildi
+ 222 - 144
assets/resources/prefabs/game_play_shuang_tu_zhao_bu_tong.prefab


+ 123 - 0
assets/script/framework/poolManager.ts

@@ -0,0 +1,123 @@
+import { _decorator, Prefab, Node, instantiate, NodePool } from "cc";
+const { ccclass, property } = _decorator;
+@ccclass("PoolManager")
+export class PoolManager {
+    private _dictPool: any = {}//对象池字典
+    private _dictPrefab: any = {}//预制体字典
+
+    static _instance: PoolManager;
+
+    static get instance() {
+        if (this._instance) {
+            return this._instance;
+        }
+
+        this._instance = new PoolManager();
+        return this._instance;
+    }
+
+    public isHavePool(prefab: Prefab):boolean{
+        let name = prefab.name;
+        if(this._dictPrefab[name]!=null){
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 根据预设从对象池中获取对应节点
+     */
+    public getNode(prefab: Prefab, parent: Node) {
+        let name = prefab.name;
+        //@ts-ignore
+        if (!prefab.position) {
+            //@ts-ignore
+            name = prefab.data.name;
+        }
+
+        this._dictPrefab[name] = prefab;
+        let node: Node = null!;
+        if (this._dictPool.hasOwnProperty(name)) {
+            //已有对应的对象池
+            let pool = this._dictPool[name];
+            if (pool.size() > 0) {
+                node = pool.get();
+            } else {
+                node = instantiate(prefab);
+            }
+        } else {
+            //没有对应对象池,创建他!
+            let pool = new NodePool();
+            this._dictPool[name] = pool;
+
+            node = instantiate(prefab);
+        }
+
+        node.parent = parent;
+        node.active = true;
+        return node;
+    }
+
+    /**
+     * 将对应节点放回对象池中
+     */
+    public putNode(node: Node) {
+        if (!node) {
+            return;
+        }
+        let name = node.name;
+        let pool = null;
+        if (this._dictPool.hasOwnProperty(name)) {
+            //已有对应的对象池
+            pool = this._dictPool[name];
+        } else {
+            //没有对应对象池,创建他!
+            pool = new NodePool();
+            this._dictPool[name] = pool;
+        }
+
+        pool.put(node);
+    }
+
+    /**
+     * 根据名称,清除对应对象池
+     */
+    public clearPool(name: string) {
+        if (this._dictPool.hasOwnProperty(name)) {
+            let pool = this._dictPool[name];
+            pool.clear();
+        }
+    }
+    
+    /**
+     * 预生成对象池
+     *
+     * @param {Prefab} prefab 预制体
+     * @param {number} num 需要预加载的数量
+     * @returns
+     * @memberof PoolManager
+     */
+    public preloadPool (prefab: Prefab, num: number) {
+        let name = prefab.name;
+        // @ts-ignore
+        if (!prefab.position) {
+            // @ts-ignore
+            name = prefab.data.name;
+        }
+
+        let pool: any = null;
+        if (this._dictPool.hasOwnProperty(name)) {
+            // 已有对应的对象池
+            pool = this._dictPool[name];
+        } else {
+            // 没有对应对象池,创建他!
+            pool = new NodePool();
+            this._dictPool[name] = pool;
+        }         
+
+        for (let i = 0; i < num; i++) {
+            let node = instantiate(prefab);
+            pool.put(node);
+        }
+    }
+}

+ 9 - 0
assets/script/framework/poolManager.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "b9dc3fe4-e8ba-4f58-a005-a06d019692cf",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 8 - 5
assets/script/gameManager.ts

@@ -294,12 +294,15 @@ export class gameManager extends Component {
             for (let index = 0; index < gameManager.g_server_play_list_data.list.length; index++) {
                 const element = gameManager.g_server_play_list_data.list[index];
                 let item = gameManager.get_cur_level_by_categoryid(element.id);
-                let key = `${element.id}_${item.level+1}`;
-                let str = StorageManager.instance.getGlobalData(key);
-                if(str===""||str===undefined||str===null){
-                    gameManager.PreloadingLevelImgNumber++;
-                    gameManager.loadLevelImg(element.id,item.level+1,call_back)
+                if((item.level+1)<=element.barrier_number){
+                    let key = `${element.id}_${item.level+1}`;
+                    // let str = StorageManager.instance.getGlobalData(key);
+                    if(!gameManager.cache.get(`${item.level+1}_${element.id}`)){
+                        gameManager.PreloadingLevelImgNumber++;
+                        gameManager.loadLevelImg(element.id,item.level+1,call_back)
+                    }
                 }
+           
             }
         }
     

+ 12 - 2
assets/script/play_list/zhaocha_font/view_game_play_han_zi_zhao_bu_tong.ts

@@ -11,6 +11,7 @@ import { ClientEvent } from '../../framework/clientEvent';
 import { AudioManager } from '../../framework/audioManager';
 import { pause } from '../../dialog/pause';
 import { Util } from '../../framework/util';
+import { PoolManager } from '../../framework/poolManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('view_game_play_han_zi_zhao_bu_tong')
@@ -65,6 +66,10 @@ export class view_game_play_han_zi_zhao_bu_tong extends Component {
                 })
             })
         },this);
+        if(!PoolManager.instance.isHavePool(this.item_prefab)){
+            PoolManager.instance.preloadPool(this.item_prefab,11*15)
+        }
+        
         ClientEvent.on(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER,this.onChangeCoinNumber.bind(this),this);
     }
     protected onDestroy(): void {
@@ -193,6 +198,10 @@ export class view_game_play_han_zi_zhao_bu_tong extends Component {
     initGrid(){
         this.font_grid.getComponent(Layout).constraintNum = this.m_data.col;
         this.lab_coin.getComponent(Label).string = gameManager.get_user_coin()+"";
+        for (let index = 0; index < this.font_grid.children.length; index++) {
+            const element = this.font_grid.children[index];
+            PoolManager.instance.putNode(element);
+        }
         this.font_grid.removeAllChildren()
         this.bottom_pos.removeAllChildren()
         this.left_pos.removeAllChildren()
@@ -209,9 +218,10 @@ export class view_game_play_han_zi_zhao_bu_tong extends Component {
         for (let index = 0; index <this.m_data.col*this.m_data.row; index++) {
             let col = index%this.m_data.col;
             let row = Math.floor(index/this.m_data.col);
-            let item = instantiate(this.item_prefab);
+            // let item = instantiate(this.item_prefab);
+            let item = PoolManager.instance.getNode(this.item_prefab,this.font_grid)
             item.getComponent(font_grid_item).initView(this.default_img,this.find_img,row,col,this.onGridItemClick.bind(this),this.isRight(row,col));
-            item.parent = this.font_grid;
+            // item.parent = this.font_grid;
         }
         for (let index = this.m_data.row; index > 0; index--) {
             let item = instantiate(this.left_item);

+ 0 - 1
assets/script/tools.ts

@@ -88,7 +88,6 @@ export class tools  {
                 }
             }
         }
-
         if(!isCache){
             assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
                 if (!err && imageAsset2) {        

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor