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

[FC] UISystem 更改组件模式,直接挂载

fengcong 5 лет назад
Родитель
Сommit
76b42396b2

+ 35 - 7
mk_framework/assets/scene/MainScene.fire

@@ -78,25 +78,28 @@
         "__id__": 6
       },
       {
-        "__id__": 7
-      },
-      {
         "__id__": 8
       },
       {
         "__id__": 9
+      },
+      {
+        "__id__": 10
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 10
-      },
-      {
         "__id__": 11
       },
       {
         "__id__": 12
+      },
+      {
+        "__id__": 13
+      },
+      {
+        "__id__": 14
       }
     ],
     "_prefab": null,
@@ -312,7 +315,11 @@
     },
     "_children": [],
     "_active": true,
-    "_components": [],
+    "_components": [
+      {
+        "__id__": 7
+      }
+    ],
     "_prefab": null,
     "_opacity": 255,
     "_color": {
@@ -362,6 +369,16 @@
     "_id": "feed4Ygc5Mh52Eu+0uixiP"
   },
   {
+    "__type__": "d0ea1+IO0BKJoZMInS6d9dy",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 6
+    },
+    "_enabled": true,
+    "_id": "28M/hEEcFHZqi/h+X6U+Jt"
+  },
+  {
     "__type__": "cc.Node",
     "_name": "提示层",
     "_objFlags": 0,
@@ -589,5 +606,16 @@
     "_enabled": true,
     "mainfestUrl": null,
     "_id": "6fbJRZsUhE4p90rFOw/XX3"
+  },
+  {
+    "__type__": "a0fd9gYXhZMJ46ArqYj2wBy",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 2
+    },
+    "_enabled": true,
+    "ifShowAd": true,
+    "_id": "47/AwonetJ3rlH9QZE1+cJ"
   }
 ]

+ 14 - 4
mk_framework/assets/script/mk/system/UISystem.ts

@@ -1,12 +1,14 @@
+
+const { ccclass, property } = cc._decorator;
+@ccclass
 /**
  * UI管理类
  * @author 冯聪
  */
-export default class UISystem {
+export default class UISystem extends cc.Component {
 
     /** panel父节点 */
-    public panelParent: cc.Node = null;
-
+    private panelParent: cc.Node = null;
     /** 界面预制体路径 */
     private panelPrefanbUrl: string = './prefab/uiPanel/'
     /** 是否正在打开界面 */
@@ -18,6 +20,14 @@ export default class UISystem {
     /** 上一个打开的界面名称 */
     private lastOpenPanelName: string = "";
 
+    /** start */
+    start() {
+        //自己赋节点
+        if (!this.panelParent) {
+            this.panelParent = this.node;
+        }
+    }
+
     /**
      * 打开panel界面
      * @param panelName  界面名称
@@ -42,7 +52,7 @@ export default class UISystem {
 
                     //如果父节点不存在,就默认把该节点定为panel的父节点
                     if (!this.panelParent) {
-                        console.error("[UISystem] UI的父节点panelParent为null,需指定UI打开的父节点");
+                        console.error("[UISystem] UI的父节点panelParent为null,请检查脚本挂载情况");
                         return;
                     }