123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { LQCollide } from "../../Collide/lq_collide_system/lq_collide";
- import { LevelMgr } from "../../levelMgr";
- import { EditorSet } from "../common/editorSet";
- import { GameLogic } from "../update/GameLogic";
- const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
- ccclass
- class AniData{
- loop: boolean;
- }
- @ccclass
- @executeInEditMode
- @playOnFocus
- export default class AniList extends GameLogic {
- @property(cc.Prefab) monster: cc.Prefab = null;
- @property([cc.AnimationClip]) aniClip = [];
- monsterNode: cc.Node;
- protected onLoad(): void {
- let monsterNode = new cc.Node('monsterGroup');
- this.monsterNode = monsterNode;
- EditorSet.DontShow(monsterNode);
- this.node.addChild(monsterNode);
- if(CC_EDITOR){
- let node = new cc.Node('Collide');
- this.node.addChild(node);
- node.zIndex = cc.macro.MAX_ZINDEX;
- EditorSet.DontShow(node);
- let debugDrawer = node.addComponent(cc.Graphics);
- debugDrawer.lineWidth = 5;
- debugDrawer.strokeColor = new cc.Color(255, 0, 0);
- debugDrawer.fillColor = new cc.Color(255, 0, 0);
- debugDrawer.circle(0, 0, 20);
- debugDrawer.stroke();
- }
- else{
- this.play();
- }
-
- }
- // protected onFocusInEditor(): void {
- // this.play();
- // }
- // protected onLostFocusInEditor(): void {
- // this.end();
- // }
- end(){
- this.monsterNode.destroyAllChildren();
- }
- play(): void {
- this.monsterNode.destroyAllChildren();
- if(!this.monster) {
- cc.log('设置怪物资源');
- return;
- }
- // let node = cc.instantiate(this.monster);
- // let ani = node.addComponent(cc.Animation);
- // this.monsterNode.addChild(node);
- // EditorSet.DontShow(node);
- // this.aniClip.forEach((v,k)=>{
- // ani.addClip(v, `path${k}`)
- // });
- // let cnt = 0;
- // let callAni = ()=>{
- // ani.play(`path${cnt}`);
- // ani.once(cc.Animation.EventType.FINISHED, ()=>{
- // cnt++;
- // if(cnt < this.aniClip.length){
- // callAni();
- // }
- // });
- // }
- // callAni();
- let monsterNode = cc.instantiate(this.monster);
- let cnt = 0;
- let callAni = ()=>{
- let aniNode = new cc.Node('AniItem');
- let parent = monsterNode.parent ? monsterNode.parent : this.monsterNode;
- monsterNode.removeFromParent(false);
- aniNode.addChild(monsterNode);
- parent.addChild(aniNode);
- let ani = aniNode.addComponent(cc.Animation);
- ani.addClip(this.aniClip[cnt], 'path')
- ani.play('path');
- ani.once(cc.Animation.EventType.FINISHED, ()=>{
- cnt++;
- if(cnt < this.aniClip.length){
- callAni();
- }
- });
- }
- callAni();
- }
- gameUpdate(dt: number): void {
- // if(CC_EDITOR) return;
- // if(this.monsterNode.getComponentsInChildren(LQCollide).length > 0) return;
- // LevelMgr.inst.next();
- // 结束
- }
- }
|