add:统一控制所有动画播放速度的参数; fix:play方法修改

This commit is contained in:
YipLee 2021-08-02 22:56:22 +08:00
parent 7a1b589424
commit 4db3a36500
8 changed files with 128 additions and 48 deletions

View File

@ -43,14 +43,23 @@ export default class AnimatorBase extends cc.Component {
/** 自定义的动画播放控制器 */ /** 自定义的动画播放控制器 */
protected _animationPlayer: AnimationPlayer = null; protected _animationPlayer: AnimationPlayer = null;
protected _extraMulti: number = 1;
/** 统一控制所有动画播放速度的参数 */
public get extraMulti(): number { return this._extraMulti; }
public set extraMulti(v: number) {
if (this._extraMulti === v) {
return;
}
this._extraMulti = v;
this.updatePlaySpeed();
}
/** 当前状态名 */ /** 当前状态名 */
public get curStateName(): string { public get curStateName(): string { return this._ac.curState.name; }
return this._ac.curState.name;
}
/** 当前动画名 */ /** 当前动画名 */
public get curStateMotion(): string { public get curStateMotion(): string { return this._ac.curState.motion; }
return this._ac.curState.motion; /** 当前动画是否播放完毕 */
} public get animComplete(): boolean { return this._ac.animComplete; }
/** /**
* 0-3 * 0-3
@ -83,13 +92,21 @@ export default class AnimatorBase extends cc.Component {
}); });
} }
private updateAnimator() { /**
*
*/
private updatePlaySpeed() {
// 混合当前动画播放速度 // 混合当前动画播放速度
let playSpeed = this._ac.curState.speed; let playSpeed = this._ac.curState.speed * this.extraMulti;
if (this._ac.curState.multi) { if (this._ac.curState.multi) {
playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1; playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1;
} }
this.scaleTime(playSpeed); this.scaleTime(playSpeed);
}
private updateAnimator() {
// 更新动画播放速度
this.updatePlaySpeed();
// 更新AnimatorStateLogic // 更新AnimatorStateLogic
if (this._stateLogicMap) { if (this._stateLogicMap) {
@ -217,7 +234,7 @@ export default class AnimatorBase extends cc.Component {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {

View File

@ -79,17 +79,20 @@ export default class AnimatorController {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {
if (!this._states.has(stateName) || this._curState.name === stateName) { if (!this._states.has(stateName)) {
return; return;
} }
// 重置动画完成标记 // 重置动画完成标记
this.animComplete = false; this.animComplete = false;
this.changeState(stateName); let oldState = this._curState;
this._curState = this._states.get(stateName);
this._animator.onStateChange(oldState, this._curState);
this.updateState();
} }
/** /**

View File

@ -44,14 +44,23 @@ export default class AnimatorBase extends Component {
/** 自定义的动画播放控制器 */ /** 自定义的动画播放控制器 */
protected _animationPlayer: AnimationPlayer = null!; protected _animationPlayer: AnimationPlayer = null!;
protected _extraMulti: number = 1;
/** 统一控制所有动画播放速度的参数 */
public get extraMulti(): number { return this._extraMulti; }
public set extraMulti(v: number) {
if (this._extraMulti === v) {
return;
}
this._extraMulti = v;
this.updatePlaySpeed();
}
/** 当前状态名 */ /** 当前状态名 */
public get curStateName(): string { public get curStateName(): string { return this._ac.curState.name; }
return this._ac.curState.name;
}
/** 当前动画名 */ /** 当前动画名 */
public get curStateMotion(): string { public get curStateMotion(): string { return this._ac.curState.motion; }
return this._ac.curState.motion; /** 当前动画是否播放完毕 */
} public get animComplete(): boolean { return this._ac.animComplete; }
/** /**
* 0-3 * 0-3
@ -84,13 +93,21 @@ export default class AnimatorBase extends Component {
}); });
} }
private updateAnimator() { /**
*
*/
private updatePlaySpeed() {
// 混合当前动画播放速度 // 混合当前动画播放速度
let playSpeed = this._ac.curState.speed; let playSpeed = this._ac.curState.speed * this.extraMulti;
if (this._ac.curState.multi) { if (this._ac.curState.multi) {
playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1; playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1;
} }
this.scaleTime(playSpeed); this.scaleTime(playSpeed);
}
private updateAnimator() {
// 更新动画播放速度
this.updatePlaySpeed();
// 更新AnimatorStateLogic // 更新AnimatorStateLogic
if (this._stateLogicMap) { if (this._stateLogicMap) {
@ -218,7 +235,7 @@ export default class AnimatorBase extends Component {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {

View File

@ -80,17 +80,20 @@ export default class AnimatorController {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {
if (!this._states.has(stateName) || this._curState.name === stateName) { if (!this._states.has(stateName)) {
return; return;
} }
// 重置动画完成标记 // 重置动画完成标记
this.animComplete = false; this.animComplete = false;
this.changeState(stateName); let oldState = this._curState;
this._curState = this._states.get(stateName)!;
this._animator.onStateChange(oldState, this._curState);
this.updateState();
} }
/** /**

View File

@ -43,14 +43,23 @@ export default class AnimatorBase extends cc.Component {
/** 自定义的动画播放控制器 */ /** 自定义的动画播放控制器 */
protected _animationPlayer: AnimationPlayer = null; protected _animationPlayer: AnimationPlayer = null;
protected _extraMulti: number = 1;
/** 统一控制所有动画播放速度的参数 */
public get extraMulti(): number { return this._extraMulti; }
public set extraMulti(v: number) {
if (this._extraMulti === v) {
return;
}
this._extraMulti = v;
this.updatePlaySpeed();
}
/** 当前状态名 */ /** 当前状态名 */
public get curStateName(): string { public get curStateName(): string { return this._ac.curState.name; }
return this._ac.curState.name;
}
/** 当前动画名 */ /** 当前动画名 */
public get curStateMotion(): string { public get curStateMotion(): string { return this._ac.curState.motion; }
return this._ac.curState.motion; /** 当前动画是否播放完毕 */
} public get animComplete(): boolean { return this._ac.animComplete; }
/** /**
* 0-3 * 0-3
@ -83,13 +92,21 @@ export default class AnimatorBase extends cc.Component {
}); });
} }
private updateAnimator() { /**
*
*/
private updatePlaySpeed() {
// 混合当前动画播放速度 // 混合当前动画播放速度
let playSpeed = this._ac.curState.speed; let playSpeed = this._ac.curState.speed * this.extraMulti;
if (this._ac.curState.multi) { if (this._ac.curState.multi) {
playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1; playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1;
} }
this.scaleTime(playSpeed); this.scaleTime(playSpeed);
}
private updateAnimator() {
// 更新动画播放速度
this.updatePlaySpeed();
// 更新AnimatorStateLogic // 更新AnimatorStateLogic
if (this._stateLogicMap) { if (this._stateLogicMap) {
@ -217,7 +234,7 @@ export default class AnimatorBase extends cc.Component {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {

View File

@ -79,17 +79,20 @@ export default class AnimatorController {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {
if (!this._states.has(stateName) || this._curState.name === stateName) { if (!this._states.has(stateName)) {
return; return;
} }
// 重置动画完成标记 // 重置动画完成标记
this.animComplete = false; this.animComplete = false;
this.changeState(stateName); let oldState = this._curState;
this._curState = this._states.get(stateName);
this._animator.onStateChange(oldState, this._curState);
this.updateState();
} }
/** /**

View File

@ -44,14 +44,23 @@ export default class AnimatorBase extends Component {
/** 自定义的动画播放控制器 */ /** 自定义的动画播放控制器 */
protected _animationPlayer: AnimationPlayer = null!; protected _animationPlayer: AnimationPlayer = null!;
protected _extraMulti: number = 1;
/** 统一控制所有动画播放速度的参数 */
public get extraMulti(): number { return this._extraMulti; }
public set extraMulti(v: number) {
if (this._extraMulti === v) {
return;
}
this._extraMulti = v;
this.updatePlaySpeed();
}
/** 当前状态名 */ /** 当前状态名 */
public get curStateName(): string { public get curStateName(): string { return this._ac.curState.name; }
return this._ac.curState.name;
}
/** 当前动画名 */ /** 当前动画名 */
public get curStateMotion(): string { public get curStateMotion(): string { return this._ac.curState.motion; }
return this._ac.curState.motion; /** 当前动画是否播放完毕 */
} public get animComplete(): boolean { return this._ac.animComplete; }
/** /**
* 0-3 * 0-3
@ -84,13 +93,21 @@ export default class AnimatorBase extends Component {
}); });
} }
private updateAnimator() { /**
*
*/
private updatePlaySpeed() {
// 混合当前动画播放速度 // 混合当前动画播放速度
let playSpeed = this._ac.curState.speed; let playSpeed = this._ac.curState.speed * this.extraMulti;
if (this._ac.curState.multi) { if (this._ac.curState.multi) {
playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1; playSpeed *= this._ac.params.getNumber(this._ac.curState.multi) || 1;
} }
this.scaleTime(playSpeed); this.scaleTime(playSpeed);
}
private updateAnimator() {
// 更新动画播放速度
this.updatePlaySpeed();
// 更新AnimatorStateLogic // 更新AnimatorStateLogic
if (this._stateLogicMap) { if (this._stateLogicMap) {
@ -218,7 +235,7 @@ export default class AnimatorBase extends Component {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {

View File

@ -80,17 +80,20 @@ export default class AnimatorController {
} }
/** /**
* *
* @param * @param
*/ */
public play(stateName: string) { public play(stateName: string) {
if (!this._states.has(stateName) || this._curState.name === stateName) { if (!this._states.has(stateName)) {
return; return;
} }
// 重置动画完成标记 // 重置动画完成标记
this.animComplete = false; this.animComplete = false;
this.changeState(stateName); let oldState = this._curState;
this._curState = this._states.get(stateName)!;
this._animator.onStateChange(oldState, this._curState);
this.updateState();
} }
/** /**