mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Fix spine texture asset issue
This commit is contained in:
@@ -103,6 +103,7 @@ sp.Skeleton = cc.Class({
|
||||
if (CC_EDITOR) {
|
||||
this._refreshInspector();
|
||||
}
|
||||
this._updateSkeletonData();
|
||||
},
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.skeleton.skeleton_data'
|
||||
},
|
||||
@@ -383,22 +384,7 @@ sp.Skeleton = cc.Class({
|
||||
this._refreshInspector();
|
||||
}
|
||||
|
||||
if (this.skeletonData/* && this.atlasFile*/) {
|
||||
var data = this.skeletonData.getRuntimeData();
|
||||
if (data) {
|
||||
try {
|
||||
this.setSkeletonData(data);
|
||||
this.setAnimationStateData(new spine.AnimationStateData(this._skeleton.data));
|
||||
if (this.defaultSkin) {
|
||||
this._skeleton.setSkinByName(this.defaultSkin);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
cc.warn(e);
|
||||
}
|
||||
this.animation = this.defaultAnimation;
|
||||
}
|
||||
}
|
||||
this._updateSkeletonData();
|
||||
},
|
||||
|
||||
onDestroy () {
|
||||
@@ -727,32 +713,6 @@ sp.Skeleton = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// update animation list for editor
|
||||
_updateAnimEnum: CC_EDITOR && function () {
|
||||
var animEnum;
|
||||
if (this.skeletonData) {
|
||||
animEnum = this.skeletonData.getAnimsEnum();
|
||||
}
|
||||
// change enum
|
||||
setEnumAttr(this, '_animationIndex', animEnum || DefaultAnimsEnum);
|
||||
},
|
||||
// update skin list for editor
|
||||
_updateSkinEnum: CC_EDITOR && function () {
|
||||
var skinEnum;
|
||||
if (this.skeletonData) {
|
||||
skinEnum = this.skeletonData.getSkinsEnum();
|
||||
}
|
||||
// change enum
|
||||
setEnumAttr(this, '_defaultSkinIndex', skinEnum || DefaultSkinsEnum);
|
||||
},
|
||||
|
||||
_ensureListener () {
|
||||
if (!this._listener) {
|
||||
this._listener = new TrackEntryListeners();
|
||||
this._state.addListener(this._listener);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Set the start event listener.
|
||||
* !#zh 用来设置开始播放动画的事件监听。
|
||||
@@ -900,6 +860,51 @@ sp.Skeleton = cc.Class({
|
||||
return this._state;
|
||||
},
|
||||
|
||||
// update animation list for editor
|
||||
_updateAnimEnum: CC_EDITOR && function () {
|
||||
var animEnum;
|
||||
if (this.skeletonData) {
|
||||
animEnum = this.skeletonData.getAnimsEnum();
|
||||
}
|
||||
// change enum
|
||||
setEnumAttr(this, '_animationIndex', animEnum || DefaultAnimsEnum);
|
||||
},
|
||||
// update skin list for editor
|
||||
_updateSkinEnum: CC_EDITOR && function () {
|
||||
var skinEnum;
|
||||
if (this.skeletonData) {
|
||||
skinEnum = this.skeletonData.getSkinsEnum();
|
||||
}
|
||||
// change enum
|
||||
setEnumAttr(this, '_defaultSkinIndex', skinEnum || DefaultSkinsEnum);
|
||||
},
|
||||
|
||||
_ensureListener () {
|
||||
if (!this._listener) {
|
||||
this._listener = new TrackEntryListeners();
|
||||
this._state.addListener(this._listener);
|
||||
}
|
||||
},
|
||||
|
||||
_updateSkeletonData () {
|
||||
if (this.skeletonData/* && this.atlasFile*/) {
|
||||
let data = this.skeletonData.getRuntimeData();
|
||||
if (data) {
|
||||
try {
|
||||
this.setSkeletonData(data);
|
||||
this.setAnimationStateData(new spine.AnimationStateData(this._skeleton.data));
|
||||
if (this.defaultSkin) {
|
||||
this._skeleton.setSkinByName(this.defaultSkin);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
cc.warn(e);
|
||||
}
|
||||
this.animation = this.defaultAnimation;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_refreshInspector () {
|
||||
// update inspector
|
||||
this._updateAnimEnum();
|
||||
|
||||
@@ -27,48 +27,6 @@
|
||||
* @module sp
|
||||
*/
|
||||
|
||||
// implements a simple texture loader like sp._atlasLoader
|
||||
var TextureLoader = cc.Class({
|
||||
ctor: function () {
|
||||
// {SkeletonData}
|
||||
this.asset = arguments[0];
|
||||
},
|
||||
getTexture: function (line) {
|
||||
//var name = cc.path.mainFileName(line);
|
||||
//var textures = this.asset.textures;
|
||||
//for (var i = 0; i < textures.length; i++) {
|
||||
// var tex = textures[i];
|
||||
// if (tex.name === name) {
|
||||
// return tex;
|
||||
// }
|
||||
//}
|
||||
var urls = this.asset.textures;
|
||||
for (var i = 0; i < urls.length; i++) {
|
||||
var url = urls[i];
|
||||
if (url.endsWith(line)) {
|
||||
var texture = cc.textureUtil.loadImage(url);
|
||||
var tex = new sp.SkeletonTexture({ width: texture.width, height: texture.height });
|
||||
tex.setRealTexture(texture);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
load: function (line) {
|
||||
var texture = this.getTexture(line);
|
||||
if (texture) {
|
||||
return texture;
|
||||
}
|
||||
else {
|
||||
cc.errorID(7506, line);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
unload: function (obj) {
|
||||
//page.rendererObject.release();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* !#en The skeleton data of spine.
|
||||
* !#zh Spine 的 骨骼数据。
|
||||
@@ -117,19 +75,21 @@ var SkeletonData = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// Fallback to raw asset for JSB -------------------
|
||||
atlasUrl: {
|
||||
default: '',
|
||||
url: cc.RawAsset
|
||||
},
|
||||
// -------------------------------------------------
|
||||
|
||||
/**
|
||||
* @property {Texture2D[]} textures
|
||||
*/
|
||||
textures: {
|
||||
default: [],
|
||||
url: [cc.Texture2D]
|
||||
type: [cc.Texture2D]
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {String[]} textureNames
|
||||
* @private
|
||||
*/
|
||||
textureNames: {
|
||||
default: [],
|
||||
type: [cc.String]
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -148,7 +108,8 @@ var SkeletonData = cc.Class({
|
||||
},
|
||||
|
||||
statics: {
|
||||
preventDeferredLoadDependents: true
|
||||
preventDeferredLoadDependents: true,
|
||||
preventPreloadNativeObject: true,
|
||||
},
|
||||
|
||||
// PUBLIC
|
||||
@@ -192,7 +153,7 @@ var SkeletonData = cc.Class({
|
||||
return this._skeletonCache;
|
||||
}
|
||||
|
||||
if ( !(this.textures && this.textures.length > 0) ) {
|
||||
if ( !(this.textures && this.textures.length > 0) && this.textureNames && this.textureNames.length > 0 ) {
|
||||
if ( !quiet ) {
|
||||
cc.errorID(7507, this.name);
|
||||
}
|
||||
@@ -252,6 +213,20 @@ var SkeletonData = cc.Class({
|
||||
|
||||
// PRIVATE
|
||||
|
||||
_getTexture: !CC_JSB && function (line) {
|
||||
var names = this.textureNames;
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
if (names[i] === line) {
|
||||
var texture = this.textures[i];
|
||||
var tex = new sp.SkeletonTexture({ width: texture.width, height: texture.height });
|
||||
tex.setRealTexture(texture);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
cc.errorID(7506, line);
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method _getAtlas
|
||||
* @param {boolean} [quiet=false]
|
||||
@@ -270,8 +245,7 @@ var SkeletonData = cc.Class({
|
||||
return null;
|
||||
}
|
||||
|
||||
var loader = new TextureLoader(this);
|
||||
return this._atlasCache = new sp.spine.TextureAtlas(this.atlasText, loader.load.bind(loader));
|
||||
return this._atlasCache = new sp.spine.TextureAtlas(this.atlasText, this._getTexture.bind(this));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user