Просмотр исходного кода

Merge branch 'master' of http://git.mokasz.com/zouyong/mk_framework

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

+ 17 - 16
mk_framework/assets/script/mk/sdk/BuglySDK.ts

@@ -1,9 +1,23 @@
+/**
+ * @description 错误日志管理类
+ * @author 邹勇
+ */
 export default class BuglySDK {
 export default class BuglySDK {
     constructor() {
     constructor() {
-        this.initErrorHandler();
+        this.initELKHandler();
     }
     }
 
 
-    private initErrorHandler() {
+    /**
+     * 接入第三方腾讯bugly
+     */
+    private initBugly(){
+
+    }
+
+    /**
+     * 错误日志发送elk服务器
+     */
+    private initELKHandler() {
         if (cc.sys.isNative) {
         if (cc.sys.isNative) {
             let __handler;
             let __handler;
             if (window['__errorHandler']) {
             if (window['__errorHandler']) {
@@ -18,19 +32,6 @@ export default class BuglySDK {
                 }
                 }
             }
             }
         }
         }
-        else if (cc.sys.isBrowser) {
-            let __handler;
-            if (window.onerror) {
-                __handler = window.onerror;
-            }
-            window.onerror = function (...args) {
-                console.log('游戏报错,浏览器');
-                BuglySDK.handleError(...args)
-                if (__handler) {
-                    __handler(...args);
-                }
-            }
-        }
     }
     }
 
 
 
 
@@ -112,7 +113,7 @@ export default class BuglySDK {
         };
         };
 
 
         let str = JSON.stringify(senddata);
         let str = JSON.stringify(senddata);
-        str = Utils.RSAEncrypt(str);
+        str = mk.encrypt.rsaEncrypt(str);
 
 
         httpRequest.send(str);
         httpRequest.send(str);
     }
     }

+ 4 - 0
mk_framework/assets/script/mk/system/DataSystem.ts

