فهرست منبع

[FC]:新增UISystem;StorageUtil;GameUtil

fengcong 5 سال پیش
والد
کامیت
a32d3330ac

+ 15 - 3
mk_framework/assets/script/mk/system/MKSystem.ts

@@ -6,6 +6,13 @@ 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 { 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 {
@@ -16,18 +23,23 @@ class MKSystem {
     /** 工具 */
     /** 工具 */
     time: TimeUtil;
     time: TimeUtil;
     file: FileUtil;
     file: FileUtil;
-    loadRes:LoadResUtil;
     encrypt:EncryptUtil;
     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() {
         //工具
         //工具

+ 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": {}
+}

+ 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": {}
+}