Browse Source

游戏暂停

zhoupeng 1 year ago
parent
commit
1170320734

+ 2 - 0
airPlay/assets/Script/Start.ts

@@ -48,6 +48,8 @@ export default class Start extends cc.Component {
         // let node = new cc.Node()
 
         UIMgr.inst.setup(this.$ui_node, UILayerNames.length, UILayerNames);
+
+
         LQCollideSystem.is_enable = true;
         cc.director.getPhysicsManager().enabled = true; 
         cc.director.getPhysicsManager().gravity = cc.v2(0, 0);

+ 6 - 5
airPlay/assets/Script/game/flyImg.ts

@@ -5,12 +5,15 @@
 // Learn life-cycle callbacks:
 //  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
 
+import { GameLogic } from "./update/logic";
+
+
 const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
 
 @ccclass
 @executeInEditMode
 @playOnFocus
-export default class flyImg extends cc.Component {
+export default class flyImg extends  GameLogic {
 
     pos:cc.Vec2 = cc.v2(0,0);
     uvSpeed: number = 0;
@@ -25,7 +28,7 @@ export default class flyImg extends cc.Component {
         this.uvSpeed = value / this.node.height
     }
 
-    start () {
+    onLoad () {
         let spr = this.getComponent(cc.Sprite);
         let mat = spr.getMaterial(0);
         mat.setProperty('center', this.pos);
@@ -33,11 +36,9 @@ export default class flyImg extends cc.Component {
         this.mat = this.node.getComponent(cc.Sprite).getMaterial(0);
     }
 
-    protected update(dt: number): void {
+    gameUpdate(dt: number): void {
         let uvSpeed = this.uvSpeed * dt;
         this.pos.y -= uvSpeed;
         this.mat.setProperty('center', this.pos);
     }
-
-    // update (dt) {}
 }

+ 5 - 4
airPlay/assets/Script/game/monsterFactory.ts

@@ -6,6 +6,7 @@
 //  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
 
 import { LevelMgr } from "../../Script/levelMgr";
+import { GameLogic } from "./update/logic";
 
 /**
  * 怪物类型:
@@ -25,7 +26,7 @@ const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
 @ccclass
 @executeInEditMode
 @playOnFocus
-export default class MonsterFactory extends cc.Component {
+export default class MonsterFactory extends GameLogic {
 
     @property(cc.Prefab) monster: cc.Prefab = null;
     @property(cc.AnimationClip) aniClip:cc.AnimationClip = null;
@@ -66,7 +67,7 @@ export default class MonsterFactory extends cc.Component {
     timeArr = [];
     monsterCnt: number;
 
-    protected start(): void {
+    protected onLoad(): void {
         this.play();
     }
 
@@ -126,7 +127,7 @@ export default class MonsterFactory extends cc.Component {
                 ani.once(cc.Animation.EventType.FINISHED, ()=>{
                     let nodeBox = node.getBoundingBoxToWorld();
                     let viewBox = cc.view.getViewportRect();
-                    console.log(nodeBox, viewBox);
+
                     if(!viewBox.containsRect(nodeBox)) {
                         node.destroy();
                     }
@@ -137,7 +138,7 @@ export default class MonsterFactory extends cc.Component {
         }
     }
 
-    protected update(dt: number): void {
+    gameUpdate(dt: number): void {
         if(CC_EDITOR) return;
         if(this.monsterCnt < this.num) return;
         if(this.node.childrenCount > 0) return;

+ 4 - 2
airPlay/assets/Script/game/move.ts

@@ -1,7 +1,9 @@
+import { GameLogic } from "./update/logic";
+
 const {ccclass, property} = cc._decorator;
 
 @ccclass
-export default class move extends cc.Component {
+export default class move extends GameLogic {
 
     private _speed: number = 100;
     public get speed(): number {
@@ -19,7 +21,7 @@ export default class move extends cc.Component {
         this._dirction = value;
     }
 
-    protected update(dt: number): void {
+    gameUpdate(dt: number): void {
         this.node.x += this.speed * dt * this.dirction.x;
         this.node.y += this.speed * dt * this.dirction.y;
     }

+ 5 - 3
airPlay/assets/Script/game/moveDest.ts

@@ -1,7 +1,10 @@
+import { GameLogic } from "./update/logic";
+
 const {ccclass, property} = cc._decorator;
 
 @ccclass
-export default class MoveDest extends cc.Component {
+export default class MoveDest extends GameLogic {
+
     private _speed: number = 100;
     public get speed(): number {
         return this._speed;
@@ -18,8 +21,7 @@ export default class MoveDest extends cc.Component {
         this._destination = value;
     }
 
-    protected update(dt: number): void {
-
+    gameUpdate(dt: number): void {
         let offset = this.destination.sub(this.node.getPosition());
         if(offset.mag() <= this.speed * dt) {
             this.node.setPosition(this.destination);

+ 13 - 0
airPlay/assets/Script/game/panel.meta

@@ -0,0 +1,13 @@
+{
+  "ver": "1.1.3",
+  "uuid": "c2344ab4-da61-477f-8283-f0c590d0bee3",
+  "importer": "folder",
+  "isBundle": false,
+  "bundleName": "",
+  "priority": 1,
+  "compressionType": {},
+  "optimizeHotUpdate": {},
+  "inlineSpriteFrames": {},
+  "isRemoteBundle": {},
+  "subMetas": {}
+}

+ 23 - 0
airPlay/assets/Script/game/panel/debug.ts

@@ -0,0 +1,23 @@
+import { GameLogicMgr } from "../update/logic";
+
+const {ccclass, property} = cc._decorator;
+
+@ccclass
+export default class debug extends cc.Component {
+
+    /*===========================自动绑定组件开始===========================*/
+    /*自动生成*/
+    @property({type:cc.Button, displayName:""})
+    private $gamePlay_btn:cc.Button = null;
+    
+	/*===========================自动绑定组件结束===========================*/
+
+    /*===========================自动生成按钮事件开始==========================*/
+	onGameplayTouchEnd(){
+        GameLogicMgr.inst.switch();
+    }
+
+
+	/*===========================自动生成按钮事件结束==========================*/
+
+}

+ 10 - 0
airPlay/assets/Script/game/panel/debug.ts.meta

@@ -0,0 +1,10 @@
+{
+  "ver": "1.1.0",
+  "uuid": "9be2fa05-47f7-4f32-b4b4-765b6120dd3d",
+  "importer": "typescript",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 4 - 2
airPlay/assets/Script/game/player.ts

@@ -2,11 +2,12 @@ import { EventMgr } from "../Core/Base/EventMgr";
 import Start from "../Start";
 import { Touch_Start, Touch_Move, Touch_End } from "./eventDef";
 import MoveDest from "./moveDest";
+import { GameLogic } from "./update/logic";
 
 const {ccclass, property} = cc._decorator;
 
 @ccclass
-export default class player extends cc.Component {
+export default class player extends GameLogic {
 
     /*===========================自动绑定组件开始===========================*/
     /*自动生成*/
@@ -43,6 +44,7 @@ export default class player extends cc.Component {
         
     }
 
+
     protected onEnable(): void {
         // 摇杆操作
         // EventMgr.inst.on(Roker_Move, this.onRokerMove, this);
@@ -60,7 +62,7 @@ export default class player extends cc.Component {
         
     }
 
-    protected update(dt: number): void {
+    gameUpdate(dt: number): void {
         this.bulletCDTime -= dt;
         if(this.bulletCDTime <= 0){
             this.bulletCDTime = this.bulletCD;

+ 13 - 0
airPlay/assets/Script/game/update.meta

@@ -0,0 +1,13 @@
+{
+  "ver": "1.1.3",
+  "uuid": "d3b55891-3132-4f15-8ee5-04b972a33c59",
+  "importer": "folder",
+  "isBundle": false,
+  "bundleName": "",
+  "priority": 1,
+  "compressionType": {},
+  "optimizeHotUpdate": {},
+  "inlineSpriteFrames": {},
+  "isRemoteBundle": {},
+  "subMetas": {}
+}

+ 13 - 0
airPlay/assets/Script/game/update/GameAnimation.ts

@@ -0,0 +1,13 @@
+import { GameLogicMgr, GameLogic } from "./logic";
+
+export class GameAnimation extends  cc.Animation {
+
+    protected update(dt: number): void {
+        if(GameLogicMgr.inst.isGamePause) {
+            if(this.enabled) this.enabled = false;
+        }
+        else{
+            if(!this.enabled) this.enabled = true;
+        }
+    }
+}

+ 10 - 0
airPlay/assets/Script/game/update/GameAnimation.ts.meta

@@ -0,0 +1,10 @@
+{
+  "ver": "1.1.0",
+  "uuid": "133ff06c-6704-44d1-a8f2-74f05e91017d",
+  "importer": "typescript",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 45 - 0
airPlay/assets/Script/game/update/logic.ts

@@ -0,0 +1,45 @@
+
+
+
+export class GameLogicMgr {
+
+    private static _inst: GameLogicMgr;
+    public static get inst(): GameLogicMgr {
+        if (this._inst == null) {
+            this._inst = new GameLogicMgr();
+            this._inst.init();
+        }
+        return this._inst;
+    }
+
+    isGamePause: boolean = false;
+
+    switch(){
+        this.isGamePause = !this.isGamePause;
+    }
+
+    init(){
+        //@ts-ignore
+        let aniMgr = cc.director.getAnimationManager();
+
+        aniMgr._oldUpdate = aniMgr.update;
+        aniMgr.update = function(dt){
+            if(GameLogicMgr.inst.isGamePause) return;
+            aniMgr._oldUpdate(dt);
+        }
+    }
+}
+
+export class GameLogic extends cc.Component {
+    logicId:number;
+
+    update(dt: number): void {
+        if(GameLogicMgr.inst.isGamePause) return;
+        this.gameUpdate(dt);
+    }
+
+    gameUpdate(dt:number): void {
+
+    };
+}
+

+ 10 - 0
airPlay/assets/Script/game/update/logic.ts.meta

@@ -0,0 +1,10 @@
+{
+  "ver": "1.1.0",
+  "uuid": "72132e51-b041-46b7-ab86-e05a00ef9fad",
+  "importer": "typescript",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 38 - 8
airPlay/assets/resources/ui/debug.prefab

@@ -24,11 +24,14 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 12
+        "__id__": 13
+      },
+      {
+        "__id__": 14
       }
     ],
     "_prefab": {
-      "__id__": 13
+      "__id__": 15
     },
     "_opacity": 255,
     "_color": {
@@ -79,7 +82,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "New Button",
+    "_name": "$gamePlay_btn",
     "_objFlags": 0,
     "_parent": {
       "__id__": 1
@@ -96,7 +99,7 @@
       }
     ],
     "_prefab": {
-      "__id__": 11
+      "__id__": 12
     },
     "_opacity": 255,
     "_color": {
@@ -200,7 +203,7 @@
         1,
         1,
         1,
-        1
+        0
       ]
     },
     "_eulerAngles": {
@@ -406,11 +409,15 @@
     "_grayMaterial": null,
     "duration": 0.1,
     "zoomScale": 1.2,
-    "clickEvents": [],
+    "clickEvents": [
+      {
+        "__id__": 11
+      }
+    ],
     "_N$interactable": true,
     "_N$enableAutoGrayEffect": false,
-    "_N$transition": 2,
-    "transition": 2,
+    "_N$transition": 3,
+    "transition": 3,
     "_N$normalColor": {
       "__type__": "cc.Color",
       "r": 230,
@@ -476,6 +483,16 @@
     },
     "_id": ""
   },
+  {
+    "__type__": "cc.ClickEvent",
+    "target": {
+      "__id__": 1
+    },
+    "component": "debug",
+    "_componentId": "",
+    "handler": "onGameplayTouchEnd",
+    "customEventData": ""
+  },
   {
     "__type__": "cc.PrefabInfo",
     "root": {
@@ -514,6 +531,19 @@
     "_originalHeight": 0,
     "_id": ""
   },
+  {
+    "__type__": "9be2foFR/dPMrS0dlthIN09",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "$gamePlay_btn": {
+      "__id__": 10
+    },
+    "_id": ""
+  },
   {
     "__type__": "cc.PrefabInfo",
     "root": {

+ 0 - 29
airPlay/packages/aaa/main.js

@@ -1,29 +0,0 @@
-'use strict';
-
-module.exports = {
-  load () {
-    Editor.log('aaa +');
-    // execute when package loaded
-  },
-
-  unload () {
-    Editor.log('aaa -');  
-    // execute when package unloaded
-  },
-
-  // register your ipc messages here
-  messages: {
-    'open' () {
-      // open entry panel registered in package.json
-      Editor.Panel.open('aaa');  
-    },
-    'say-hello' () {
-      Editor.log('Hello World!');
-      // send ipc message to panel
-      Editor.Ipc.sendToPanel('aaa1', 'aaa:hello');
-    },
-    'clicked' () {
-      Editor.log('Button clicked! 11');
-    }
-  },
-};

+ 0 - 28
airPlay/packages/aaa/package.json

@@ -1,28 +0,0 @@
-{
-  "name": "aaa",
-  "version": "0.0.1",
-  "description": "The package template for getting started.",
-  "author": "Cocos Creator",
-  "main": "main.js",
-  "main-menu": {
-    "i18n:MAIN_MENU.package.title/aaa/open": {
-      "message": "aaa:open"
-    },
-    "i18n:MAIN_MENU.package.title/aaa/hello": {
-      "message": "aaa:say-hello"
-    }
-  },
-  "panel": {
-    "main": "panel/index.js",
-    "type": "dockable",
-    "title": "aaa",
-    "width": 400,
-    "height": 300
-  },
-  "reload": {
-    "test": ["test/**/*", "tests/**/*"],
-    "renderer": ["renderer/**/*", "panel/**/*"],
-    "ignore": [],
-    "main": ["main.js"]
-  }
-}

+ 0 - 37
airPlay/packages/aaa/panel/index.js

@@ -1,37 +0,0 @@
-// panel/index.js, this filename needs to match the one registered in package.json
-Editor.Panel.extend({
-  // css style for panel
-  style: `
-    :host { margin: 5px; }
-    h2 { color: #f90; }
-  `,
-
-  // html template for panel
-  template: `
-    <h2>aaa</h2>
-    <hr />
-    <div>State: <span id="label">--</span></div>
-    <hr />
-    <ui-button id="btn">Send To Main</ui-button>
-  `,
-
-  // element and variable binding
-  $: {
-    btn: '#btn',
-    label: '#label',
-  },
-
-  // method executed when template and styles are successfully loaded and initialized
-  ready () {
-    this.$btn.addEventListener('confirm', () => {
-      Editor.Ipc.sendToMain('aaa:clicked');
-    });
-  },
-
-  // register your ipc messages here
-  messages: {
-    'aaa:hello' (event) {
-      this.$label.innerText = 'Hello!';
-    }
-  }
-});