should not call onEnable if not executeInEditMode

This commit is contained in:
Jare Guo
2015-12-16 11:05:50 +08:00
parent 3f58254507
commit 9959210cd0
2 changed files with 32 additions and 17 deletions
+17 -17
View File
@@ -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) {
+15
View File
@@ -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');