From 9959210cd071f8a9dc75a16a3e2fa2a385b14bf6 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 16 Dec 2015 11:05:50 +0800 Subject: [PATCH] should not call onEnable if not executeInEditMode --- cocos2d/core/components/CCComponent.js | 34 +++++++++++++------------- test/qunit/unit/test-component.js | 15 ++++++++++++ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index 566070cf92..0eea6c9dea 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -19,23 +19,23 @@ var callOnFocusInTryCatch = CC_EDITOR && eval(ExecInTryCatchTmpl.replace(/_FUNC_ var callOnLostFocusInTryCatch = CC_EDITOR && eval(ExecInTryCatchTmpl.replace(/_FUNC_/g, 'onLostFocusInEditMode')); function callOnEnable (self, enable) { - //if (CC_EDITOR) { - // if (enable ) { - // if ( !(self._objFlags & IsEditorOnEnabledCalled) ) { - // editorCallback.onComponentEnabled(self); - // self._objFlags |= IsEditorOnEnabledCalled; - // } - // } - // else { - // if (self._objFlags & IsEditorOnEnabledCalled) { - // editorCallback.onComponentDisabled(self); - // self._objFlags &= ~IsEditorOnEnabledCalled; - // } - // } - // if ( !(cc.game.isPlaying || self.constructor._executeInEditMode) ) { - // return; - // } - //} + if (CC_EDITOR) { + //if (enable ) { + // if ( !(self._objFlags & IsEditorOnEnabledCalled) ) { + // editorCallback.onComponentEnabled(self); + // self._objFlags |= IsEditorOnEnabledCalled; + // } + //} + //else { + // if (self._objFlags & IsEditorOnEnabledCalled) { + // editorCallback.onComponentDisabled(self); + // self._objFlags &= ~IsEditorOnEnabledCalled; + // } + //} + if ( !(cc.engine.isPlaying || self.constructor._executeInEditMode) ) { + return; + } + } var enableCalled = self._objFlags & IsOnEnableCalled; if (enable) { if (!enableCalled) { diff --git a/test/qunit/unit/test-component.js b/test/qunit/unit/test-component.js index 9be6308397..080f117ce5 100644 --- a/test/qunit/unit/test-component.js +++ b/test/qunit/unit/test-component.js @@ -19,6 +19,21 @@ test('Inheritance of editor properties', function () { strictEqual(child._playOnFocus, true, 'should inherit playOnFocus from base component'); }); +//test('should not call lifecycle methods if not executeInEditMode', function () { +// var Comp = cc.Class({ +// extends: CallbackTester, +// ctor: function () { +// this.notExpect(CallbackTester.OnLoad, 'onLoad'); +// this.notExpect(CallbackTester.OnEnable, 'onEnable'); +// } +// }); +// +// var parent = new cc.Node(); +// cc.director.getScene().addChild(parent); +// var comp = parent.addComponent(Comp); +// comp.stopTest(); +//}); + //asyncTest('invoke using name', function () { // var cb = new Callback().setDisabledMessage('method should not invokes in this frame'); // var cb2 = new Callback().disable('method should not being called after destroyed');