fix animation event bug (#4462)

This commit is contained in:
Leslie Leigh
2019-05-21 13:08:43 +08:00
committed by Weiliang Wang
parent 27a2ab03ae
commit 70ee2668c7
2 changed files with 9 additions and 3 deletions
+8 -2
View File
@@ -177,6 +177,7 @@ export class AnimationState extends Playable {
private _lastWrapInfoEvent: WrappedInfo | null = null;
private _process = this.process;
private _target: Node | null = null;
private _targetNode: Node | null = null;
private _clip: AnimationClip;
private _name: string;
private _lastIterations?: number;
@@ -197,6 +198,7 @@ export class AnimationState extends Playable {
public initialize (root: Node) {
this._curveLoaded = true;
this._curveInstances.length = 0;
this._targetNode = root;
const clip = this._clip;
this.duration = clip.duration;
@@ -290,6 +292,10 @@ export class AnimationState extends Playable {
this._target = target;
}
public setTargetNode (target: Node) {
this._targetNode = target;
}
public setTime (time: number) {
this._currentFramePlayed = false;
this.time = time || 0;
@@ -618,7 +624,7 @@ export class AnimationState extends Playable {
}
private _fireEvent (index: number) {
if (!this._target || !this._target.isValid) {
if (!this._targetNode || !this._targetNode.isValid) {
return;
}
@@ -628,7 +634,7 @@ export class AnimationState extends Playable {
}
const eventGroup = eventGroups[index];
const components = this._target.components;
const components = this._targetNode.components;
for (const event of eventGroup.events) {
const { functionName } = event;
for (const component of components) {
+1 -1
View File
@@ -454,7 +454,7 @@ export class AnimationComponent extends Component implements IEventTarget {
private _createState (clip: AnimationClip, name?: string) {
const state = new AnimationState(clip, name);
state._setEventTarget(this.node);
state._setEventTarget(this);
this._nameToState[state.name] = state;
return state;
}