Browse Source

合并冲突

fengcong 5 years ago
parent
commit
b892651074

+ 2 - 2
mk_framework/assets/script/game/AudioManager.ts

@@ -51,7 +51,7 @@ export default class AudioManager {
     public async playMusic(audio_name: AUDIO_NAME, loop: boolean = true) {
         let asset = this._map_audio.get(audio_name);
         if (!asset) {
-            // asset = await mk.loader.loadAssetByType(AUDIO_PATH + audio_name, cc.AudioClip);
+            asset = await mk.loader.load(AUDIO_PATH + audio_name, cc.AudioClip);
             this._map_audio.set(audio_name, asset);
         }
         mk.audio.playMusic(asset, loop);
@@ -66,7 +66,7 @@ export default class AudioManager {
         if (this._switchEffect && this._switchTempEffect) {
             let asset = this._map_audio.get(audio_name);
             if (!asset) {
-                // asset = await mk.loader.loadAssetByType(AUDIO_PATH + audio_name, cc.AudioClip);
+                asset = await mk.loader.load(AUDIO_PATH + audio_name, cc.AudioClip);
                 this._map_audio.set(audio_name, asset);
             }
             mk.audio.playEffect(asset, loop);

+ 0 - 137
mk_framework/assets/script/mk/system/LoaderSystem.ts

@@ -1,137 +0,0 @@
-/**
- * @description 资源加载
- * @author xhx
- */
-export default class LoaderSystem {
-    private _bundle = null;
-    public setBundle(bundle) {
-        bundle && (this._bundle = bundle);
-    }
-
-    public getBundle() {
-        return this._bundle || cc.resources;
-    }
-    /**
-     * 
-     * @param relative_path 资源路径
-     * @param asset_type 资源类型
-     * @param complete_callback 完成回调【选填】
-     * @returns 对应的资源
-     */
-    public loadAssetByType<T extends typeof cc.Asset>(relative_path: string, asset_type: T, complete_callback?: Function): Promise<InstanceType<T>> {
-        return new Promise((resolve: (data) => void, reject) => {
-            this.getBundle().load(relative_path, asset_type, (error, asset) => {
-                if (error) {
-                    error('xx.loadAssetByType failed ... and path = ' + relative_path, '==error:', JSON.stringify(error));
-                    reject();
-                    return;
-                } else {
-                    complete_callback && complete_callback(asset);
-                    resolve(asset);
-                }
-            });
-        });
-    }
-
-    /**
-     * 获取resource路径下资源地址数组
-     * @param path 文件夹路径
-     * @param type 文件类型
-     * @returns [路径]
-     */
-    public getDirUrlsRecursion(path, type) {
-        let urls = [];
-        this.getBundle().getDirWithPath(path, type, urls);
-        let arr_path = [];
-        for (let i = 0; i < urls.length; i++) {
-            const element = urls[i].path;
-            arr_path.push(element);
-        }
-        return arr_path;
-    }
-
-
-    /**
-     * 预加载资源 by 配置表 【暂未使用】
-     * @param assets_config 配置表
-     * @param progress_callback 进度回调
-     * @param complete_callback 完成回调
-     */
-    public loadAssetsByConfig(assets_config, progress_callback, complete_callback) {
-        let total_count = 0;
-        let complete_count = 0;
-        for (let i = 0; i < assets_config.length; i++) {
-            let config = assets_config[i];
-            let path = config.path;
-            let type = config.type;
-
-            let urls = [];
-            this.getBundle().getDirWithPath(path, type, urls);
-            total_count += urls.length;
-            cc.log('预加载资源:%o', urls);
-            let callback = config.cb;
-            for (let i = 0; i < urls.length; i++) {
-                let path = urls[i].path;
-                this.getBundle().load(path, type, function (err, spriteFrame) {
-                    if (err) {
-                        cc.error(err.message || err);
-                        return;
-                    }
-                    ++complete_count;
-                    progress_callback && progress_callback(complete_count, total_count, spriteFrame);
-                    callback && callback(spriteFrame);
-
-                    if (complete_count === total_count) {
-                        complete_callback && complete_callback();
-                    }
-                });
-            }
-        }
-    }
-
-
-    /**
-     * 同步获取已经预加载的图集中的spriteframe 此接口进入游戏后生效
-     * @param sprite_frame_name 要获取的纹理名字
-     * @param path 图集路径
-     * @returns cc.SpriteFrame
-     */
-    public getSpriteFrameFromAtlas(sprite_frame_name, path = '/Atlas'): cc.SpriteFrame {
-        let urls = this.getDirUrlsRecursion(path, cc.SpriteAtlas);
-        let len = urls.length;
-        for (let i = 0; i < len; i++) {
-            let url = urls[i];
-            let atlas: any = this.getBundle().getRes(url, cc.SpriteAtlas);//resources.get
-            if (atlas) {
-                let sf = atlas.getSpriteFrame(sprite_frame_name);
-                if (sf) return sf;
-            }
-        }
-    }
-
-    /**
-     * 获取散图资源(需要在loading的时候首先加载)
-     * @param sprite_frame_path 资源路径
-     * @returns cc.SpriteFrame || null
-     */
-    public getSpriteFrame(sprite_frame_path: string): cc.SpriteFrame {
-        let res = this.getBundle().getRes(sprite_frame_path, cc.SpriteFrame);
-        return res;
-    }
-
-    /**
-     * 获取图片纹理 by 图集 
-     * @param sprite_frame_name 要获取的纹理名字
-     * @param arr_atlas [图集列表]
-     * @returns cc.SpriteFrame || null
-     */
-    public getSpriteFrameByArrAlst(sprite_frame_name: string, arr_atlas: Array<cc.SpriteAtlas>): cc.SpriteFrame {
-        let count = arr_atlas.length;
-        for (let i = 0; i < count; i++) {
-            let _atlas = arr_atlas[i];
-            let spf = _atlas.getSpriteFrame(sprite_frame_name);
-            if (spf) return spf;
-        }
-        return null;
-    }
-};

+ 0 - 9
mk_framework/assets/script/mk/system/LoaderSystem.ts.meta

@@ -1,9 +0,0 @@
-{
-  "ver": "1.0.8",
-  "uuid": "803afd6a-cc27-421e-8d5b-f88683cb9e0e",
-  "isPlugin": false,
-  "loadPluginInWeb": true,
-  "loadPluginInNative": true,
-  "loadPluginInEditor": false,
-  "subMetas": {}
-}

+ 5 - 4
mk_framework/assets/script/mk/system/MKSystem.ts

@@ -4,8 +4,11 @@ import TimeUtil from "../utils/TimeUtil";
 import AudioSystem from "./AudioSystem";
 import DataSystem from "./DataSystem";
 import HttpSystem from "./HttpSystem";
+<<<<<<< HEAD
 import LoaderSystem from "../utils/LoadResUtil";
 import LogUtil from "../utils/LogUtil";
+=======
+>>>>>>> 6f493536dc39438f7a6f0a44915973f112b500d2
 import LoadResUtil from "../utils/LoadResUtil";
 
 
@@ -25,7 +28,7 @@ class MKSystem {
     
 
     /** 系统管理 */
-    loader: LoaderSystem;
+    loader: LoadResUtil;
     data:DataSystem;
     http:HttpSystem;
     audio:AudioSystem;
@@ -34,14 +37,12 @@ class MKSystem {
         //工具
         this.time = new TimeUtil();
         this.file = new FileUtil();
-        this.log = new LogUtil();
-        this.loadRes = new LoadResUtil();
+        this.loader = new LoadResUtil();
 
         //sdk
         this.bugly = new BuglySDK();
 
         //system
-        this.loader = new LoaderSystem();
         this.audio = new AudioSystem();
         this.data = new DataSystem();
         this.http = new HttpSystem();