You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
|
4 years ago
|
|
||
|
|
const {ccclass, property} = cc._decorator;
|
||
|
|
|
||
|
|
import {gameMY} from './gameModule';
|
||
|
|
import {columnControl} from './columnControl';
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@ccclass
|
||
|
|
export default class NewClass extends cc.Component {
|
||
|
|
|
||
|
|
|
||
|
|
@property((cc.Node))
|
||
|
|
gameModule: cc.Node = null;
|
||
|
|
|
||
|
|
@property((cc.Node))
|
||
|
|
columnControl: cc.Node = null;
|
||
|
|
|
||
|
|
private secCounter: number;
|
||
|
|
|
||
|
|
private gameModuleScript;
|
||
|
|
private columnControlScript;
|
||
|
|
|
||
|
|
protected onLoad () {
|
||
|
|
cc.log("this is ee onLoad");
|
||
|
|
// 呼叫其他 script 的方法或資源
|
||
|
|
this.gameModuleScript = this.gameModule.getComponent('gameMY')
|
||
|
|
this.columnControlScript = this.columnControl.getComponent('columnControl')
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onEnable(){
|
||
|
|
cc.log("this is ee onEnable");
|
||
|
|
}
|
||
|
|
|
||
|
|
protected start () {
|
||
|
|
cc.log("this is ee start");
|
||
|
|
this.secCounter = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
tempValue = true
|
||
|
|
|
||
|
|
protected update (dt) {
|
||
|
|
this.secCounter += dt;
|
||
|
|
|
||
|
|
// 測試 cc.resources.loadDir 載入時間 ==> 結論: 約需要 0.2~0.5秒
|
||
|
|
if(this.tempValue){
|
||
|
|
if(!(Object.keys(this.gameModuleScript.item_spriteFrame).length === 0)){
|
||
|
|
cc.log(" empty to full : " + this.secCounter)
|
||
|
|
this.tempValue = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if(this.secCounter >= 5) {
|
||
|
|
cc.log("engineer Function Update : " + this.secCounter)
|
||
|
|
this.secCounter = 0
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onDisable(): void {
|
||
|
|
cc.log("this is ee onDisable")
|
||
|
|
}
|
||
|
|
|
||
|
|
unitTest1():void {
|
||
|
|
this.gameModule.emit('Bob', 'unitTest1 Success')
|
||
|
|
}
|
||
|
|
|
||
|
|
disableColumn():void {
|
||
|
|
// this.node.active = !this.node.active;
|
||
|
|
this.columnControl.active = !this.columnControl.active;
|
||
|
|
}
|
||
|
|
|
||
|
|
unitTest3():void {
|
||
|
|
|
||
|
|
// @ts-ignore
|
||
|
|
this.itemList = Object.values(this.gameModuleScript.itemNameMapping)
|
||
|
|
|
||
|
|
for(let i=0;i<this.columnControl.childrenCount;i++){
|
||
|
|
let a = this.itemList[Math.floor(Math.random() * 12)];
|
||
|
|
this.columnControlScript.columnItem.push( a );
|
||
|
|
let c = this.gameModuleScript.item_spriteFrame[a]
|
||
|
|
this.columnControl.children[i].getComponent(cc.Sprite).spriteFrame = c
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|