Commit f196d3df authored by liujiangnan's avatar liujiangnan

feat: 佳鑫的代码

parent 9f5f5457
No preview for this file type
This diff is collapsed.
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
cocos creator技术框架下的H5互动模板框架脚手架,基于cocos creator实现快速开发基于绘玩云的H5互动课件。 cocos creator技术框架下的H5互动模板框架脚手架,基于cocos creator实现快速开发基于绘玩云的H5互动课件。
[视频教程传送门](https://www.bilibili.com/video/BV1Dq4y1t7n5/)
# 使用简介 # 使用简介
## 前期准备 ## 前期准备
...@@ -51,7 +49,21 @@ npm start ...@@ -51,7 +49,21 @@ npm start
``` ```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug * 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* [点击查看调试视频教程](https://www.bilibili.com/video/BV1Dq4y1t7n5?p=8) * 点击右上角齿轮,选择技术选型、调试模式选择“普通”
### 互动模板
* 找到项目根路径下 index.html 文件
* 在引入JS的位置将air.js改为air_online_open.js
* 启动本地服务
```
npm start
```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* 点击右上角齿轮,选择技术选型、调试模式选择“互动”
* 左侧老师、右侧学生
### 真机调试 ### 真机调试
...@@ -69,11 +81,4 @@ npm start ...@@ -69,11 +81,4 @@ npm start
* 手机和电脑连接同一个Wifi * 手机和电脑连接同一个Wifi
* 打开调试app,根据提示输入IP地址,点击开始就可以在手机上预览模板了 * 打开调试app,根据提示输入IP地址,点击开始就可以在手机上预览模板了
* 使用 console.log("==调试信息=="); 可以打印日志进行必要的调试 * 使用 this.log("==调试信息=="); 可以打印日志进行必要的调试
* 点击左上角 “logcat” 可以查看运行日志,(logcat是可以按住拖动的, 所以不用考虑UI遮挡问题) \ No newline at end of file
### 注意事项及常见问题
* 项目里所有文件及文件夹的命名方式要注意不能包含空格、汉字、减号
* 项目里尽量不要使用setTimeout、setInterval等定时器,如果使用了记得在onDestroy中释放掉(onDestroy 是指CocosCreator的生命周期钩子)
* 理论上禁止使用全局变量,因为模板到线上会进行组装,常见问题是一个模板使用多次造成全局变量被读脏
{
"ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{ {
"ver": "1.2.9", "ver": "1.2.9",
"uuid": "0737ce42-24f0-45c6-8e1a-8bdab4f74ba3", "uuid": "06cd8565-a4c1-447d-9d22-f34a4efe1390",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"autoReleaseAssets": true, "autoReleaseAssets": false,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
cc.Class({
extends: cc.Component,
properties: {
},
start() {
const layout = cc.find('Canvas/layout');
const str = 'Now Loading...';
// str.split('').forEach((word, idx) => {
// const node = new cc.Node();
// const label = node.addComponent(cc.Label);
// label.string = word;
// node.parent = layout;
// cc.tween(node)
// .delay(idx / 4)
// .by(0.3, { y: 50 }, { easing: 'sineOut' })
// .by(0.3, { y: -50 }, { easing: 'sineIn' })
// .delay((str.length - idx) / 4)
// .union()
// .repeatForever()
// .start();
// });
const totalWidth = layout.children.reduce((width, node, idx) => {
return width + node.width;
}, 0);
layout.width = totalWidth;
const baseUrl = 'https://staging-teach.ireadabc.com';
const uri = '/api/template/v1/middleLayer_for_debug'
const reqData = {};
cc.game.addPersistRootNode(cc.find('cacertNode'));
this.callNetworkApiGet(baseUrl, uri, reqData, (respData) => {
// console.log(respData);
const data = JSON.parse(respData);
let configData = data.data.conf.web_desktop;
if (cc.sys.os == cc.sys.OS_IOS) {
configData = data.data.conf.ios;
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
configData = data.data.conf.android;
}
console.log('汪汪汪: ' + configData.sceneName);
cc.assetManager.loadBundle(configData.bondleUrl, { version: configData.version }, async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
}
// 方便Debug壳的打包
const isDebug = cc.find('Canvas/MainScene').active === false;
if(isDebug){
// 如果没有牛津的主界面,就显示debug的界面,方便调试
bundle.loadScene(configData.sceneName, null, null, (e, scene) => {
if (e) {
return this.asyncDelayLog(e);
}
cc.director.runScene(scene);
});
}
const canvas = cc.find('Canvas');
canvas.emit('MIDDLE_LAYER_LOADED', { scene: null });
globalThis.configData = configData;
});
});
},
callNetworkApiGet(baseUrl, uri, data, callBack) {
let queryStr = '?';
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
const value = data[key];
queryStr += `${key}=${value}`;
}
}
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
callBack(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
});
{
"ver": "1.0.8",
"uuid": "1a8e6a8d-05c7-427f-ac6e-c0e01826e041",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
cacertFile: {
type: cc.Asset,
default: null
}
},
start() {
},
});
{
"ver": "1.0.8",
"uuid": "42b9679e-21e6-4a1d-9289-7557d2e5d0fb",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -165,7 +165,7 @@ export function getSprNodeByUrl(url, cb) { ...@@ -165,7 +165,7 @@ export function getSprNodeByUrl(url, cb) {
export function playAudio(audioClip, cb = null) { export function playAudio(audioClip, cb = null) {
if (audioClip) { if (audioClip) {
const audioId = cc.audioEngine.playEffect(audioClip, false); const audioId = cc.audioEngine.playEffect(audioClip, false, 0.8);
if (cb) { if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => { cc.audioEngine.setFinishCallback(audioId, () => {
cb(); cb();
...@@ -177,85 +177,15 @@ export function playAudio(audioClip, cb = null) { ...@@ -177,85 +177,15 @@ export function playAudio(audioClip, cb = null) {
export async function asyncDelay(time) { export async function asyncDelay(time) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
cc.tween(cc.find('Canvas')) setTimeout(() => {
.delay(time) resolve();
.call(()=>{ }, time * 1000);
resolve(null);
})
.start();
} catch (e) { } catch (e) {
reject(e); reject(e);
} }
}) })
} }
export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJsonDataUrl }, texJsonData: { url: texJsonDataUrl }, texPngData: { url: texPngDataUrl } }) {
if (!texPngDataUrl || !texJsonDataUrl || !texPngDataUrl
|| texPngDataUrl == '' || texJsonDataUrl == '' || texPngDataUrl == '') {
return;
}
return new Promise((resolve, reject) => {
if (node.animaNode) {
node.animaNode.removeFromParent();
}
const animaNode = new cc.Node();
animaNode.name = 'animaNode';
animaNode.parent = node;
animaNode.active = true;
node.animaNode = animaNode;
const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
const loadTexture = new Promise((resolve, reject) => {
cc.assetManager.loadRemote(texPngDataUrl, (error, texture) => {
if (error) {
reject(error);
}
resolve(texture);
});
});
const loadTexJsonData = new Promise((resolve, reject) => {
cc.assetManager.loadAny({ url: texJsonDataUrl }, (error, atlasJson) => {
if (error) {
reject(error);
}
resolve(atlasJson);
});
});
const loadSkeJsonData = new Promise((resolve, reject) => {
cc.assetManager.loadAny({ url: skeJsonDataUrl }, (error, dragonBonesJson) => {
if (error) {
reject(error);
}
resolve(dragonBonesJson);
});
});
Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => {
const atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = JSON.stringify(atlasJson);
atlas.texture = texture;
const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = JSON.stringify(dragonBonesJson);
dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset;
let armatureNames = dragonBonesJson.armature.map(data => data.name);
if (armatureNames.length > 0) {
dragonDisplay.armatureName = armatureNames[0];
}
resolve(animaNode);
});
});
}
export class FireworkSettings { export class FireworkSettings {
baseNode; // 父节点 baseNode; // 父节点
nodeList; // 火花节点的array nodeList; // 火花节点的array
...@@ -366,7 +296,7 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) { ...@@ -366,7 +296,7 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
cc.tween(node) cc.tween(node)
.to(duration, obj, ease) .to(duration, obj, ease)
.call(() => { .call(() => {
resolve(null); resolve();
}) })
.start(); .start();
} catch (e) { } catch (e) {
...@@ -381,7 +311,7 @@ export async function asyncTweenBy(node, duration, obj, ease = undefined) { ...@@ -381,7 +311,7 @@ export async function asyncTweenBy(node, duration, obj, ease = undefined) {
cc.tween(node) cc.tween(node)
.by(duration, obj, ease) .by(duration, obj, ease)
.call(() => { .call(() => {
resolve(null); resolve();
}) })
.start(); .start();
} catch (e) { } catch (e) {
...@@ -411,56 +341,14 @@ export function showTrebleFirework(baseNode, rabbonList) { ...@@ -411,56 +341,14 @@ export function showTrebleFirework(baseNode, rabbonList) {
showFireworks(right); showFireworks(right);
} }
export function httpHeadCall(requsetUrl: string, callback) { export function onHomeworkFinish() {
let xhr = new XMLHttpRequest();
console.log("Status: Send Post Request to " + requsetUrl);
try {
xhr.onreadystatechange = () => {
try {
console.log('xhr.readyState: ', xhr.readyState);
if (xhr.readyState == 4) {
if ((xhr.status >= 200 && xhr.status < 400)) {
callback(true);
} else {
callback(false);
}
}
} catch (e) {
console.log(e)
}
};
xhr.open("HEAD", requsetUrl, true);
xhr.send();
xhr.timeout = 15000;
xhr.onerror = (e) => {
callback(false);
};
xhr.ontimeout = (e) => {
callback(false);
};
} catch (e) {
console.log("Send Get Request error: ", e);
}
}
export function onHomeworkFinish(data = "", callback = ()=>{}) {
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.onHomeworkFinish(callback, data);
} else {
console.log('onHomeworkFinish', JSON.stringify(data));
}
}
export function callMiddleLayerFunction(apiName: string, data: any, callback: Function) {
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find('middleLayer');
if (middleLayer) { if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.callMiddleLayerFunction(apiName, data, callback); if (middleLayerComponent.role == 'student') {
middleLayerComponent.onHomeworkFinish(() => { });
}
} else { } else {
console.log('callMiddleLayerFunction: ' + apiName); console.log('onHomeworkFinish');
} }
} }
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "fd279805-6e95-474f-ac26-e19034f2b093",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
}
initView() {
this.initBg();
this.initPic();
this.initBtn();
this.initIcon();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
}
pic1 = null;
pic2 = null;
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
}
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
})
}
curPage = null;
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn');
})
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 1) {
return;
}
this.curPage = 1
this.rightMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
}
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
// update (dt) {},
initListener() {
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
}
}
{
"ver": "1.1.2",
"uuid": "a5f635d9-92ca-41fe-ba2a-e6fee035993e",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"ver": "1.0.8",
"uuid": "771c13cf-dd4a-4c25-9dca-413a319550cf",
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{ {
"ver": "1.1.2", "ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541", "uuid": "b4b62bd3-1442-4e7e-8b59-38c0f3bf6c52",
"isBundle": false, "isBundle": false,
"bundleName": "", "bundleName": "",
"priority": 1, "priority": 1,
"compressionType": {}, "compressionType": {
"optimizeHotUpdate": {}, "android": "default"
"inlineSpriteFrames": {}, },
"optimizeHotUpdate": {
"android": true
},
"inlineSpriteFrames": {
"android": false
},
"isRemoteBundle": { "isRemoteBundle": {
"ios": false, "ios": false,
"android": false "android": false
......
{
"ver": "1.1.2",
"uuid": "c0d30415-8af2-4c71-9969-002df7c07791",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"__type__": "cc.AnimationClip",
"_name": "arrow",
"_objFlags": 0,
"_native": "",
"_duration": 1,
"sample": 60,
"speed": 1,
"wrapMode": 2,
"curveData": {
"paths": {
"arrow1": {
"props": {
"opacity": [
{
"frame": 0,
"value": 0
},
{
"frame": 0.3333333333333333,
"value": 127
},
{
"frame": 0.6666666666666666,
"value": 255
},
{
"frame": 0.8333333333333334,
"value": 127
},
{
"frame": 1,
"value": 0
}
]
}
},
"arrow2": {
"props": {
"opacity": [
{
"frame": 0,
"value": 127
},
{
"frame": 0.3333333333333333,
"value": 255
},
{
"frame": 0.6666666666666666,
"value": 127
},
{
"frame": 0.8333333333333334,
"value": 0
},
{
"frame": 1,
"value": 127
}
]
}
},
"arrow3": {
"props": {
"opacity": [
{
"frame": 0,
"value": 255
},
{
"frame": 0.3333333333333333,
"value": 127
},
{
"frame": 0.6666666666666666,
"value": 0
},
{
"frame": 0.8333333333333334,
"value": 127
},
{
"frame": 1,
"value": 255
}
]
}
}
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.0",
"uuid": "24b3d2c8-f67f-4cc1-b6f9-768e225b3d22",
"subMetas": {}
}
\ No newline at end of file
{
"__type__": "cc.AnimationClip",
"_name": "arrow",
"_objFlags": 0,
"_native": "",
"_duration": 1,
"sample": 60,
"speed": 1,
"wrapMode": 2,
"curveData": {
"paths": {
"arrow1": {
"props": {
"opacity": [
{
"frame": 0,
"value": 0
},
{
"frame": 0.5,
"value": 127
},
{
"frame": 1,
"value": 255
}
]
}
},
"arrow2": {
"props": {
"opacity": [
{
"frame": 0,
"value": 127
},
{
"frame": 0.5,
"value": 255
},
{
"frame": 1,
"value": 127
}
]
}
},
"arrow3": {
"props": {
"opacity": [
{
"frame": 0,
"value": 255
},
{
"frame": 0.5,
"value": 127
},
{
"frame": 1,
"value": 0
}
]
}
}
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.0",
"uuid": "774a75c2-673e-44ef-a320-23d1ebca06eb",
"subMetas": {}
}
\ No newline at end of file
{
"__type__": "cc.AnimationClip",
"_name": "arrow2",
"_objFlags": 0,
"_native": "",
"_duration": 0.5,
"sample": 60,
"speed": 1,
"wrapMode": 2,
"curveData": {
"paths": {
"arrow1": {
"props": {
"opacity": [
{
"frame": 0,
"value": 0
},
{
"frame": 0.5,
"value": 255
}
]
}
},
"arrow2": {
"props": {
"opacity": [
{
"frame": 0,
"value": 255
},
{
"frame": 0.5,
"value": 0
}
]
}
}
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.0",
"uuid": "eb8ae587-31c0-4536-8ecf-f907520f2939",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "fff45320-253a-4fca-8d41-71657ca56be0",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "cb3bc965-0fb2-4a72-aa15-9ccbb8543671",
"downloadMode": 0,
"duration": 19.435102,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "e16e2ad2-276a-495a-83d0-5b16756e02a6",
"downloadMode": 0,
"duration": 67.970612,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "364b705a-1783-4f46-8240-bca1627c3a4b",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "border_prefbab",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
}
],
"_prefab": {
"__id__": 11
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 868,
"height": 563
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
310.126,
-230,
0,
0,
0,
0,
1,
0.5,
0.5,
0.5
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "cover",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
}
],
"_prefab": {
"__id__": 4
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 868,
"height": 563
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": null,
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "98403cdc-f16c-432c-8f58-50b78acc5caf"
},
"fileId": "d17RVDfvZJNq7kLF7rLrBJ",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "frame",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 8
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 868,
"height": 563
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "afbee15e-e24a-4b66-bf52-fc2b93b889f7"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 868,
"_originalHeight": 563,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "98403cdc-f16c-432c-8f58-50b78acc5caf"
},
"fileId": "54LfqtYRRMTo13Z+QDKZlh",
"sync": false
},
{
"__type__": "bd34eayA01P0KaOMasxsTM+",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "98403cdc-f16c-432c-8f58-50b78acc5caf"
},
"fileId": "",
"sync": false
}
]
\ No newline at end of file
{
"ver": "1.2.9",
"uuid": "98403cdc-f16c-432c-8f58-50b78acc5caf",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "eb535010-e6f8-48ff-b5e6-a427458eedfc",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.1.2",
"uuid": "ecdde385-d614-491b-b29d-3f33445f948b",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class Attributes extends cc.Component {
@property
id: string = '';
@property
class: string = '';
@property({ type: [cc.String], displayName: '自定义属性', tooltip: "key:value结构,冒号“:”分割" })
customAttributeStrArr: string[] = [];
attrMap = {};
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
this.attrMap = {}
for (let i = 0 ; i < this.customAttributeStrArr.length; i++) {
const att = this.customAttributeStrArr[i];
const [k, v] = att.split(':');
this.attrMap[k] = v;
}
}
checkNode({selector, type, node, first = true, result = []}) {
// console.log(node.name);
const att = node.getComponent('Attributes');
if (att && att[type] === selector ) {
if (first) {
return node;
} else {
result.push(node);
att.walkChildren({selector, type, node, first, result})
}
} else if(att && type === 'attr') {
let [k ,v] = selector.split('=');
if (k) {
k = k.trim()
}
if (v) {
v = v.trim()
}
if (k && !v) {
if (first) {
if(k in att.attrMap) {
return node;
}
} else {
if(k in att.attrMap) {
result.push(node);
}
att.walkChildren({selector, type, node, first, result})
}
} else if (k && v){
if (first) {
if(att.attrMap[k]==v) {
return node;
}
} else {
if(att.attrMap[k]==v) {
result.push(node);
}
att.walkChildren({selector, type, node, first, result})
}
}
} else {
if (first) {
const matchNode = this.walkChildren({selector, type, node, first, result});
if (matchNode) {
return matchNode
}
} else {
this.walkChildren({selector, type, node, first, result});
}
}
}
walkChildren({selector, type, node, first = true, result = []}) {
for (let i = 0; i < node.children.length; i++) {
const n = node.children[i];
// console.log(n.name);
const r = this.checkNode({selector, type, node: n, first, result});
if (first && r) {
return r;
}
}
}
walk({selector, type, node, first = true, result = []}) {
const r = this.checkNode({selector, type, node, first, result});
if (first && r) {
return r;
}
}
getToken(selector) {
const s = selector[0];
let type = 'name';
selector = selector.substr(1);
if (s === '.') {
type = 'class';
} else if (s === '#') {
type = 'id'
} else if (s === '[') {
type = 'attr'
selector = selector.substring(0, selector.length-1);
selector = selector.replace(/\s+/g, '').replace(/'/g, '').replace(/"/g, '');
} else {
selector = s + selector;
}
return {
type,
selector
}
}
querySelector(selectorStr) {
const {selector, type} = this.getToken(selectorStr);
return this.walk({selector, type, node: this.node});
}
querySelectorAll(selectorStr) {
const {selector, type} = this.getToken(selectorStr);
const result = [];
this.walk({selector, type, node: this.node, first: false, result});
return result;
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "8d79d796-5e68-41cb-b412-4a39519ec7cb",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
// @property(cc.Label)
// label: cc.Label = null;
// @property
// text: string = 'hello';
@property
need: number = 5;
touchCounter = 0;
countTimer = null;
hat = null;
// isDebug = false;
// touchTimeline = [];
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
isDebug() {
return this.hat && this.hat.active;
}
start () {
console.log(111)
this.hat = this.node.getChildByName('hat');
if (!this.hat) {
return;
}
this.node.on(cc.Node.EventType.TOUCH_START, () => {
// console.log(Date.now());
// this.touchTimeline.push(Date.now());
this.touchCounter++;
if (!this.countTimer) {
this.countTimer = setTimeout(() =>{
this.touchCounter = 0;
clearTimeout(this.countTimer);
this.countTimer = null;
}, 2000);
}
if (this.touchCounter == this.need) {
clearTimeout(this.countTimer);
this.countTimer = null;
if (this.hat.active) {
this.hat.active = false
} else {
this.hat.active = true
}
}
});
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "9c2d1f95-a5c9-46fb-bccb-d8ddfea5bc5c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class CoverClass extends cc.Component {
// @property
// url: string = '';
// @property(cc.Node)
// coverFrame: cc.SpriteFrame = null;
coverNode: cc.Node = null;
loaded = false;
spriteFrameCache = {};
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.coverNode = this.node.getChildByName('cover')
}
start () {
// this.coverFrame = this.coverNode.getComponent(cc.Sprite).spriteFrame
}
setSpriteFrame(spriteFrame) {
if(!this.coverNode) {
return;
}
if(!spriteFrame) {
return;
}
const {width, height} = spriteFrame.getOriginalSize()
this.coverNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
this.coverNode.width = width;
this.coverNode.height = height;
const sx = this.node.width / width;
const sy = this.node.height / height;
const s = Math.min(sx, sy);
const scale = Math.round(s * 1000) / 1000;
this.coverNode.scale = scale * .9
return spriteFrame
}
setUrl(url) {
if (!url) {
return;
}
if (this.spriteFrameCache[url]) {
this.setSpriteFrame(this.spriteFrameCache[url]);
return;
}
if (this.coverNode) {
cc.assetManager.loadRemote( url, (err, tex) => {
const spriteFrame = new cc.SpriteFrame(tex);
// console.log(spriteFrame);
this.setSpriteFrame(spriteFrame);
this.spriteFrameCache[url] = spriteFrame
});
}
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "bd34e6b2-034d-4fd0-a68e-31ab31b1333e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -172,8 +172,6 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -172,8 +172,6 @@ export class MyCocosSceneComponent extends cc.Component {
}); });
} }
}); });
}else{
cb && cb();
} }
} }
} }
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "915ea301-b224-43b0-92cc-5f419c9b54c7",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "479b1654-507c-41d0-af5b-94ab3e8a9a0b",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"ver": "1.1.2",
"uuid": "0e080fff-3cc9-4584-b02c-b71a64a9208f",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment