From 4cc9531e8951dddf756d0bfd23aa09d2eb1f5c1d Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Wed, 24 Apr 2019 16:40:50 +0800 Subject: [PATCH] remove WrapMode from cc, instead make it as a member of AnimationClip (#4292) * remove WrapMode from cc, instead make it as a member of AnimationClip * fix bug in getChildByPath --- cocos/animation/animation-clip.ts | 8 +++++--- cocos/animation/types.ts | 1 - cocos/scene-graph/base-node.ts | 12 +++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cocos/animation/animation-clip.ts b/cocos/animation/animation-clip.ts index 6e638db8b5..822ee6f1e5 100644 --- a/cocos/animation/animation-clip.ts +++ b/cocos/animation/animation-clip.ts @@ -10,7 +10,7 @@ import { CurveValue, DynamicAnimCurve, EasingMethodName, ICurveTarget, RatioSamp import { AnimationState } from './animation-state'; import * as blending from './blending'; import { MotionPath, sampleMotionPaths } from './motion-path-helper'; -import { ILerpable, isLerpable, WrapMode } from './types'; +import { ILerpable, isLerpable, WrapMode as AnimationWrapMode } from './types'; interface IAnimationEvent { frame: number; @@ -43,6 +43,7 @@ interface ICurveData { @ccclass('cc.AnimationClip') export class AnimationClip extends Asset { + public static WrapMode = AnimationWrapMode; /** * !#en Duration of this animation. @@ -114,7 +115,7 @@ export class AnimationClip extends Asset { * !#zh 动画的循环模式。 */ @property - public wrapMode = WrapMode.Normal; + public wrapMode = AnimationWrapMode.Normal; /** * !#en Curve data. @@ -259,8 +260,9 @@ export class AnimationClip extends Asset { (key) => key / this._duration))); const curves: DynamicAnimCurve[] = []; for (const path of Object.keys(this.curveDatas)) { - const target = find(path, root); + const target = root.getChildByPath(path); if (!target) { + console.warn(`Target animation node referenced by path ${path} is not found(from ${root.name}).`); continue; } const curveData = this.curveDatas[path]; diff --git a/cocos/animation/types.ts b/cocos/animation/types.ts index e0f594e5c6..7036a8809b 100644 --- a/cocos/animation/types.ts +++ b/cocos/animation/types.ts @@ -61,7 +61,6 @@ export enum WrapMode { } ccenum(WrapMode); -cc.WrapMode = WrapMode; /** * For internal diff --git a/cocos/scene-graph/base-node.ts b/cocos/scene-graph/base-node.ts index 88f6a32fff..a773b579a7 100644 --- a/cocos/scene-graph/base-node.ts +++ b/cocos/scene-graph/base-node.ts @@ -494,18 +494,12 @@ export class BaseNode extends CCObject { * var child = node.getChildByPath("Test Node"); */ public getChildByPath (path: string) { - if (path.length === 0) { - return this; - } const segments = path.split('/'); - - // Starts with / - if (segments.length !== 0 && segments[0].length === 0) { - segments.shift(); - } - let lastNode: this = this; for (const segment of segments) { + if (segment.length === 0) { + continue; + } const next = lastNode.children.find((childNode) => childNode.name === segment); if (!next) { return null;