mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #488 from pandamicro/v1.0
Detect existing persist node by uuid
This commit is contained in:
@@ -513,7 +513,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
// Re-attach or replace persist nodes
|
||||
for (id in persistNodes) {
|
||||
node = persistNodes[id];
|
||||
var existNode = scene.getChildByName(node.name);
|
||||
var existNode = scene.getChildByUuid(id);
|
||||
// Scene contains the persist node, should not reattach, should update the persist node
|
||||
if (existNode) {
|
||||
persistNodes[id] = existNode;
|
||||
|
||||
@@ -976,6 +976,26 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a child from the container given its uuid
|
||||
* @method getChildByUuid
|
||||
* @param {String} uuid - The uuid to find the child node.
|
||||
* @return {Node} a Node whose uuid equals to the input parameter
|
||||
*/
|
||||
getChildByUuid: function(uuid){
|
||||
if(!uuid){
|
||||
cc.log("Invalid uuid");
|
||||
return null;
|
||||
}
|
||||
|
||||
var locChildren = this._children;
|
||||
for(var i = 0, len = locChildren.length; i < len; i++){
|
||||
if(locChildren[i]._id === uuid)
|
||||
return locChildren[i];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a child from the container given its name
|
||||
* @method getChildByName
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ cc.js.mixin(cc.director, {
|
||||
// Re-attach persist nodes
|
||||
for (id in persistNodes) {
|
||||
node = persistNodes[id];
|
||||
var existNode = scene.getChildByName(node.name);
|
||||
var existNode = scene.getChildByUuid(id);
|
||||
// Scene contains the persist node, should not reattach, should update the persist node
|
||||
if (existNode) {
|
||||
persistNodes[id] = existNode;
|
||||
|
||||
Reference in New Issue
Block a user