Hi.
We (team behind bobmob.gg) use spine extensively with a 'skinning' system and many character-slots that users in a multiplayer onlinegame can (almost) freely mix and match, allowing for tens of thousands of unique characters all based on a few spine skeletons.
Loading Image
Loading Image
As the number of assets constantly increases (we have a open marketplace system), we lazy-load the sprite images for the slot-attachments on demand from our servers and create textures on the fly. We established the system using PIXI and PIXI-spine (example code for that is at the end of the post).
Now, we have to re-create that system using Unity-Spine to create what we call mini-games.
Loading Image
We got animations and basic spine usage down, but I am too stupid to create attachments from runtime-www-loaded pngs.
E.g. I am missing Spine.core.TextureRegion and the unity-quivalent for PIXI.BaseTexture.fromImage
So, basically, my question is: how the hell can i create textures and subsequently attachments from images I load at runtime from a url?
This is a rough (shortened, contextless) example of what I do in JS/PIXI to achieve dynamic creation of textures and from them attachments, which I later assemble into runtime-created skins:
Character.prototype.setAssets = function(assets, show) { // show meaning: if false delete the item
var skeleton = this.spine.skeleton;
var skin = this.spine.skeleton.skin;
var asset = null;
for (var i = 0; i < assets.length; i += 1) {
asset = assets[i];
var slotName = asset.slot;
var slotIndex = skeleton.findSlotIndex(slotName);
var placeholder = asset.placeholder;
if (show) {
var textureRegion = this.getTextureRegionOfAsset(asset);
var name = asset.name;
var attachment = new pixi_spine.core.RegionAttachment(name);
attachment.name = name;
attachment.path = name;
attachment.region = textureRegion;
attachment.region.name = name;
attachment.x = asset.attachmentData.x;
attachment.y = asset.attachmentData.y;
attachment.rotation = asset.attachmentData.rotation;
attachment.scaleX = asset.attachmentData.scaleX;
attachment.scaleY = asset.attachmentData.scaleY;
attachment.width = asset.attachmentData.w;
attachment.height = asset.attachmentData.h;
skin.addAttachment(slotIndex, placeholder, attachment);
} else {
var placeHolderAttachments = skin.attachments[slotIndex];
delete placeHolderAttachments[placeholder];
}
}
};
Character.prototype.getTextureRegionOfAsset = function(asset) {
var textureRegion = new pixi_spine.core.TextureRegion();
textureRegion.texture = this.getTexture(asset.sourceFile, asset.x, asset.y, asset.w, asset.h);
return textureRegion;
}
Character.prototype.getTexture = function(sourceFile, x, y, w, h) {
var baseTexture = PIXI.BaseTexture;
if (this.baseTextureMap[sourceFile]) {
baseTexture = this.baseTextureMap[sourceFile];
} else {
baseTexture = PIXI.BaseTexture.fromImage(hookd.server.staticSpineAssetUrl + sourceFile, undefined, PIXI.SCALE_MODES.NEAREST);
this.baseTextureMap[sourceFile] = baseTexture;
}
baseTexture.mipmap = true;
var frame = new PIXI.Rectangle(x, y, w, h);
return new PIXI.Texture(baseTexture, frame);
}