Hello!
So recently I have been working on a tool for building skins for characters. It allows the user to choose a character out of a list and select its skin parts, as well as edit the attachments and sub skins those skins are built out of.
My only problem is that I can't seem to find any way to show the visuals for the parts of the skin. Is there a way to show a skin part as sprite? if so how does one do it?
1. sayfa (Toplam 1 sayfa)
EladFlaish
Bu mesaja eklenen dosyaları görüntülemek için gerekli yetkilere sahip değilsiniz.
3 months ago
- EladFlaish
- Mesajlar: 4
Harald
You can get a
https://docs.unity3d.com/ScriptReference/EditorGUI.DrawPreviewTexture.html
Or you could use
https://docs.unity3d.com/ScriptReference/Graphics.DrawTexture.html
Note that you then might still run into the problem of packing rotation (which can be 0, 90, 180 or 270 degrees).
Sprite
from an AtlasRegion
via the provided extension method in AttachmentTools
:using Spine.Unity.AttachmentTools;
void OnGUI () { // or a similar method
Skin skin = ...;
Atlas atlas = ...; // e.g. skeletonAnimation.SkeletonDataAsset.atlasAssets[0].GetAtlas();
foreach (Skin.SkinEntry skinEntry in skin.Attachments) {
string name = skinEntry.Name;
AtlasRegion region = atlas.FindRegion(name);
Sprite sprite = region.ToSprite();
..
}
If this is not an option, you could extract the Attachment's UVs, or void OnGUI () { // or a similar method
Skin skin = ...;
Atlas atlas = ...; // e.g. skeletonAnimation.SkeletonDataAsset.atlasAssets[0].GetAtlas();
foreach (Skin.SkinEntry skinEntry in skin.Attachments) {
string name = skinEntry.Name;
AtlasRegion region = atlas.FindRegion(name);
Sprite sprite = region.ToSprite();
..
}
regionOffsetX
, regionOffsetY
, regionWidth
, regionHeight
:foreach (Skin.SkinEntry skinEntry in skin.Attachments) {
var attachment = skinEntry.Attachment;
RegionAttachment regionAttachment = attachment as RegionAttachment;
MeshAttachment meshAttachment = attachment as MeshAttachment;
float[] uvs;
if (regionAttachment != null)
uvs = regionAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
else if (meshAttachment != null)
uvs = meshAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
...
And then use the UV coords or var attachment = skinEntry.Attachment;
RegionAttachment regionAttachment = attachment as RegionAttachment;
MeshAttachment meshAttachment = attachment as MeshAttachment;
float[] uvs;
if (regionAttachment != null)
uvs = regionAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
else if (meshAttachment != null)
uvs = meshAttachment.UVs; // or get regionOffsetX, regionOffsetY, regionWidth, regionHeight
...
regionOffsetX
, regionOffsetY
, regionWidth
, regionHeight
to copy the region pixels to a temporary texture to use with e.g. DrawPreviewTexture
:https://docs.unity3d.com/ScriptReference/EditorGUI.DrawPreviewTexture.html
Or you could use
DrawTexture
, which allows a sourceRect
parameter to define source uv coords.https://docs.unity3d.com/ScriptReference/Graphics.DrawTexture.html
Note that you then might still run into the problem of packing rotation (which can be 0, 90, 180 or 270 degrees).
3 months ago
-
Harald - Mesajlar: 4002
Mark topic unread
• 1. sayfa (Toplam 1 sayfa)
Dön Unity
- Tüm zamanlar UTC