From 3e4171ef6394477c156f600d7b9ee24603484dfd Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 19 Jun 2018 11:29:20 +0800 Subject: [PATCH] Fix components undo issue in editor (#2871) --- cocos2d/core/graphics/graphics.js | 6 ++++++ cocos2d/videoplayer/CCVideoPlayer.js | 6 ++++++ cocos2d/webview/CCWebView.js | 6 ++++++ extensions/spine/Skeleton.js | 11 +++++++++++ 4 files changed, 29 insertions(+) diff --git a/cocos2d/core/graphics/graphics.js b/cocos2d/core/graphics/graphics.js index a6ffd1c955..aa62182cb4 100644 --- a/cocos2d/core/graphics/graphics.js +++ b/cocos2d/core/graphics/graphics.js @@ -172,6 +172,12 @@ let Graphics = cc.Class({ LineCap: LineCap }, + onRestore () { + if (!this._impl) { + this._impl = Graphics._assembler.createImpl(); + } + }, + onEnable () { this._super(); this._activateMaterial(); diff --git a/cocos2d/videoplayer/CCVideoPlayer.js b/cocos2d/videoplayer/CCVideoPlayer.js index 4e18bbd0cc..d0584aa32a 100644 --- a/cocos2d/videoplayer/CCVideoPlayer.js +++ b/cocos2d/videoplayer/CCVideoPlayer.js @@ -322,6 +322,12 @@ let VideoPlayer = cc.Class({ } }, + onRestore () { + if (!this._impl) { + this._impl = new WebViewImpl(); + } + }, + onEnable () { if (this._impl) { this._impl.enable(); diff --git a/cocos2d/webview/CCWebView.js b/cocos2d/webview/CCWebView.js index 43a8095da1..6ead76a7ef 100644 --- a/cocos2d/webview/CCWebView.js +++ b/cocos2d/webview/CCWebView.js @@ -114,6 +114,12 @@ let WebView = cc.Class({ this._impl = new WebViewImpl(); }, + onRestore () { + if (!this._impl) { + this._impl = new WebViewImpl(); + } + }, + onEnable () { let impl = this._impl; impl.createDomElementIfNeeded(this.node.width, this.node.height); diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index 29efe5dda5..ae018f3017 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -376,6 +376,17 @@ sp.Skeleton = cc.Class({ this._updateSkeletonData(); }, + onRestore () { + // Destroyed and restored in Editor + if (!this._material) { + this._boundingBox = cc.rect(); + this._material = new SpriteMaterial(); + this._renderDatas = []; + this._debugNode = new Node(); + this._debugRenderer = this._debugNode.addComponent(Graphics); + } + }, + onDestroy () { this._super(); this._debugNode.destroy();