mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 02:02:41 +08:00
reset dynamic atlas before scene loading (#2655)
* reset dynamic atlas before scene loading * fixed node undo/redo
This commit is contained in:
@@ -156,6 +156,8 @@ cc.Director.prototype = {
|
||||
this._actionManager = null;
|
||||
}
|
||||
|
||||
cc.dynamicAtlasManager.enabled = true;
|
||||
|
||||
this.sharedInit();
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -2934,6 +2934,8 @@ var Node = cc.Class({
|
||||
onRestore: CC_EDITOR && function () {
|
||||
this._onRestoreBase();
|
||||
|
||||
this._renderFlag |= RenderFlow.FLAG_TRANSFORM | RenderFlow.FLAG_COLOR;
|
||||
|
||||
var actionManager = cc.director.getActionManager();
|
||||
if (this._activeInHierarchy) {
|
||||
actionManager && actionManager.resumeTarget(this);
|
||||
|
||||
@@ -484,6 +484,7 @@ var Sprite = cc.Class({
|
||||
}
|
||||
|
||||
this._updateAssembler();
|
||||
this._renderData.uvDirty = true;
|
||||
|
||||
this.node.on(NodeEvent.SIZE_CHANGED, this._onNodeSizeDirty, this);
|
||||
this.node.on(NodeEvent.ANCHOR_CHANGED, this._onNodeSizeDirty, this);
|
||||
@@ -512,6 +513,7 @@ var Sprite = cc.Class({
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.material = this._material;
|
||||
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -35,12 +35,13 @@ module.exports = {
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -37,12 +37,13 @@ const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -47,12 +47,13 @@ module.exports = {
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -34,12 +34,13 @@ module.exports = {
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -46,12 +46,13 @@ module.exports = {
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -37,12 +37,13 @@ module.exports = {
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (frame) {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
if (!sprite._material) {
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
@@ -97,7 +97,7 @@ class Atlas {
|
||||
frame._rect.x = oriInfo.x;
|
||||
frame._rect.y = oriInfo.y;
|
||||
frame._texture = oriInfo.texture;
|
||||
spriteFrame._calculateUV();
|
||||
frame._calculateUV();
|
||||
frame._original = null;
|
||||
}
|
||||
this._innerSpriteFrames.length = 0;
|
||||
|
||||
@@ -9,17 +9,23 @@ let _textureSize = 2048;
|
||||
let _minFrameSize = 8;
|
||||
let _maxFrameSize = 512;
|
||||
|
||||
let _enabled = true;
|
||||
|
||||
let _debugNode = null;
|
||||
|
||||
function newAtlas () {
|
||||
let atlas = new Atlas(_textureSize, _textureSize);
|
||||
_atlases.push(atlas);
|
||||
_atlasIndex++;
|
||||
let atlas = _atlases[++_atlasIndex]
|
||||
if (!atlas) {
|
||||
atlas = new Atlas(_textureSize, _textureSize);
|
||||
_atlases.push(atlas);
|
||||
}
|
||||
return atlas;
|
||||
}
|
||||
|
||||
function beforeSceneLoad () {
|
||||
dynamicAtlasManager.reset();
|
||||
}
|
||||
|
||||
let _enabled = false;
|
||||
|
||||
/**
|
||||
* !#en Manager the dynamic atlas.
|
||||
@@ -42,7 +48,12 @@ let dynamicAtlasManager = {
|
||||
|
||||
if (value) {
|
||||
this.reset();
|
||||
cc.director.on(cc.Director.EVENT_BEFORE_SCENE_LOADING, beforeSceneLoad);
|
||||
}
|
||||
else {
|
||||
cc.director.off(cc.Director.EVENT_BEFORE_SCENE_LOADING, beforeSceneLoad);
|
||||
}
|
||||
|
||||
_enabled = value;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user