@@ -1,3 +1,7 @@
+/**
+ * @description 数据管理类
+ * @author 邹勇
+ */
 export default class DataSystem {
 export default class DataSystem {
     constructor() {
     constructor() {
         
         

+ 112 - 0
mk_framework/assets/script/mk/system/EventSystem.ts

@@ -0,0 +1,112 @@
+
+/**
+ * 游戏事件管理类
+ * @author 冯聪
+ */
+export default class EventSystem {
+
+    /** 监听数组 */
+    private listeners: { [key: string]: Observer[] } = {};
+    
+    /** 
+     * 注册事件
+     * @param name 事件名称
+     * @param callback 回调函数
+     * @param context 上下文
+     */
+    public register(name: string, callback: Function, context: any) {
+
+        //如果没有该事件
+        if (!this.listeners[name]) {
+            this.listeners[name] = [];
+        }
+
+        let observers: Observer[] = this.listeners[name];
+
+        let length = observers.length;
+        for (let i = 0; i < length; i++) {
+            let observer = observers[i];
+            if (observer.compar(context)) {
+                console.warn("[EventMgr]重复添加监听,请检查事件:", name)
+                return;
+            }
+        }
+        this.listeners[name].push(new Observer(callback, context));
+    }
+
+    /**
+     * 移除事件
+     * @param name 事件名称
+     * @param callback 回调函数
+     * @param context 上下文
+     */
+    public remove(name: string, callback: Function, context: any) {
+
+        let observers: Observer[] = this.listeners[name];
+        if (!observers) return;
+        let length = observers.length;
+        for (let i = 0; i < length; i++) {
+            let observer = observers[i];
+            if (observer.compar(context)) {
+                observers.splice(i, 1);
+                break;
+            }
+        }
+        if (observers.length == 0) {
+            delete this.listeners[name];
+        }
+    }
+
+    /**
+     * 发送事件
+     * @param name 事件名称
+     */
+    public fire(name: string, ...args: any[]) {
+
+        let observers: Observer[] = this.listeners[name];
+        if (!observers) return;
+
+        //克隆一个新数组(暂时concat代替),然后分发事件,防止那边remove之后,[0 1] 变成 [1] 然后1号位为undefined
+        let tempObservers: Observer[] = observers.concat();
+        let length = tempObservers.length;
+        for (let i = 0; i < length; i++) {
+            let observer = tempObservers[i];
+            observer.notify(...args, name);
+        }
+        //置空释放
+        tempObservers = null;
+    }
+}
+
+/**事件观察者类*/
+class Observer {
+
+    /** 回调函数 */
+    private callback: Function = null;
+    /** 上下文 */
+    private context: any = null;
+
+    /**构造函数 */
+    constructor(callback: Function, context: any) {
+        let self = this;
+        self.callback = callback;
+        self.context = context;
+    }
+
+    /**
+     * 发送通知
+     * @param args 不定参数
+     */
+    notify(...args: any[]): void {
+        let self = this;
+        self.callback.call(self.context, ...args);
+    }
+
+    /**
+     * 上下文比较
+     * @param context 上下文
+     */
+    compar(context: any): boolean {
+        return context == this.context;
+    }
+}

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

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "aab2795c-5fda-40cf-9490-d7a52412b6e1",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 2 - 2
mk_framework/assets/script/mk/system/HttpSystem.ts

@@ -1,6 +1,6 @@
 /**
 /**
- * @description http请求
- * @author zy
+ * @description http请求管理类
+ * @author 邹勇
  */
  */
 export default class HttpSystem {
 export default class HttpSystem {
     constructor() {
     constructor() {

+ 18 - 2
mk_framework/assets/script/mk/system/MKSystem.ts

@@ -5,6 +5,14 @@ import AudioSystem from "./AudioSystem";
 import DataSystem from "./DataSystem";
 import DataSystem from "./DataSystem";
 import HttpSystem from "./HttpSystem";
 import HttpSystem from "./HttpSystem";
 import LoadResUtil from "../utils/LoadResUtil";
 import LoadResUtil from "../utils/LoadResUtil";
+import { EncryptUtil } from "../utils/EncryptUtil";
+import LogUtil from "../utils/LogUtil";
+import GameUtil from "../utils/GameUtil";
+import UISystem from "./UISystem";
+import StorageUtil from "../utils/StorageUtil";
+import TimerSystem from "./TimerSystem";
+import EventSystem from "./EventSystem";
+import MathUtil from "../utils/MathUtil";
 
 
 
 
 class MKSystem {
 class MKSystem {
@@ -15,22 +23,30 @@ class MKSystem {
     /** 工具 */
     /** 工具 */
     time: TimeUtil;
     time: TimeUtil;
     file: FileUtil;
     file: FileUtil;
+    encrypt:EncryptUtil;
+    console:LogUtil;
+    game:GameUtil;
+    loader: LoadResUtil;
+    localStorage:StorageUtil;
+    math:MathUtil;
 
 
     /** SDK */
     /** SDK */
     bugly:BuglySDK;
     bugly:BuglySDK;
-    
 
 
     /** 系统管理 */
     /** 系统管理 */
-    loader: LoadResUtil;
+    ui:UISystem;
     data:DataSystem;
     data:DataSystem;
     http:HttpSystem;
     http:HttpSystem;
     audio:AudioSystem;
     audio:AudioSystem;
+    timer:TimerSystem;
+    event:EventSystem;
 
 
     init() {
     init() {
         //工具
         //工具
         this.time = new TimeUtil();
         this.time = new TimeUtil();
         this.file = new FileUtil();
         this.file = new FileUtil();
         this.loader = new LoadResUtil();
         this.loader = new LoadResUtil();
+        this.encrypt = new EncryptUtil();
 
 
         //sdk
         //sdk
         this.bugly = new BuglySDK();
         this.bugly = new BuglySDK();

+ 104 - 0
mk_framework/assets/script/mk/system/TimerSystem.ts

@@ -0,0 +1,104 @@
+
+/**
+ * 计时器管理类 
+ * @description
+ * @author 冯聪 
+ */
+export default class TimerSystem extends cc.Component {
+
+    /** 计数器数组 */
+    private timerArr: Timer[] = [];
+
+    /** 开启游戏计时器 */
+    public startTimer() {
+        this.schedule(() => {
+            this.runTimer();
+        }, 1);
+    }
+
+    /** 运行游戏计时器 */
+    private runTimer() {
+        for (var i: number = 0; i < this.timerArr.length; i++) {
+            var gameTimer: Timer = this.timerArr[i];
+            var callBack: Function = gameTimer.callBack;
+            var object: any = gameTimer.object;
+            gameTimer.curTime--;
+            if (gameTimer.curTime <= 0) {
+                gameTimer.curTime = gameTimer.totalTime;
+                callBack.call(object);
+            }
+        }
+    }
+
+    /**
+     * 添加游戏计时器
+     * @description
+     * @param time     计时的时间
+     * @param callBack 计时结束之后的回调
+     * @param object   计时绑定的对象
+     */
+    public addTimer(time: number, callBack: Function, object: any) {
+        if (!this.ifHasSameTimer(callBack, object)) {
+            let gameTimer = new Timer();
+            gameTimer.curTime = time;
+            gameTimer.totalTime = time;
+            gameTimer.callBack = callBack;
+            gameTimer.object = object;
+            this.timerArr.push(gameTimer);
+        }
+    }
+
+    /**
+     * 是否有相同的时间管理器
+     * @param callBack 比对的回调
+     * @param object   比对的对象
+     */
+    private ifHasSameTimer(callBack: Function, object: any): boolean {
+        if (this.getTimer(callBack, object)) {
+            //重复添加时间计时器
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
+    /** 获取时间管理器 */
+    private getTimer(callBack: Function, object: any): Timer {
+        for (var i: number = this.timerArr.length - 1; i >= 0; i--) {
+            let gameTimer: Timer = this.timerArr[i];
+            if (gameTimer.callBack == callBack && gameTimer.object == object) {
+                return gameTimer;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 移除时间管理器
+     * @param callBack 
+     * @param object 
+     */
+    public removeTimer(callBack: Function, object: any) {
+        for (var i: number = this.timerArr.length - 1; i >= 0; i--) {
+            let timer: Timer = this.timerArr[i];
+            if (timer.callBack == callBack && timer.object == object) {
+                this.timerArr.splice(i, 1)
+                //gameTimer = null; //要不要加null 看最后的效果
+                return;
+            }
+        }
+    }
+}
+
+/**游戏计时器类 */
+export class Timer {
+    /**当前计时时间 */
+    curTime: number = 0;
+    /**计时总时间 */
+    totalTime: number = 0;
+    /**计时的回调 */
+    callBack: Function = null;
+    /**绑定的脚本对象 */
+    object: any = null;
+}

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

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "70a46dc2-1209-45cb-8f4e-1905ab19da1c",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 105 - 0
mk_framework/assets/script/mk/system/UISystem.ts

@@ -0,0 +1,105 @@
+
+/**
+ * UI管理类
+ * @author 冯聪
+ */
+export default class UISystem {
+
+    /**panel父节点 */
+    public panelParent: cc.Node = null;
+
+    /**界面预制体路径 */
+    private panelPrefanbUrl: string = './prefab/uiPanel/'
+    /**是否正在打开界面 */
+    private isPanelOpening: boolean = false;
+    /**是否界面正在关闭 */
+    private isPanelClosing: boolean = false;
+    /**当前打开的UIPanel */
+    private curOnPanelDic: { [key: string]: cc.Node } = {};
+    /**上一个打开的界面名称 */
+    private lastOpenPanelName: string = "";
+
+    /**
+     * 打开panel界面
+     * @param panelName 界面名称
+     * @param callBack  打开之后的回调
+     * @param openAction 打开之后的操(需不需要关闭其他界面)
+     */
+    onPanel(panelName: string, callBack: Function = null, openAction: OpenActionType = OpenActionType.normal) {
+
+        if (this.isPanelOpening || this.getCurOnPanel(panelName)) {
+            return;
+        }
+
+        this.isPanelOpening = true;
+
+        mk.loader.load(`${this.panelPrefanbUrl}` + panelName, cc.Prefab).then((prefab) => {
+
+            this.isPanelOpening = false;
+
+            let node_panel = cc.instantiate(prefab);
+            this.curOnPanelDic[panelName] = node_panel;
+            //如果父节点不存在,就默认把该节点定为panel的父节点
+            if (!this.panelParent) {
+                mk.console.log("[UISystem] UI的父节点panelParent为null,需指定UI打开的父节点");
+                return;
+            }
+            this.panelParent.addChild(node_panel);
+            
+            callBack && callBack();
+
+            switch (openAction) {
+                case OpenActionType.normal:
+                    break;
+                case OpenActionType.closeLast:
+                    if (this.lastOpenPanelName) {
+                        this.offPanel(this.lastOpenPanelName);
+                    }
+                    break;
+                case OpenActionType.closeOther:
+                    let keys = Object.keys(this.curOnPanelDic).filter((key) => { key != panelName });
+                    for (var i = 0; i < keys.length; i++) {
+                        let key = keys[i];
+                        this.offPanel(key);
+                    }
+                    break;
+            }
+            this.lastOpenPanelName = panelName;
+        })
+    }
+
+    /**获取当前打开的panel界面
+     * @param panelName 界面名称
+     */
+    getCurOnPanel(panelName: string): cc.Node {
+        return this.curOnPanelDic[panelName];
+    }
+
+    /**
+     * 关闭panel界面
+     * @param panelName 界面名称
+     * @param callBack  关闭之后回调
+     */
+    offPanel(panelName: string, callBack: Function = null) {
+        if (this.isPanelClosing || !this.getCurOnPanel(panelName)) {
+            return;
+        }
+        this.isPanelClosing = true;
+
+        let node_panel = this.getCurOnPanel(panelName);
+        node_panel.removeFromParent();
+        delete this.curOnPanelDic[panelName];
+
+        this.isPanelClosing = false;
+    }
+}
+
+/**界面打开操作 */
+export enum OpenActionType {
+    /**普通不操作 */
+    normal = 0,
+    /**关闭其他 */
+    closeOther = 1,
+    /**关闭上一个 */
+    closeLast = 2
+}

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

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "d0ea1f88-3b40-4a26-864c-2274ba77d772",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 51 - 0
mk_framework/assets/script/mk/utils/GameUtil.ts

@@ -0,0 +1,51 @@
+
+/**
+ * 游戏工具类
+ * @description 
+ * @author 冯聪
+ */
+export default class GameUtil {
+
+    /**获取屏幕尺寸 */
+    public getWinSize(): cc.Size {
+        return cc.winSize;
+    }
+
+    /**激活物理系统 */
+    public enablePhysics() {
+        cc.director.getPhysicsManager().enabled = true;
+    }
+
+    /**绘制物理信息 */
+    public debugDrawPhysicsFlag(ifDraw: boolean = false) {
+        if (ifDraw) {
+            cc.director.getPhysicsManager().debugDrawFlags =
+                cc.PhysicsManager.DrawBits.e_aabbBit |
+                cc.PhysicsManager.DrawBits.e_jointBit |
+                cc.PhysicsManager.DrawBits.e_shapeBit;
+        }
+        else {
+            cc.director.getPhysicsManager().debugDrawFlags = 0;
+        }
+    }
+
+    /**获取世界坐标
+     * @param 需要获取的节点
+     */
+    public static getWorldPos(node: cc.Node): cc.Vec2 {
+        let originX = node.x;
+        let originY = node.y;
+        let curNode = node;
+
+        while (curNode.parent) {
+            let parent = curNode.parent;
+            if (parent.name == 'Canvas') {
+                break;
+            }
+            originX += parent.x;
+            originY += parent.y;
+            curNode = parent;
+        }
+        return new cc.Vec2(originX, originY);
+    }
+}

+ 9 - 0
mk_framework/assets/script/mk/utils/GameUtil.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "78449f73-4199-44e4-b190-fc0380599a91",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 23 - 22
mk_framework/assets/script/mk/utils/LoadResUtil.ts

@@ -1,5 +1,6 @@
 
 
-/**加载资源工具类
+/**
+ * 加载资源工具类
  * @description 
  * @description 
  * @author 冯聪
  * @author 冯聪
  */
  */
@@ -13,9 +14,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 预加载本地资源 
      * 预加载本地资源 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param paths 加载路径
-     * @param type  资源类型(cc.Asset)
+     * @description   https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param  paths  加载路径
+     * @param  type   资源类型(cc.Asset)
      * @returns Promise
      * @returns Promise
      */
      */
     public preload(paths: string | any, type: typeof cc.Asset): Promise<any> {
     public preload(paths: string | any, type: typeof cc.Asset): Promise<any> {
@@ -39,9 +40,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 加载本地资源 
      * 加载本地资源 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param paths 加载路径
-     * @param type  资源类型(cc.Asset)
+     * @description   https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param  paths  加载路径
+     * @param  type   资源类型(cc.Asset)
      * @returns Promise
      * @returns Promise
      */
      */
     public load<T extends cc.Asset>(paths: string | any, type: typeof cc.Asset): Promise<any> {
     public load<T extends cc.Asset>(paths: string | any, type: typeof cc.Asset): Promise<any> {
@@ -65,9 +66,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 预加载文件夹资源 
      * 预加载文件夹资源 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param dir   文件夹路径
-     * @param type  资源类型(cc.Asset)
+     * @description   https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param   dir   文件夹路径
+     * @param   type  资源类型(cc.Asset)
      * @returns Promise
      * @returns Promise
      */
      */
     public preloadDir(dir: string, type: typeof cc.Asset): Promise<any> {
     public preloadDir(dir: string, type: typeof cc.Asset): Promise<any> {
@@ -89,9 +90,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 加载文件夹资源 
      * 加载文件夹资源 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param dir   文件夹路径
-     * @param type  资源类型(cc.Asset)
+     * @description   https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param   dir   文件夹路径
+     * @param   type  资源类型(cc.Asset)
      * @returns Promise
      * @returns Promise
      */
      */
     public loadDir<T extends cc.Asset>(dir: string, type: typeof cc.Asset): Promise<any> {
     public loadDir<T extends cc.Asset>(dir: string, type: typeof cc.Asset): Promise<any> {
@@ -115,9 +116,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 加载远程资源 
      * 加载远程资源 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param url   加载路径
-     * @param options  
+     * @description      https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param   url      加载路径
+     * @param   options  
      * @returns Promise
      * @returns Promise
      */
      */
     public loadRemote<T extends cc.Asset>(url: string, options: Record<string, any>): Promise<any> {
     public loadRemote<T extends cc.Asset>(url: string, options: Record<string, any>): Promise<any> {
@@ -137,9 +138,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 预加载场景 
      * 预加载场景 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param url   加载路径
-     * @param options  
+     * @description     https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param   url     加载路径
+     * @param   options  
      * @returns Promise
      * @returns Promise
      */
      */
     public preloadScene(sceneName: string, options: Record<string, any>) {
     public preloadScene(sceneName: string, options: Record<string, any>) {
@@ -163,9 +164,9 @@ export default class LoadResUtil {
 
 
     /**
     /**
      * 加载场景 
      * 加载场景 
-     * @description https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
-     * @param url   加载路径
-     * @param options 
+     * @description     https://docs.cocos.com/creator/manual/zh/release-notes/subpackage-upgrade-guide.html
+     * @param   url     加载路径
+     * @param   options 
      * @returns Promise
      * @returns Promise
      */
      */
     public loadScene(sceneName: string, options: Record<string, any>): Promise<any> {
     public loadScene(sceneName: string, options: Record<string, any>): Promise<any> {

+ 5 - 7
mk_framework/assets/script/mk/utils/LogUtil.ts

@@ -1,4 +1,5 @@
-/**日志打印工具类
+/**
+ * 日志打印工具类
  * @description 
  * @description 
  * @author 冯聪
  * @author 冯聪
  */
  */
@@ -39,8 +40,7 @@ export default class LogUtil {
             return;
             return;
         }
         }
         let totalTag = tag + this._tagChar;
         let totalTag = tag + this._tagChar;
-        let message = this.getMessage(data);
-        console.log("%c " + totalTag, "color: " + LogTagColor.bule, message);
+        console.log("%c " + totalTag, "color: " + LogTagColor.bule, ...data);
     }
     }
 
 
     /**
     /**
@@ -54,8 +54,7 @@ export default class LogUtil {
             return;
             return;
         }
         }
         let totalTag = tag + this._tagChar;
         let totalTag = tag + this._tagChar;
-        let message = this.getMessage(data);
-        console.warn("%c " + totalTag, "color: " + LogTagColor.orange, message);
+        console.warn("%c " + totalTag, "color: " + LogTagColor.orange, ...data);
     }
     }
 
 
     /**
     /**
@@ -69,8 +68,7 @@ export default class LogUtil {
             return;
             return;
         }
         }
         let totalTag = tag + this._tagChar;
         let totalTag = tag + this._tagChar;
-        let message = this.getMessage(data);
-        console.warn("%c " + totalTag, "color: " + LogTagColor.red, message);
+        console.warn("%c " + totalTag, "color: " + LogTagColor.red,...data);
     }
     }
 
 
     /**
     /**

+ 240 - 0
mk_framework/assets/script/mk/utils/MathUtil.ts

@@ -0,0 +1,240 @@
+
+/**
+ * 数学计算工具类
+ * @author 冯聪
+ */
+export default class MathUtil {
+
+    /** 计算两点之间距离 */
+    dis(x1, y1, x2, y2): number {
+        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
+    }
+
+    /**
+    * 取一个区间内随机整数
+    * @param n 开始位置
+    * @param m 结束位置
+    * @param ifInt 是否是整数
+    * @returns 返回的随机整数
+    */
+    public rnd(n: number, m: number, ifInt: boolean = true): number {
+        let random: number = n;
+        if (ifInt) {
+            random = Math.floor(Math.random() * (m - n + 1) + n);
+        }
+        else {
+            random = Math.random() * (m - n) + n;
+        }
+        return random;
+    }
+
+    //---------------------------------------------------------科学计数法-----------------------------------------------------
+    /**数字单位 */
+    private numUnit = { 4: "万", 8: "亿", 12: "兆", 16: "万兆", 20: "亿兆", 24: "兆兆", 28: "万兆兆", 32: "亿兆兆", 36: "兆兆兆" };
+
+    /**
+     * 超大数值加法运算  忽略小数部分
+     * @param a
+     * @param b
+     */
+    public addition(a: string, b: string): string {
+        var res: any = '',
+            temp: any = 0;
+        let a1 = a.split('.')[0].split('');
+        let b1 = b.split('.')[0].split('');
+        while (a1.length || b1.length || temp) {
+            temp += ~~a1.pop() + ~~b1.pop();
+            res = (temp % 10) + res;
+            temp = temp > 9;
+        }
+        return res.replace(/^0+/, '');
+    }
+
+    /**
+     * 超大数值减法运算  忽略小数部分
+     * @param a
+     * @param b
+     */
+    public subtraction(a: any, b: any): string {
+        a = a.split('.')[0].split('');
+        b = b.split('.')[0].split('');
+        var aMaxb = a.length > b.length;
+        if (a.length == b.length) {
+            for (var i = 0, len = a.length; i < len; i++) {
+                if (a[i] == b[i]) continue;
+                aMaxb = a[i] > b[i];
+                break;
+            }
+        }
+        if (!aMaxb) a = [b, b = a][0];
+        var result = '';
+        while (a.length) {
+            var temp = parseInt(a.pop()) - parseInt(b.pop() || 0);
+            if (temp >= 0) result = temp + result;
+            else {
+                result = temp + 10 + result;
+                a[a.length - 1]--;
+            }
+        }
+        result = (aMaxb ? '' : '-') + result.replace(/^0*/g, '');
+        if (result == '-') {
+            result = '0'
+        }
+
+        return result
+    }
+
+    /**
+     * 超大数值高位对比  忽略小数部分
+     * @param a
+     * @param b
+     */
+    public contrastNumber(a: any, b: any): boolean {
+        a = a.split('.')[0].split('');
+        b = b.split('.')[0].split('');
+        var aMaxb = a.length > b.length;
+        if (a.length == b.length) {
+            for (var i = 0, len = a.length; i < len; i++) {
+                if (a[i] == b[i]) continue;
+                aMaxb = a[i] > b[i];
+                break;
+            }
+        }
+        if (!aMaxb) a = [b, b = a][0];
+        var result = '';
+        while (a.length) {
+            var temp = parseInt(a.pop()) - parseInt(b.pop() || 0);
+            if (temp >= 0) result = temp + result;
+            else {
+                result = temp + 10 + result;
+                a[a.length - 1]--;
+            }
+        }
+        if (a === b) return true;
+        return Boolean(aMaxb);
+    }
+
+    /**
+     * 数值乘法
+     * @param a 
+     * @param b
+     */
+    public accMuls(a, b): string {
+        let arra = a.split('').reverse(),
+            arrb = b.split('').reverse(),
+            lena = arra.length,
+            lenb = arrb.length,
+            result: any = Array(lena + lenb + 1).join('0').split('');
+        arra.map((itema, indexa) => {
+            arrb.map((itemb, indexb) => {
+                result[indexa + indexb] = +result[indexa + indexb] + itema * itemb;
+            });
+        });
+        result.map((item, index) => {
+            if (item >= 10) {
+                result[index + 1] = ~~result[index + 1] + ~~(result[index] / 10);
+                result[index] %= 10;
+            }
+        });
+        return result.reverse().join('').replace(/^0+/, '');
+    }
+
+    /**
+     * 超大数值乘法
+     * @param arg1
+     * @param arg2
+     */
+    public accMul(arg1: string, arg2: string): string {
+        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
+        try { m += s1.split(".")[1].length } catch (e) { }
+        try { m += s2.split(".")[1].length } catch (e) { }
+        let targe = this.accMuls(s1.replace(".", ""), s2.replace(".", ""));
+
+        return this.accDiv(targe, Math.pow(10, m).toString())
+    }
+
+    /** 科学技术法转为数值字符串形式 */
+    public toNonExponential(num: number): string {
+        return num.toLocaleString().replace(/[,]/g, '')
+    }
+
+    /**
+     * 超大数值除法运算
+     * @param arg1
+     * @param arg2
+     */
+    public accDiv(arg1: string, arg2: string): string {
+
+        var t1 = 0, t2 = 0, t3 = 0, r1, r2;
+
+        try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
+
+        try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
+
+        r1 = Number(arg1.toString().replace(".", ""))
+
+        r2 = Number(arg2.toString().replace(".", ""))
+
+        if (r2 == 0)
+            return '0';
+
+        var result = String(r1 / r2);
+
+        try { t3 = result.toString().split(".")[1].length } catch (e) { }
+
+        var index = t2 - t1 - t3;
+
+        if (index < 0) {
+            result = result.replace(".", "");
+
+            while (result.length <= Math.abs(index)) {
+                result = '0' + result;
+            }
+
+            var start = result.substring(0, result.length + index);
+            var end = result.substring(result.length + index, result.length);
+
+            result = start + '.' + end;
+
+            return this.toNonExponential(Number(result));
+        }
+        else if (index > 0) {
+            result = result.replace(".", "");
+
+            while (result.length <= Math.abs(index)) {
+                result += '0';
+            }
+            return this.toNonExponential(Number(result));
+        }
+        else return this.toNonExponential(Number(result.replace(".", "")));
+    }
+
+    /**
+     * 数值格式化
+     * @param value
+     * @param showDeci
+     */
+    public format(value: string, showDeci: boolean = true): string {
+        var a = value.split('.')[0];
+        var b;
+        for (let i in this.numUnit) {
+            let ii = Number(i);
+            if (a.length - 1 >= ii) {
+                if (showDeci) {
+                    let deci = a.slice(a.length - ii, a.length - ii + 1)
+                    if (Number(deci) >= 1) {
+                        b = a.slice(0, a.length - ii) + "." + deci + this.numUnit[ii];
+                    }
+                    else {
+                        b = a.slice(0, a.length - ii) + this.numUnit[ii];
+                    }
+                }
+                else {
+                    b = a.slice(0, a.length - ii) + this.numUnit[ii];
+                }
+            }
+        };
+        if (!b) return a;
+        return b;
+    }
+}

+ 9 - 0
mk_framework/assets/script/mk/utils/MathUtil.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "2e942b06-e892-49a5-a5a0-be51898ae38e",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 26 - 0
mk_framework/assets/script/mk/utils/StorageUtil.ts

@@ -0,0 +1,26 @@
+/**
+ * 本地存储工具类 
+ * @author 冯聪
+ */
+export default class StorageUtil {
+
+    /**获取存储
+     * @param:key key值
+     */
+    public getStorage(key: string): any {
+        if (cc.sys.localStorage.getItem(key)) {
+            return JSON.parse(cc.sys.localStorage.getItem(key));
+        }
+        else {
+            return null;
+        }
+    }
+
+    /**存储
+     * @param: key key值
+     * @param: value 要存储的value值
+     */
+    public setStorage(key: string, value: any) {
+        cc.sys.localStorage.setItem(key, JSON.stringify(value));
+    }
+}

+ 9 - 0
mk_framework/assets/script/mk/utils/StorageUtil.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "897f9fce-4dee-482e-9091-7f385d550522",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 1 - 1
mk_framework/assets/script/mk/utils/TimeUtil.ts

@@ -1,6 +1,6 @@
 /**
 /**
  * @description 时间工具类
  * @description 时间工具类
- * @author zy
+ * @author 邹勇
  */
  */
 export default class TimeUtil {
 export default class TimeUtil {
     constructor() {
     constructor() {