薛鸿潇 5 лет назад
Родитель
Сommit
5416204666

+ 30 - 30
mk_framework/assets/MKLib/manager/LoaderMgr.ts

@@ -14,11 +14,11 @@ export class LoaderMgr {
     // todo 根据场景来清除资源缓存(什么场景加载的资源就保存到什么场景资源配置上。
     //  可能存在的问题:两个场景公用的资源可能会被释放,之后重新加载,可能会有问题
     //  )
-    public SetBundle(bundle) {
+    public setBundle(bundle) {
         bundle && (this._bundle = bundle);
     }
 
-    public GetBundle() {
+    public getBundle() {
         return this._bundle || cc.resources;
     }
     /*============================================================================================================*/
@@ -26,11 +26,11 @@ export class LoaderMgr {
      * 异步加载资源
      */
     /*============================================================================================================*/
-    public LoadAsset(relative_path: string, complete_callback) {
-        let loader = this.GetBundle();
+    public loadAsset(relative_path: string, complete_callback) {
+        let loader = this.getBundle();
         loader.load(relative_path, (error, asset) => {
             if (error) {
-                error('xx.LoadAsset failed ... and path = ' + relative_path, '===error:', JSON.stringify(error));
+                error('xx.loadAsset failed ... and path = ' + relative_path, '===error:', JSON.stringify(error));
                 return;
             } else {
                 complete_callback && complete_callback(asset);
@@ -43,11 +43,11 @@ export class LoaderMgr {
      * 根据类型异步加载
      */
     /*============================================================================================================*/
-    public LoadAssetByType(relative_path: string, asset_type, complete_callback?: Function) {
+    public loadAssetByType(relative_path: string, asset_type, complete_callback?: Function) {
         return new Promise((resolve: (data) => void, reject) => {
-            this.GetBundle().load(relative_path, asset_type, (error, asset) => {
+            this.getBundle().load(relative_path, asset_type, (error, asset) => {
                 if (error) {
-                    error('xx.LoadAssetByType failed ... and path = ' + relative_path, '==error:', JSON.stringify(error));
+                    error('xx.loadAssetByType failed ... and path = ' + relative_path, '==error:', JSON.stringify(error));
                     reject();
                     return;
                 } else {
@@ -64,9 +64,9 @@ export class LoaderMgr {
      * @param type 资源类型,如果为空,则返回所有类型文件地址
      */
     /*============================================================================================================*/
-    public GetDirUrlsRecursion(path, type) {
+    public getDirUrlsRecursion(path, type) {
         let urls = [];
-        this.GetBundle().getDirWithPath(path, type, urls);
+        this.getBundle().getDirWithPath(path, type, urls);
         let arr_path = [];
         for (let i = 0; i < urls.length; i++) {
             const element = urls[i].path;
@@ -80,7 +80,7 @@ export class LoaderMgr {
      * 通过config构造uuid数组加载
      */
     /*============================================================================================================*/
-    public LoadByConfigUseUuids(assets_config, progress_callback, complete_callback) {
+    public loadByConfigUseUuids(assets_config, progress_callback, complete_callback) {
         // let uuids = [];
         // let urls = [];
         // let len = assets_config.length;
@@ -88,7 +88,7 @@ export class LoaderMgr {
         //     let config = assets_config[i];
         //     let path = config.path;
         //     let type = config.type;
-        //     let _uuids = this.GetBundle().getDirWithPath(path, type, urls);
+        //     let _uuids = this.getBundle().getDirWithPath(path, type, urls);
         //     uuids = uuids.concat(_uuids);
         // }
 
@@ -97,7 +97,7 @@ export class LoaderMgr {
         // let DoWithAssetItemOnProgress = function (completed_count, total_count, item) {
         //     let asset = item.content;
         //     if (asset instanceof JsonAsset) {
-        //         xx.Dict.LoadByAsset(asset);
+        //         xx.Dict.loadByAsset(asset);
         //     }
         //     progress_callback && progress_callback(completed_count, total_count);
         // };
@@ -109,7 +109,7 @@ export class LoaderMgr {
         // loader._loadResUuids(uuids, DoWithAssetItemOnProgress, DoWithAssetOnComplete, urls);
     }
 
-    public LoadAssetsByConfig(assets_config, progress_callback, 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++) {
@@ -118,13 +118,13 @@ export class LoaderMgr {
             let type = config.type;
 
             let urls = [];
-            this.GetBundle().getDirWithPath(path, type, 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) {
+                this.getBundle().load(path, type, function (err, spriteFrame) {
                     if (err) {
                         cc.error(err.message || err);
                         return;
@@ -145,15 +145,15 @@ export class LoaderMgr {
     /**
      */
     /*============================================================================================================*/
-    public ReleaseResByPathAndType(path = '', type) {
+    public releaseResByPathAndType(path = '', type) {
         if (!path || !type) return;
 
-        let urls = this.GetDirUrlsRecursion(path, type);
+        let urls = this.getDirUrlsRecursion(path, type);
         let len = urls.length;
         for (let i = 0; i < len; ++i) {
             let url = urls[i];
-            let atlas = this.GetBundle().getRes(url, type);
-            let deps = this.GetBundle().getDependsRecursively(atlas);
+            let atlas = this.getBundle().getRes(url, type);
+            let deps = this.getBundle().getDependsRecursively(atlas);
             // assetManager.releaseAsset(deps);
         }
         cc.sys.garbageCollect();
@@ -164,12 +164,12 @@ export class LoaderMgr {
      * 同步获取已经预加载的图集中的spriteframe 此接口进入游戏后生效
      */
     /*============================================================================================================*/
-    public GetSpriteFrameFromAtlas(sprite_frame_name, path = '/Atlas') {
-        let urls = this.GetDirUrlsRecursion(path, cc.SpriteAtlas);
+    public getSpriteFrameFromAtlas(sprite_frame_name, path = '/Atlas') {
+        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
+            let atlas: any = this.getBundle().getRes(url, cc.SpriteAtlas);//resources.get
             if (atlas) {
                 let sf = atlas.getSpriteFrame(sprite_frame_name);
                 if (sf) return sf;
@@ -183,8 +183,8 @@ export class LoaderMgr {
      * @param {string} sprite_frame_path 资源相对于resource下的路径
      */
     /*============================================================================================================*/
-    public GetSpriteFrame(sprite_frame_path) {
-        let res = this.GetBundle().getRes(sprite_frame_path, cc.SpriteFrame);
+    public getSpriteFrame(sprite_frame_path) {
+        let res = this.getBundle().getRes(sprite_frame_path, cc.SpriteFrame);
         return res;
     }
 
@@ -193,8 +193,8 @@ export class LoaderMgr {
      * SpriteFrame有一个_uuid的属性,根据uuid去loader里面查找路径加载路径
      */
     /*============================================================================================================*/
-    public ParseUuidToUrl(uuid) {
-        let path_to_uuid = this.GetBundle()._pathToUuid;
+    public parseUuidToUrl(uuid) {
+        let path_to_uuid = this.getBundle()._pathToUuid;
         for (let key in path_to_uuid) {
             let entrys = path_to_uuid[key];
             if (entrys instanceof Array) {
@@ -212,7 +212,7 @@ export class LoaderMgr {
         return '';
     }
 
-    public LoadRemoteTexture(url, role_id, callback) {
+    public loadRemoteTexture(url, role_id, callback) {
         if (this._profile_res[role_id]) {
             let spf = this._profile_res[role_id];
             callback && callback(role_id, spf);
@@ -222,7 +222,7 @@ export class LoaderMgr {
 
         if (!cc.sys.isNative) return;
 
-        this.GetBundle().load({ url: url, type: 'png' }, (err, tex) => {
+        this.getBundle().load({ url: url, type: 'png' }, (err, tex) => {
             cc.log('===get_texture:', role_id);
             if (err) {
                 cc.log('===err:', err);
@@ -237,7 +237,7 @@ export class LoaderMgr {
      * - sprite_frame_name:要获取的纹理名字
      * - arr_atlas:图集列表
     */
-    public GetSpriteFrameByArrAlst(sprite_frame_name: string, arr_atlas: Array<cc.SpriteAtlas>): cc.SpriteFrame {
+    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];

+ 13 - 13
mk_framework/assets/MKLib/manager/LocalStorageMgr.ts

@@ -11,7 +11,7 @@ export class LocalStorageMgr {
     /**
      */
     /*============================================================================================================*/
-    public InitStorage(storage_file) {
+    public initStorage(storage_file) {
         // this._storage_config = require(storage_file);
     }
 
@@ -19,7 +19,7 @@ export class LocalStorageMgr {
     /**
      */
     /*============================================================================================================*/
-    public Set(key, value) {
+    public set(key, value) {
         value = JSON.stringify(value);
         cc.sys.localStorage.setItem(key, value);
     }
@@ -28,7 +28,7 @@ export class LocalStorageMgr {
     /**
      */
     /*============================================================================================================*/
-    public Get(key) {
+    public get(key) {
         let v = cc.sys.localStorage.getItem(key);
         v = JSON.parse(v);
         return v;
@@ -38,7 +38,7 @@ export class LocalStorageMgr {
     /**
      */
     /*============================================================================================================*/
-    public SetNumber(key, value) {
+    public setNumber(key, value) {
         value = JSON.stringify(value);
         cc.sys.localStorage.setItem(key, value);
     }
@@ -48,7 +48,7 @@ export class LocalStorageMgr {
      * default: null => 0
      */
     /*============================================================================================================*/
-    public GetNumber(key) {
+    public getNumber(key) {
         let value = cc.sys.localStorage.getItem(key);
         value = JSON.parse(value) || 0;
 
@@ -72,25 +72,25 @@ export class LocalStorageMgr {
     /**
      */
     /*============================================================================================================*/
-    public GetMusicVolume() {
-        let value = this.Get('music_volume');
+    public getMusicVolume() {
+        let value = this.get('music_volume');
         (value === null) && (value = 1);
         return value;
     }
 
-    public SetMusicVolume(value) {
+    public setMusicVolume(value) {
         if (value < 0.03) value = 0;
-        this.Set('music_volume', value);
+        this.set('music_volume', value);
     }
 
-    public GetEffectVolume() {
-        let value = this.Get('effect_volume');
+    public getEffectVolume() {
+        let value = this.get('effect_volume');
         (value === null) && (value = 1);
         return value;
     }
 
-    public SetEffectVolume(value) {
+    public setEffectVolume(value) {
         if (value < 0.03) value = 0;
-        this.Set('effect_volume', value);
+        this.set('effect_volume', value);
     }
 }

+ 3 - 3
mk_framework/assets/script/scene/TestScene.ts

@@ -10,13 +10,13 @@ export default class NewClass extends cc.Component {
     onLoad() {
         mk.event.on('/1:2/3-4x', this.on1234, this);
         cc.systemEvent.on('/1:2/3-4x2', this.on2222, this);
-        mk.sys.localStorage.Set('test', 'storage_test')
+        mk.sys.localStorage.set('test', 'storage_test');
     }
 
     async start() {
         // 动态加载应用Promise示例:
         let path = 'test_prefab';
-        let asset = await mk.loader.LoadAssetByType(path, cc.Prefab)
+        let asset = await mk.loader.loadAssetByType(path, cc.Prefab);
         this.test_prefab = asset;
         let node = cc.instantiate(asset);
         node.parent = this.node;
@@ -28,7 +28,7 @@ export default class NewClass extends cc.Component {
         cc.systemEvent.emit('/1:2/3-4x2', this.on2222, this);
 
         // 本地存储示例:
-        cc.log(mk.sys.localStorage.Get('test'))
+        cc.log(mk.sys.localStorage.get('test'))
         cc.log(cc.sys.localStorage.getItem('test'))
     }
     /** 测试接口 */