添加微信云开发环境
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,} from "cc";
|
||||
import { Color, Component, EventTouch, Vec3, _decorator ,} from "cc";
|
||||
import HeroAnmComp from "./HeroAnmComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -12,6 +12,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { LoadingViewComp } from "./view/LoadingViewComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { WxCloudApi } from "../wx_clound_client_api/WxCloudApi";
|
||||
|
||||
|
||||
// import {data} from "../data/data";
|
||||
@@ -50,6 +51,10 @@ export class Initialize extends ecs.Entity {
|
||||
oops.res.load("language/font/" + oops.language.current, () => {
|
||||
// 加载本地英雄数据
|
||||
this.loadHeroDataFromLocal();
|
||||
// 判断是否为微信客户端,是的话才加载云端数据
|
||||
if (this.isWxClient()) {
|
||||
this.loadWxDataFromCloud();
|
||||
}
|
||||
next();
|
||||
});
|
||||
//加载精灵配置表
|
||||
@@ -83,7 +88,19 @@ export class Initialize extends ecs.Entity {
|
||||
oops.res.loadDir("common", next);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 判断是否为微信客户端
|
||||
*/
|
||||
private isWxClient(): boolean {
|
||||
// 检查是否存在微信API
|
||||
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
|
||||
}
|
||||
|
||||
private loadWxDataFromCloud() {
|
||||
WxCloudApi.login().then(loginRes=>{
|
||||
console.log("login res", loginRes);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 从本地存储加载游戏数据
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math, RigidBody2D, Animation, sp, Tween} from "cc";
|
||||
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math, RigidBody2D, Animation, Tween} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
@@ -50,7 +50,6 @@ export class SkillCom extends CCComp {
|
||||
debuff_value:number=0;
|
||||
debuff_count:number=0;
|
||||
// 组件引用
|
||||
spine:sp.Skeleton=null;
|
||||
anim:Animation=null;
|
||||
tweenInstance:Tween<any> = null;
|
||||
private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向
|
||||
@@ -82,11 +81,9 @@ export class SkillCom extends CCComp {
|
||||
this.initializeSkillConfig();
|
||||
if (!this.skillConfig) return;
|
||||
this.node.setPosition(this.startPos.x,this.startPos.y,0)
|
||||
if(this.node.getChildByName('anm')){
|
||||
this.spine=this.node.getChildByName('anm').getComponent('sp.Skeleton') as sp.Skeleton;
|
||||
}else{
|
||||
this.anim=this.node.getComponent(Animation)
|
||||
}
|
||||
|
||||
this.anim=this.node.getComponent(Animation)
|
||||
|
||||
this.on(GameEvent.MissionEnd, this.doDestroy, this);
|
||||
this.node.active = true;
|
||||
//console.log("[SkillCom]:caster",this.caster)
|
||||
@@ -149,15 +146,7 @@ export class SkillCom extends CCComp {
|
||||
//console.log("[SkillCom]:has anim",anim)
|
||||
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
||||
}
|
||||
if(this.node.getChildByName('anm')){
|
||||
if(this.node.getChildByName('anm').getComponent('sp.Skeleton')){
|
||||
//console.log("[SkillCom]:has spine",this.spine)
|
||||
this.spine.setCompleteListener((trackEntry) => {
|
||||
this.onAnimationFinished()
|
||||
//console.log("[SkillCom]:[track %s][animation %s] complete: %s", trackEntry.trackIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
onAnimationFinished(){
|
||||
// console.log("[SkillCom]:onAnimationFinished",this.s_uuid)
|
||||
@@ -233,12 +222,10 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
|
||||
if(smc.mission.pause) {
|
||||
if(this.spine) this.spine.paused=true
|
||||
if(this.anim) this.anim.pause()
|
||||
return;
|
||||
}
|
||||
if(this.anim) this.anim.resume()
|
||||
if(this.spine) this.spine.paused=false
|
||||
if (!this.node || !this.node.isValid) return;
|
||||
|
||||
if(this.skillConfig.EType==EType.timeEnd){
|
||||
|
||||
9
assets/script/game/wx_clound_client_api.meta
Normal file
9
assets/script/game/wx_clound_client_api.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "45c44975-aaf4-4196-88aa-a58fdbb534bb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
84
assets/script/game/wx_clound_client_api/WxCloudApi.ts
Normal file
84
assets/script/game/wx_clound_client_api/WxCloudApi.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
export type CloudReturnType<T = any> = {
|
||||
code: number,// 200成功
|
||||
msg?:string,
|
||||
data?:T
|
||||
}
|
||||
|
||||
export class WxCloudApi{
|
||||
/**
|
||||
* @en init the cloud
|
||||
* @zh 初始化云客户端(只调用一次即可)
|
||||
* @param {string} env 云环境名称
|
||||
*/
|
||||
public static init(env:string){
|
||||
wx?.cloud.init({
|
||||
env: env
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Login to the cloud
|
||||
* @zh 登录云
|
||||
* @return 返回结果
|
||||
* 参考:
|
||||
* result.result = {
|
||||
* code: number, // 200成功,其他都是失败
|
||||
* msg: string, // 如果失败,这里是失败原因等信息
|
||||
* data: { // 成功才有
|
||||
* openid: string, // 用户微信平台openid
|
||||
* regist_time: number, // 时间戳,用户注册时间
|
||||
* game_data: object, // 开发者自己保存的数据
|
||||
* }
|
||||
* }
|
||||
* 如果这个泛型令你报错(一般是因为你删了wx.api.d.ts导致),请使用以下签名:
|
||||
* login():Promise<{result: CloudReturnType<{openid: string, regist_time: number, game_data: object}>}>
|
||||
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
|
||||
* login():Promise<any>
|
||||
*/
|
||||
public static async login(): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
openid:string,
|
||||
regist_time:number,
|
||||
game_data:any
|
||||
}>>>{
|
||||
return await wx?.cloud.callFunction({
|
||||
name: 'cocos_cloud',
|
||||
data: {
|
||||
cmd: "login"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Save game data to the cloud
|
||||
* @zh 把客户端数据写入云,此为全覆盖写入,请自行管理完整数据
|
||||
* @return 返回结果
|
||||
* 参考:
|
||||
* result.result = {
|
||||
* code: number, // 200成功,其他都是失败
|
||||
* msg: string, // 如果失败,这里是失败原因等信息
|
||||
* data: {
|
||||
* errMsg: "document.update:ok", // 数据库返回结果
|
||||
* stats: {
|
||||
* updated: number, // 更新了几条数据(正常是1)
|
||||
* }
|
||||
* }
|
||||
* 如果这个泛型令你报错(一般是因为你删了wx.api.d.ts导致),请使用以下签名:
|
||||
* save(gameData: any): Promise<{resoult:CloudReturnType}>
|
||||
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
|
||||
* login():Promise<any>
|
||||
*/
|
||||
public static async save(gameData: any): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
errMsg: string,
|
||||
status:{
|
||||
updated: number
|
||||
}
|
||||
}>>> {
|
||||
return await wx?.cloud.callFunction({
|
||||
name: 'cocos_cloud',
|
||||
data: {
|
||||
cmd: 'save',
|
||||
data: gameData
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0b5acaf6-aa85-428d-a38c-97bf645cc1db",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
29
assets/script/game/wx_clound_client_api/wx.aip.d.ts
vendored
Normal file
29
assets/script/game/wx_clound_client_api/wx.aip.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// 注意:此文件是为了引入微信接口
|
||||
// !!如果这个文件,与你的wx.d.ts因为定义重复报错,你可以删除本文件!!
|
||||
|
||||
// @ts-ignore
|
||||
declare class wx {
|
||||
public static cloud: Cloud;
|
||||
}
|
||||
// @ts-ignore
|
||||
declare class Cloud {
|
||||
public init(options: {
|
||||
env?: string | {
|
||||
database?: string
|
||||
storage?: string
|
||||
functions?: string
|
||||
},
|
||||
traceUser?: boolean//default true
|
||||
});
|
||||
public callFunction(obj: {
|
||||
name: string,
|
||||
data?: any,
|
||||
config?: { env: string },
|
||||
}): Promise<CloudCallFunctionResult>;
|
||||
}
|
||||
// @ts-ignore
|
||||
declare type CloudCallFunctionResult<T = any> = {
|
||||
result: T,
|
||||
errMsg: string,
|
||||
requestID: string
|
||||
}
|
||||
9
assets/script/game/wx_clound_client_api/wx.aip.d.ts.meta
Normal file
9
assets/script/game/wx_clound_client_api/wx.aip.d.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "845c60fa-24b5-49c9-85d3-ef55ed459817",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user