Merge pull request #1915 from jareguo/v1.6

should load position of node when synced with prefab
This commit is contained in:
Jare Guo
2017-08-18 18:37:31 +08:00
committed by GitHub
5 changed files with 40 additions and 32 deletions
+1 -1
View File
@@ -311,7 +311,7 @@ proto.enumerateCCClass = function (codeArray, obj, klass) {
var attrs = Attr.getClassAttrs(klass);
for (var p = 0; p < props.length; p++) {
var key = props[p];
if (CC_EDITOR && key === '_id') {
if ((CC_EDITOR || CC_TEST) && key === '_id') {
if (obj instanceof cc._BaseNode || obj instanceof cc.Component) {
continue;
}
+1 -1
View File
@@ -171,7 +171,7 @@ function enumerateCCClass (klass, obj, clone, parent) {
}
}
}
if (CC_EDITOR && (obj instanceof cc._BaseNode || obj instanceof cc.Component)) {
if ((CC_EDITOR || CC_TEST) && (obj instanceof cc._BaseNode || obj instanceof cc.Component)) {
clone._id = '';
}
}
+4 -2
View File
@@ -72,7 +72,8 @@ module.exports = {
var _id = node._id;
var _name = node._name;
var _active = node._active;
var _position = node._position;
var x = node._position.x;
var y = node._position.y;
var _rotationX = node._rotationX;
var _rotationY = node._rotationY;
var _localZOrder = node._localZOrder;
@@ -90,7 +91,8 @@ module.exports = {
node._prefab = _prefab;
node._name = _name;
node._active = _active;
node._position = _position;
node._position.x = x;
node._position.y = y;
node._rotationX = _rotationX;
node._rotationY = _rotationY;
node._localZOrder = _localZOrder;
+1
View File
@@ -163,6 +163,7 @@ function testInstantiate (module, match, instantiate) {
var clone = instantiate(node);
ok(clone.parent === null, 'root of cloned node should not have parent');
ok(clone.uuid !== node.uuid, 'should not clone uuid in tests');
ok(clone.children[0].parent === clone, 'cloned child node should have parent');
});
+33 -28
View File
@@ -15,37 +15,42 @@
var UUID = '19941122';
var DEBUG_SERIALIZED_PREFAB = 0 && !isPhantomJS;
var parent = new cc.Node('parent');
parent.addComponent(MyComponent);
parent.scale = cc.v2(123, 432);
parent.x = 1020;
parent.active = false;
var nodeToCreatePrefab = new cc.Node('parent');
nodeToCreatePrefab.addComponent(MyComponent);
nodeToCreatePrefab.scale = cc.v2(123, 432);
nodeToCreatePrefab.x = 1020;
nodeToCreatePrefab.active = false;
var child = new cc.Node('child');
child.addComponent(MyComponent);
child.scale = cc.v2(3, 2);
child.parent = parent;
child.parent = nodeToCreatePrefab;
child.y = 1029;
child.active = false;
var prefabAsset;
var prefabJson;
var parentJson;
var otherSyncedNode;
var reloadedParent;
(function beforeAll () {
// CREATE PREFAB ASSET
_Scene.PrefabUtils.createPrefabFrom(parent);
_Scene.PrefabUtils.createPrefabFrom(nodeToCreatePrefab);
//var asset = new cc.Prefab();
//asset.data = parent;
parent._prefab.asset._uuid = UUID;
nodeToCreatePrefab._prefab.asset._uuid = UUID;
//_Scene.PrefabUtils.setPrefabAsset(parent, Editor.serialize.asAsset());
_Scene.PrefabUtils.setPrefabSync(parent, true);
_Scene.PrefabUtils.setPrefabSync(nodeToCreatePrefab, true);
otherSyncedNode = cc.instantiate(nodeToCreatePrefab);
otherSyncedNode.x = 1234;
otherSyncedNode.name = 'otherSyncedNode';
// apply sync property
prefabAsset = _Scene.PrefabUtils.createAppliedPrefab(parent);
prefabAsset = _Scene.PrefabUtils.createAppliedPrefab(nodeToCreatePrefab);
// 重新生成已经加载好的 prefab,去除类型,去除 runtime node
prefabJson = Editor.serialize(prefabAsset, { stringify: false });
@@ -53,8 +58,7 @@
prefabAsset._uuid = UUID;
// SAVE SCENE ASSET
parentJson = Editor.serialize(parent, { stringify: false });
parentJson = Editor.serialize(otherSyncedNode, { stringify: false });
if (DEBUG_SERIALIZED_PREFAB) {
console.log(JSON.stringify(parentJson, null, 4));
}
@@ -64,14 +68,14 @@
})();
test('prefab info', function () {
strictEqual(parent._prefab.sync, true, "sync property should be saved to root prefab info");
strictEqual(nodeToCreatePrefab._prefab.sync, true, "sync property should be saved to root prefab info");
});
test('prefab asset should not discard content if sync enabled', function () {
var nodeToSave = prefabAsset.data;
ok(nodeToSave.children.length > 0, 'children should be saved');
var childToSave = nodeToSave.children[0];
strictEqual(nodeToSave.scaleX, parent.scaleX, 'root scale should be saved');
strictEqual(nodeToSave.scaleX, nodeToCreatePrefab.scaleX, 'root scale should be saved');
strictEqual(childToSave.scaleY, child.scaleY, 'child scale should be saved');
ok(nodeToSave.getComponent(cc.Component), 'root component should be saved');
ok(childToSave.getComponent(cc.Component), 'child component should be saved');
@@ -80,7 +84,7 @@
strictEqual(childToSave.active, false, 'child active should be saved');
});
test('sync config saved in prefab asset', function () {
test('sync config in prefab asset', function () {
var nodeToSave = prefabAsset.data;
strictEqual(nodeToSave._prefab.sync, false, 'sync config should not saved');
});
@@ -88,23 +92,24 @@
test('saved scene node if sync enabled', function () {
strictEqual(reloadedParent.scaleX, 1, 'all scale should not saved');
strictEqual(reloadedParent.getComponent(cc.Component), null, 'all component should not saved');
strictEqual(reloadedParent.x, parent.x, 'root position should be saved');
strictEqual(reloadedParent.name, parent.name, 'root name should be saved');
strictEqual(reloadedParent.active, false, 'root active should be saved');
ok(reloadedParent.children.length === 0, 'children should not saved');
strictEqual(reloadedParent.x, otherSyncedNode.x, 'root position should be saved');
strictEqual(reloadedParent.name, otherSyncedNode.name, 'root name should be saved');
strictEqual(reloadedParent.active, otherSyncedNode.active, 'root active should be saved');
var prefabInfo = reloadedParent._prefab;
ok(prefabInfo, 'prefab info should be saved');
ok(prefabInfo.asset, 'asset should be saved');
strictEqual(prefabInfo.sync, true, 'sync should be saved');
strictEqual(prefabInfo.fileId, parent.uuid, 'fileId should be saved');
strictEqual(prefabInfo.fileId, nodeToCreatePrefab.uuid, 'fileId should be saved');
});
test('prefab info in exported scene if syncable', function () {
var reloadedParent = cc.deserialize(Editor.serialize(parent, { stringify: false, exporting: true }));
ok(reloadedParent._prefab, 'prefab info should be saved');
strictEqual(reloadedParent._prefab.sync, true, 'sync should be saved');
strictEqual(reloadedParent._prefab.fileId, parent.uuid, 'fileId should be saved');
var exportedParent = cc.deserialize(Editor.serialize(nodeToCreatePrefab, { stringify: false, exporting: true }));
ok(exportedParent._prefab, 'prefab info should be saved');
strictEqual(exportedParent._prefab.sync, true, 'sync should be saved');
strictEqual(exportedParent._prefab.fileId, nodeToCreatePrefab.uuid, 'fileId should be saved');
});
function testInstantiatedNode (newNode) {
@@ -119,7 +124,7 @@
testInstantiatedNode(newNode);
});
test('instantiating synced scene node', function () {
var newNode = cc.instantiate(parent);
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");
@@ -140,15 +145,15 @@
ok(prefabInfo, "new node should preserve the prefab info");
ok(prefabInfo.sync === true, "sync should be instantiated");
ok(prefabInfo._synced === true, "instantiated node should be _synced");
strictEqual(prefabInfo.fileId, parent.uuid, 'fileId should be kept');
strictEqual(prefabInfo.fileId, nodeToCreatePrefab.uuid, 'fileId should be kept');
// test parent
strictEqual(reloadedParent.scaleX, parent.scaleX, 'all scale should be synced');
strictEqual(reloadedParent.scaleX, nodeToCreatePrefab.scaleX, 'all scale should be synced');
var comp = reloadedParent.getComponent(cc.Component);
ok(comp, 'all component should be synced');
strictEqual(comp.node, reloadedParent, 'component reference should redirect to scene node');
strictEqual(reloadedParent.x, parent.x, 'root position should be kept');
strictEqual(reloadedParent.name, parent.name, 'root name should be kept');
strictEqual(reloadedParent.x, otherSyncedNode.x, 'root position should be kept');
strictEqual(reloadedParent.name, otherSyncedNode.name, 'root name should be kept');
strictEqual(reloadedParent.active, false, 'root active should be kept');
strictEqual(reloadedParent.children.length, 1, 'children should be synced');