Skip to content

Commit

Permalink
refactor: opt code
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhuang committed Sep 13, 2024
1 parent 83f0b16 commit 9805cb7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
12 changes: 6 additions & 6 deletions e2e/case/animator-stateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
const toWalkTransition = new AnimatorStateTransition();
toWalkTransition.destinationState = walkState;
toWalkTransition.duration = 0.2;
toWalkTransition.addCondition(AnimatorConditionMode.Greater, "playerSpeed", 0);
toWalkTransition.addCondition("playerSpeed", AnimatorConditionMode.Greater, 0);
idleState.addTransition(toWalkTransition);
idleToWalkTime =
//@ts-ignore
toWalkTransition.exitTime * idleState._getDuration() + toWalkTransition.duration * walkState._getDuration();

const exitTransition = idleState.addExitTransition();
exitTransition.addCondition(AnimatorConditionMode.Equals, "playerSpeed", 0);
exitTransition.addCondition("playerSpeed", AnimatorConditionMode.Equals, 0);
// to walk state
const toRunTransition = new AnimatorStateTransition();
toRunTransition.destinationState = runState;
toRunTransition.duration = 0.3;
toRunTransition.addCondition(AnimatorConditionMode.Greater, "playerSpeed", 0.5);
toRunTransition.addCondition("playerSpeed", AnimatorConditionMode.Greater, 0.5);
walkState.addTransition(toRunTransition);
walkToRunTime =
//@ts-ignore
Expand All @@ -82,7 +82,7 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
const toIdleTransition = new AnimatorStateTransition();
toIdleTransition.destinationState = idleState;
toIdleTransition.duration = 0.3;
toIdleTransition.addCondition(AnimatorConditionMode.Equals, "playerSpeed", 0);
toIdleTransition.addCondition("playerSpeed", AnimatorConditionMode.Equals, 0);
walkState.addTransition(toIdleTransition);
walkToIdleTime =
//@ts-ignore
Expand All @@ -94,7 +94,7 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
const RunToWalkTransition = new AnimatorStateTransition();
RunToWalkTransition.destinationState = walkState;
RunToWalkTransition.duration = 0.3;
RunToWalkTransition.addCondition(AnimatorConditionMode.Less, "playerSpeed", 0.5);
RunToWalkTransition.addCondition("playerSpeed", AnimatorConditionMode.Less, 0.5);
runState.addTransition(RunToWalkTransition);
runToWalkTime =
//@ts-ignore
Expand All @@ -105,7 +105,7 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
stateMachine.addEntryStateTransition(idleState);

const anyTransition = stateMachine.addAnyStateTransition(idleState);
anyTransition.addCondition(AnimatorConditionMode.Equals, "playerSpeed", 0);
anyTransition.addCondition("playerSpeed", AnimatorConditionMode.Equals, 0);
anyTransition.duration = 0.3;
let anyToIdleTime =
// @ts-ignore
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/animation/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ export class Animator extends Component {
cullingMode: AnimatorCullingMode = AnimatorCullingMode.None;
/** The playback speed of the Animator, 1.0 is normal playback speed. */
@assignmentClone
speed: number = 1.0;
speed = 1.0;

/** @internal */
_playFrameCount: number = -1;
_playFrameCount = -1;
/** @internal */
_onUpdateIndex: number = -1;
_onUpdateIndex = -1;

protected _animatorController: AnimatorController;

@ignoreClone
protected _controllerUpdateFlag: BoolUpdateFlag;
@ignoreClone
protected _updateMark: number = 0;
protected _updateMark = 0;

@ignoreClone
private _animatorLayersData: AnimatorLayerData[] = [];
private _animatorLayersData = new Array<AnimatorLayerData>();
@ignoreClone
private _curveOwnerPool: Record<number, Record<string, AnimationCurveOwner<KeyframeValueType>>> = Object.create(null);
@ignoreClone
Expand All @@ -61,11 +61,9 @@ export class Animator extends Component {

@ignoreClone
private _tempAnimatorStateInfo: IAnimatorStateInfo = { layerIndex: -1, state: null };
@ignoreClone
private _tempTriggerParametersName: string[] = [];

@ignoreClone
private _controlledRenderers: Renderer[] = [];
private _controlledRenderers = new Array<Renderer>();

/**
* All layers from the AnimatorController which belongs this Animator.
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/animation/AnimatorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class AnimatorController extends ReferResource {
* Add a parameter to the controller.
* @param name - The name of the parameter
* @param defaultValue - The default value of the parameter
* @param isTrigger - Is the parameter a trigger, if true, the parameter will act as a trigger, trigger work mostly like bool parameter, but their values are reset to false after check a Transition.
*/
addParameter(name: string, defaultValue?: AnimatorControllerParameterValue): AnimatorControllerParameter {
return this._addParameter(name, defaultValue, false);
Expand Down

0 comments on commit 9805cb7

Please sign in to comment.