12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- // 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
- const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
- @ccclass
- @executeInEditMode
- @playOnFocus
- export default class MonsterFactory extends cc.Component {
- @property(cc.Prefab) monster: cc.Prefab = null;
- @property(cc.AnimationClip) aniClip:cc.AnimationClip = null;
- @property(cc.Integer)
- public get num(): number {
- return this._num;
- }
- public set num(value: number) {
- this._num = value;
- if(!CC_EDITOR) return;
- this.play();
- }
- @property(cc.Integer)
- private _num: number = 0;
- @property(cc.Integer)
- public get time(): number {
- return this._time;
- }
- public set time(value: number) {
- this._time = value;
- if(!CC_EDITOR) return;
- this.play();
- }
- @property(cc.Integer)
- private _time: number = 1;
- protected start(): void {
- this.play();
- }
- protected play(): void {
- this.node.destroyAllChildren();
- for (let index = 0; index < this.num; index++) {
- let node = cc.instantiate(this.monster);
- let ani = node.addComponent(cc.Animation);
- ani.addClip(this.aniClip)
- node._objFlags |= cc.Object.Flags.DontSave | cc.Object.Flags.LockedInEditor;
- node.active = false;
- this.node.addChild(node);
- setTimeout(() => {
- node.active = true;
- ani.play('path1');
- }, 1000 * this.time * index);
- }
- }
- }
|