mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2117 from jareguo/master
prefab should not resync if is instantiated by its parent (which is not a prefab)
This commit is contained in:
+27
-4
@@ -1061,11 +1061,12 @@ var Node = cc.Class({
|
||||
*/
|
||||
_onBatchCreated () {
|
||||
var prefabInfo = this._prefab;
|
||||
if (prefabInfo && prefabInfo.sync && !prefabInfo._synced) {
|
||||
// checks to ensure no recursion, recursion will caused only on old data.
|
||||
if (prefabInfo.root === this) {
|
||||
PrefabHelper.syncWithPrefab(this);
|
||||
if (prefabInfo && prefabInfo.sync && prefabInfo.root === this) {
|
||||
if (CC_DEV) {
|
||||
// TODO - remove all usage of _synced
|
||||
cc.assert(!prefabInfo._synced, 'prefab should not synced');
|
||||
}
|
||||
PrefabHelper.syncWithPrefab(this);
|
||||
}
|
||||
|
||||
this._updateDummySgNode();
|
||||
@@ -1088,6 +1089,28 @@ var Node = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// the same as _onBatchCreated but untouch prefab
|
||||
_onBatchRestored () {
|
||||
this._updateDummySgNode();
|
||||
|
||||
if (this._parent) {
|
||||
this._parent._sgNode.addChild(this._sgNode);
|
||||
}
|
||||
|
||||
if (!this._activeInHierarchy) {
|
||||
// deactivate ActionManager and EventManager by default
|
||||
if (ActionManagerExist) {
|
||||
cc.director.getActionManager().pauseTarget(this);
|
||||
}
|
||||
cc.eventManager.pauseTarget(this);
|
||||
}
|
||||
|
||||
var children = this._children;
|
||||
for (var i = 0, len = children.length; i < len; i++) {
|
||||
children[i]._onBatchRestored();
|
||||
}
|
||||
},
|
||||
|
||||
// EVENTS
|
||||
|
||||
/**
|
||||
|
||||
+10
-1
@@ -62,6 +62,10 @@ cc.Scene = cc.Class({
|
||||
this._activeInHierarchy = false;
|
||||
this._inited = !cc.game._isCloning;
|
||||
|
||||
if (CC_EDITOR) {
|
||||
this._prefabSyncedInLiveReload = false;
|
||||
}
|
||||
|
||||
// cache all depend assets for auto release
|
||||
this.dependAssets = null;
|
||||
},
|
||||
@@ -79,7 +83,12 @@ cc.Scene = cc.Class({
|
||||
if (CC_TEST) {
|
||||
cc.assert(!this._activeInHierarchy, 'Should deactivate ActionManager and EventManager by default');
|
||||
}
|
||||
this._onBatchCreated();
|
||||
if (CC_EDITOR && this._prefabSyncedInLiveReload) {
|
||||
this._onBatchRestored();
|
||||
}
|
||||
else {
|
||||
this._onBatchCreated();
|
||||
}
|
||||
this._inited = true;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var PrefabHelper = require('./prefab-helper');
|
||||
var Flags = require('../platform/CCObject').Flags;
|
||||
var Misc = require('./misc');
|
||||
var IdGenerater = require('../platform/id-generater');
|
||||
@@ -1055,6 +1056,12 @@ var BaseNode = cc.Class({
|
||||
|
||||
_onSetParent (value) {},
|
||||
_onPostActivated () {},
|
||||
_onBatchRestored () {
|
||||
var children = this._children;
|
||||
for (var i = 0, len = children.length; i < len; i++) {
|
||||
children[i]._onBatchRestored();
|
||||
}
|
||||
},
|
||||
|
||||
_onHierarchyChanged (oldParent) {
|
||||
var newParent = this._parent;
|
||||
@@ -1107,11 +1114,11 @@ var BaseNode = cc.Class({
|
||||
|
||||
_onBatchCreated () {
|
||||
var prefabInfo = this._prefab;
|
||||
if (prefabInfo && prefabInfo.sync && !prefabInfo._synced) {
|
||||
// checks to ensure no recursion, recursion will caused only on old data.
|
||||
if (prefabInfo.root === this) {
|
||||
PrefabHelper.syncWithPrefab(this);
|
||||
if (prefabInfo && prefabInfo.sync && prefabInfo.root === this) {
|
||||
if (CC_DEV && prefabInfo._synced) {
|
||||
cc.error('Internal error: prefab already synced');
|
||||
}
|
||||
PrefabHelper.syncWithPrefab(this);
|
||||
}
|
||||
|
||||
var children = this._children;
|
||||
@@ -1133,8 +1140,6 @@ var BaseNode = cc.Class({
|
||||
}
|
||||
var syncing = thisPrefabInfo && this === thisPrefabInfo.root && thisPrefabInfo.sync;
|
||||
if (syncing) {
|
||||
// copy non-serialized property
|
||||
cloned._prefab._synced = thisPrefabInfo._synced;
|
||||
//if (thisPrefabInfo._synced) {
|
||||
// return clone;
|
||||
//}
|
||||
@@ -1145,7 +1150,7 @@ var BaseNode = cc.Class({
|
||||
|
||||
// reset and init
|
||||
cloned._parent = null;
|
||||
cloned._onBatchCreated();
|
||||
cloned._onBatchRestored();
|
||||
|
||||
return cloned;
|
||||
},
|
||||
|
||||
@@ -25,11 +25,13 @@
|
||||
|
||||
cc._PrefabInfo = cc.Class({
|
||||
name: 'cc.PrefabInfo',
|
||||
// extends: require('../platform/CCObject'),
|
||||
properties: {
|
||||
// the most top node of this prefab in the scene
|
||||
root: null,
|
||||
|
||||
// 所属的 prefab 资源对象 (cc.Prefab)
|
||||
// In Editor, only asset._uuid is usable because asset will be changed.
|
||||
asset: null,
|
||||
|
||||
// 用来标识别该节点在 prefab 资源中的位置,因此这个 ID 只需要保证在 Assets 里不重复就行
|
||||
@@ -43,7 +45,18 @@ cc._PrefabInfo = cc.Class({
|
||||
default: false,
|
||||
serializable: false
|
||||
},
|
||||
}
|
||||
},
|
||||
// _instantiate (cloned) {
|
||||
// if (!cloned) {
|
||||
// cloned = new cc._PrefabInfo();
|
||||
// }
|
||||
// cloned.root = this.root;
|
||||
// cloned.asset = this.asset;
|
||||
// cloned.fileId = this.fileId;
|
||||
// cloned.sync = this.sync;
|
||||
// cloned._synced = this._synced;
|
||||
// return cloned;
|
||||
// }
|
||||
});
|
||||
|
||||
// prefab helper function
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
var newNode = cc.instantiate(nodeToCreatePrefab);
|
||||
testInstantiatedNode(newNode);
|
||||
ok(newNode._prefab.sync === true, "sync should be instantiated");
|
||||
ok(newNode._prefab._synced === true, "instantiated node should be _synced");
|
||||
// ok(newNode._prefab._synced === true, "instantiated node should be _synced");
|
||||
});
|
||||
|
||||
test('load and sync scene', function () {
|
||||
|
||||
Reference in New Issue
Block a user