添加了几个英雄
This commit is contained in:
85
assets/script/game/hero/HeroSpine.ts
Normal file
85
assets/script/game/hero/HeroSpine.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-08-04 15:08:35
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:26
|
||||
*/
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Animation, AnimationClip, AnimationState,} from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../../script/game/common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* RPG SPINE角色模型
|
||||
*/
|
||||
@ccclass('HeroSpine')
|
||||
export class HeroSpine extends Component {
|
||||
@property(Animation)
|
||||
animator: Animation = null!;
|
||||
idle_clip: AnimationClip = null!;
|
||||
atk_clip: AnimationClip = null!;
|
||||
max_clip: AnimationClip = null!;
|
||||
move_clip: AnimationClip = null!;
|
||||
default_clip:string = "idle";
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
this.initAnimator();
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
this.idle_clip = this.animator.clips[0];
|
||||
this.atk_clip = this.animator.clips[1];
|
||||
this.max_clip = this.animator.clips[2];
|
||||
this.move_clip = this.animator.clips[3];
|
||||
let animation = this.animator.getComponent(Animation);
|
||||
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.animator=this.node.getChildByName("anm").getComponent(Animation);
|
||||
// console.log("mon spine init",this.animator);
|
||||
}
|
||||
|
||||
onAnimationEvent(type: Animation.EventType, state: AnimationState){
|
||||
if(type==Animation.EventType.FINISHED){
|
||||
if(state.name==this.atk_clip.name||state.name==this.max_clip.name){
|
||||
this.default();
|
||||
}
|
||||
}
|
||||
}
|
||||
change_default(value:string){
|
||||
this.default_clip=value;
|
||||
this.animator.play(this.default_clip);
|
||||
}
|
||||
default() {
|
||||
this.animator.play(this.default_clip);
|
||||
}
|
||||
idle(){
|
||||
if(!this.animator.getState(this.idle_clip.name).isPlaying){
|
||||
this.animator.play(this.idle_clip.name);
|
||||
}
|
||||
}
|
||||
atk() {
|
||||
if(!this.animator.getState(this.atk_clip.name).isPlaying){
|
||||
this.animator.play(this.atk_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
max(){
|
||||
if(!this.animator.getState(this.max_clip.name).isPlaying){
|
||||
this.animator.play(this.max_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
move(){
|
||||
if(!this.animator.getState(this.move_clip.name).isPlaying){
|
||||
this.animator.play(this.move_clip.name);
|
||||
}
|
||||
}
|
||||
onDestroy() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user