消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.6 KiB

1 week ago
//*********************
// create by 流云
// time: 2025.03.10
// desc:
//*********************
import { _decorator, Camera, CCFloat, Component, director, Node, Tween, tween, UIOpacity, Vec3 } from 'cc';
import { MoveCamera } from './MoveCamera';
const { ccclass, property } = _decorator;
/**
*
*
* pathTime为每个路径节点对应的时间
* AA移动到BB移动到C的动画
*
* 13ABC
* 23transform属性ABC的位置
* 3pathTime长度设置为310.52
* 4playOnEnable设置为true
* position
*/
@ccclass('TargetTween')
export class TargetTween extends Component {
@property({ type: Node, tooltip: "动画目标节点" })
targetNode: Node = null;
@property({ type: CCFloat, tooltip: "路径节点对应的时间" })
pathTime: number[] = [];
@property({ tooltip: "显示时播放" })
playOnEnable: boolean = true;
@property({ tooltip: "循环" })
Loop: boolean = false;
private _onTweenUpdateCallback: Function = null;
protected onLoad(): void {
if (!this.targetNode)
this.targetNode = this.node;
}
protected onEnable(): void {
this.startPlay();
}
/**
*
* @param onUpdateCallback
* @param onCompleteCallback
*/
async startPlay(onUpdateCallback?: Function, onCompleteCallback?: Function) {
this._onTweenUpdateCallback = onUpdateCallback;
if (!this.node || !this.node.isValid) return;
for (let i = 0; i < this.node.children.length; i++) {
if (i < this.node.children.length) {
let n = this.node.children[i];
if (n.getComponent(MoveCamera)) {
await this.playCameraTween(n);
} else {
if (i < this.pathTime.length) {
let t = this.pathTime[i];
await this.playTween(n, t);
}
}
}
}
if (this.Loop && this.node && this.node.isValid) {
this.startPlay(onUpdateCallback, onCompleteCallback);
} else {
if (this.targetNode && this.targetNode.active && onCompleteCallback) onCompleteCallback();
}
}
stopPlay() {
this._onTweenUpdateCallback = null;
Tween.stopAllByTarget(this.targetNode);
}
private playTween(target: Node, time: number) {
return new Promise((resolve) => {
tween(this.targetNode).to(time, { worldPosition: target.worldPosition, scale: target.scale, rotation: target.rotation }, {
onUpdate: () => {
if (this._onTweenUpdateCallback) this._onTweenUpdateCallback();
}
}).call(() => {
resolve(null);
}).start();
let op1 = target.getComponent(UIOpacity);
let op2 = this.targetNode.getComponent(UIOpacity);
if (op1 && op2) {
tween(op2).to(time, { opacity: op1.opacity }).start();
}
});
}
private playCameraTween(target: Node) {
return new Promise((resolve) => {
target.getComponent(MoveCamera).startMove(() => {
resolve(null);
})
})
}
}