From c84e625fde2c4ade6332fe4942ea100b304d1dc0 Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Fri, 30 Aug 2019 14:50:11 +0800 Subject: [PATCH] fix curvedata (#5288) update --- cocos/core/animation/animation-clip.ts | 123 ++++++++++++------------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/cocos/core/animation/animation-clip.ts b/cocos/core/animation/animation-clip.ts index 3b28a3d227..c134a96424 100644 --- a/cocos/core/animation/animation-clip.ts +++ b/cocos/core/animation/animation-clip.ts @@ -106,20 +106,16 @@ export class AnimationClip extends Asset { values[i] = spriteFrames[i]; } clip.keys = [keys]; - clip.curveDatas = { - '/': { - comps: { - // component - 'cc.SpriteComponent': { - // component properties - spriteFrame: { - keys: 0, - values, - }, - }, - }, - }, - }; + clip.curves = [{ + modifiers: [ + new ComponentModifier('cc.SpriteComponent'), + 'spriteFrame' + ], + data: { + keys: 0, + values, + } + }]; return clip; } @@ -147,7 +143,7 @@ export class AnimationClip extends Asset { * @deprecated 请转用 `this.curves` */ @property - public curveDatas?: ICurveData = {}; + private curveDatas?: ICurveData = {}; @property private _curves: ITargetCurveData[] = []; @@ -228,7 +224,7 @@ export class AnimationClip extends Asset { } get hash () { - if (!this._hash) { this._hash = murmurhash2_32_gc(JSON.stringify(this.curveDatas), 666); } + if (!this._hash) { this._hash = murmurhash2_32_gc(JSON.stringify(this._getDeprecatedCurveDatas()), 666); } return this._hash; } @@ -384,56 +380,55 @@ export class AnimationClip extends Asset { } } delete this.curveDatas; - Object.defineProperty(this, 'curveDatas', { - get: () => { - const result: ICurveData = {}; - for (const curve of this._curves) { - if (curve.modifiers.length === 0 || - !isCustomTargetModifier(curve.modifiers[0], HierachyModifier)) { - continue; - } + } - let componentName: string | null = null; - let propertyName: string | undefined; - if (curve.modifiers.length === 2 && - isPropertyModifier(curve.modifiers[1])) { - propertyName = curve.modifiers[1] as PropertyModifier; - } else if (curve.modifiers.length === 3 && - isCustomTargetModifier(curve.modifiers[1], ComponentModifier) && - isPropertyModifier(curve.modifiers[2])) { - componentName = (curve.modifiers[1] as ComponentModifier).component; - propertyName = curve.modifiers[2] as PropertyModifier; - } else { - continue; - } - - const path = (curve.modifiers[0] as HierachyModifier).path; - - if (!(path in result)) { - result[path] = {}; - } - const nodeCurveData = result[path]; - let objectCurveData: IObjectCurveData | undefined; - if (componentName) { - if (!('comps' in nodeCurveData)) { - nodeCurveData.comps = {}; - } - const componentCurveData = nodeCurveData.comps!; - if (!(componentName in componentCurveData)) { - componentCurveData[componentName] = {}; - } - objectCurveData = componentCurveData[componentName]; - } else { - if (!('props' in nodeCurveData)) { - nodeCurveData.props = {}; - } - objectCurveData = nodeCurveData.props!; - } - objectCurveData[propertyName] = curve.data; - } - return result; + private _getDeprecatedCurveDatas () { + const result: ICurveData = {}; + for (const curve of this._curves) { + if (curve.modifiers.length === 0 || + !isCustomTargetModifier(curve.modifiers[0], HierachyModifier)) { + continue; } - }); + + let componentName: string | null = null; + let propertyName: string | undefined; + if (curve.modifiers.length === 2 && + isPropertyModifier(curve.modifiers[1])) { + propertyName = curve.modifiers[1] as PropertyModifier; + } else if (curve.modifiers.length === 3 && + isCustomTargetModifier(curve.modifiers[1], ComponentModifier) && + isPropertyModifier(curve.modifiers[2])) { + componentName = (curve.modifiers[1] as ComponentModifier).component; + propertyName = curve.modifiers[2] as PropertyModifier; + } else { + continue; + } + + const path = (curve.modifiers[0] as HierachyModifier).path; + + if (!(path in result)) { + result[path] = {}; + } + const nodeCurveData = result[path]; + let objectCurveData: IObjectCurveData | undefined; + if (componentName) { + if (!('comps' in nodeCurveData)) { + nodeCurveData.comps = {}; + } + const componentCurveData = nodeCurveData.comps!; + if (!(componentName in componentCurveData)) { + componentCurveData[componentName] = {}; + } + objectCurveData = componentCurveData[componentName]; + } else { + if (!('props' in nodeCurveData)) { + nodeCurveData.props = {}; + } + objectCurveData = nodeCurveData.props!; + } + objectCurveData[propertyName] = curve.data; + } + return result; } }