123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import Sdk from "../SDK/SDK";
- import HTTPS, { NetPost } from "../Template/HTTPS";
- import LocalData, { WorkState } from "../Template/LocalData";
- import PopComponet from "../Template/PopComponet";
- export type Options = {
- animation?: boolean;
- PropType?: number;
- Data?: any;
- }
- export enum GameOver {
- fail = 0,
- succeed = 1,
- }
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class PopManger {
- private static instance: PopManger;
- public static getInstance(): PopManger {
- if (!PopManger.instance) {
- PopManger.instance = new PopManger();
- }
- return PopManger.instance;
- }
- Pop(path: string, options: Options = { animation: true }) {
- return new Promise<PopComponet>((resolve, reject) => {
- let bundle = cc.assetManager.getBundle("sub");
- bundle.load(path, cc.Prefab, null, (err, PopPrefab: cc.Prefab) => {
- if (err) {
- cc.error(`加载${path}失败`)
- reject(err)
- return
- }
- let a = this.InitPrefab(PopPrefab, options)
- if (a) {
- resolve(a)
- }
- resolve(null)
- })
- })
- }
- private InitPrefab(PopPrefab: cc.Prefab, options: Options) {
- let PopNode = cc.instantiate(PopPrefab)
- let PopCom = PopNode.getComponent(PopComponet)
- if (options && PopCom) {
- PopCom.Options = options
- }
- PopNode.parent = cc.Canvas.instance.node.getChildByName('PopManger')
- PopNode.setPosition(0, 0)
- if (options.animation) {
- this.OpenAni(PopNode, () => {
- PopCom?.OpenAniOver()
- })
- }
- if (PopCom) {
- return PopCom
- }
- return null
- }
- private OpenAni(PopPrefab: cc.Node, cb: Function) {
- PopPrefab.opacity = 0
- PopPrefab.scale = 0.5
- let t = cc.tween;
- t(PopPrefab)
- // 同时执行两个 cc.tween
- .parallel(
- t().to(0.15, { scale: 1.15 }).to(0.1, { scale: 1 }),
- t().to(0.15, { opacity: 255 })
- )
- .call(() => {
- cb?.()
- })
- .start()
- }
- protected onDestroy(): void {
- PopManger.instance = null
- }
- // update (dt) {}
- LoadGameScene() {
- return new Promise((resolve, reject) => {
- console.time('预加载场景耗时')
- cc.director.preloadScene("Game", null, () => {
- console.timeEnd('预加载场景耗时')
- resolve(true)
- })
- })
- }
- //懒得写资源管理器了 放在这里吧
- LoadAssets<T extends cc.Asset>(path: string): Promise<T> {
- return new Promise((resolve, reject) => {
- let bundle = cc.assetManager.getBundle("sub");
- bundle.load(path, (err, Asset: T) => {
- if (err) {
- cc.error(`加载${path}失败`)
- reject(err)
- return
- }
- resolve(Asset)
- })
- })
- }
- //懒得写资源管理器了 放在这里吧
- LoadBundle(path: string): Promise<cc.AssetManager.Bundle> {
- return new Promise((resolve, reject) => {
- cc.assetManager.loadBundle(path, (err, bundle) => {
- if (err) {
- console.log('加载Bundle失败')
- reject(err)
- return;
- }
- resolve(bundle)
- });
- })
- }
- loadScene_Game() {
- cc.director.loadScene("Game", () => {
- HTTPS.Instance.post(NetPost.AddRecord, {}).then((resp) => {
- })
- })
- }
- /**
- *
- * @param Succeed 结果 0失败 1成功
- */
- GameOver(Succeed: number) {
- let typeeee = 0
- switch (LocalData.getInstance().getWorkState()) {
- case WorkState.引导:
- return
- case WorkState.上班:
- typeeee = 0
- break;
- case WorkState.加班:
- typeeee = 1
- break;
- default:
- break;
- }
- HTTPS.Instance.post(NetPost.EndThisGam, {
- "Type": Succeed,
- "Barrier": typeeee
- }).then((resp) => {
- if (resp.Code == 200) {
- Sdk.getInstance().Setkey(resp.Data.WorkingDays, resp.Data.Id)
- }
- })
- }
- }
|