| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class SpineAnimationCtrl extends cc.Component {
- private spineNode: sp.Skeleton = null;
- private spineCallback: Function = null;
- private completeCallback: Function = null;
- protected onLoad(): void {
- this.initProp();
- }
- private initProp() {
- this.spineNode = this.node.getComponent(sp.Skeleton);
- this.spineNode.setCompleteListener((endEntry: any) => {
- this.spineCallback && this.spineCallback(endEntry);
- });
- }
- protected start(): void {
-
- }
- playAnimation(aniName: string = "animation", isLoop: boolean = false, playedStatus: boolean = false, aniName2: string = "", isLoop2: boolean = false) {
- this.node.active = true;
- this.spineNode.setToSetupPose();
- this.spineNode.setAnimation(0, aniName, isLoop);
- this.spineCallback = (endEntry: any) => {
- let isEnd = false;
- if (aniName == endEntry.animation.name) {
- if (this.isValidString(aniName2)) {
- return this.spineNode.setAnimation(0, aniName2, isLoop2);
- }
- isEnd = true;
- } else {
- isEnd = true;
- }
- if (isEnd) {
- this.completeCallback && this.completeCallback();
- if (isLoop || isLoop2) {
- return;
- }
- this.node.active = playedStatus;
- }
- }
- }
- setCompleteCallback(callback: Function) {
- this.completeCallback = callback;
- }
- private isValidString(str: string | null | undefined): boolean {
- return !!str && str.trim().length > 0;
- }
- // generateAllNodes () {
- // // 取得挂点工具
- // let attachUtil = this.spineNode.attachUtil;
- // attachUtil.generateAllAttachedNodes();
- // // 因为同名骨骼可能不止一个,所以需要返回数组
- // let boneNodes = attachUtil.getAttachedNodes(this.boneName);
- // // 取第一个骨骼作为挂点
- // let boneNode = boneNodes[0];
- // boneNode.addChild(cc.instantiate(this.targetPrefab));
- // }
- // destroyAllNodes () {
- // let attachUtil = this.spineNode.attachUtil;
- // attachUtil.destroyAllAttachedNodes();
- // }
- // protected onEnable(): void {
-
- // }
- // protected onDisable(): void {
-
- // }
- // protected onDestroy(): void {
-
- // }
- }
|