[unity] Fixed TK2D SpriteCollectionAttachmentLoader compile errors on 4.1. See #2113.

This commit is contained in:
Harald Csaszar 2022-07-14 19:24:37 +02:00
parent 696c723013
commit 1549cdea5c

View File

@ -28,9 +28,9 @@
*****************************************************************************/ *****************************************************************************/
#if SPINE_TK2D #if SPINE_TK2D
using Spine;
using System; using System;
using UnityEngine; using UnityEngine;
using Spine;
// MITCH: handle TPackerCW flip mode (probably not swap uv horizontaly) // MITCH: handle TPackerCW flip mode (probably not swap uv horizontaly)
namespace Spine.Unity.TK2D { namespace Spine.Unity.TK2D {
@ -49,9 +49,9 @@ namespace Spine.Unity.TK2D {
this.sprites = sprites; this.sprites = sprites;
} }
private void ProcessSpriteDefinition (String name) { private AtlasRegion ProcessSpriteDefinition (String name) {
// Strip folder names. // Strip folder names.
int index = name.LastIndexOfAny(new char[] {'/', '\\'}); int index = name.LastIndexOfAny(new char[] { '/', '\\' });
if (index != -1) if (index != -1)
name = name.Substring(index + 1); name = name.Substring(index + 1);
@ -98,42 +98,62 @@ namespace Spine.Unity.TK2D {
regionOffsetY = (int)((y1 - y0) / def.texelSize.y); regionOffsetY = (int)((y1 - y0) / def.texelSize.y);
material = def.materialInst; material = def.materialInst;
}
public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) { AtlasRegion region = new AtlasRegion();
ProcessSpriteDefinition(path); region.name = name;
AtlasPage page = new AtlasPage();
RegionAttachment region = new RegionAttachment(name); page.rendererObject = material;
region.Path = path; region.page = page;
region.RendererObject = material; region.u = u;
region.SetUVs(u, v, u2, v2, regionRotated); region.u = v;
region.RegionOriginalWidth = regionOriginalWidth; region.u2 = u2;
region.RegionOriginalHeight = regionOriginalHeight; region.v2 = v2;
region.RegionWidth = regionWidth; region.rotate = regionRotated;
region.RegionHeight = regionHeight; region.degrees = regionRotated ? 90 : 0;
region.RegionOffsetX = regionOffsetX; region.originalWidth = (int)regionOriginalWidth;
region.RegionOffsetY = regionOffsetY; region.originalHeight = (int)regionOriginalHeight;
region.width = (int)regionWidth;
region.height = (int)regionHeight;
region.offsetX = regionOffsetX;
region.offsetY = regionOffsetY;
return region; return region;
} }
public MeshAttachment NewMeshAttachment (Skin skin, String name, String path) { private void LoadSequence (string name, string basePath, Sequence sequence) {
ProcessSpriteDefinition(path); TextureRegion[] regions = sequence.Regions;
for (int i = 0, n = regions.Length; i < n; i++) {
string path = sequence.GetPath(basePath, i);
regions[i] = ProcessSpriteDefinition(path);
if (regions[i] == null) throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
}
}
MeshAttachment mesh = new MeshAttachment(name); public RegionAttachment NewRegionAttachment (Skin skin, String name, String path, Sequence sequence) {
mesh.Path = path; RegionAttachment attachment = new RegionAttachment(name);
mesh.RendererObject = material; if (sequence != null)
mesh.RegionU = u; LoadSequence(name, path, sequence);
mesh.RegionV = v; else {
mesh.RegionU2 = u2; AtlasRegion region = ProcessSpriteDefinition(path);
mesh.RegionV2 = v2; if (region == null)
mesh.RegionRotate = regionRotated; throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
mesh.RegionOriginalWidth = regionOriginalWidth; attachment.Region = region;
mesh.RegionOriginalHeight = regionOriginalHeight; attachment.Path = path;
mesh.RegionWidth = regionWidth; }
mesh.RegionHeight = regionHeight; return attachment;
mesh.RegionOffsetX = regionOffsetX; }
mesh.RegionOffsetY = regionOffsetY;
return mesh; public MeshAttachment NewMeshAttachment (Skin skin, String name, String path, Sequence sequence) {
MeshAttachment attachment = new MeshAttachment(name);
if (sequence != null)
LoadSequence(name, path, sequence);
else {
AtlasRegion region = ProcessSpriteDefinition(path);
if (region == null)
throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
attachment.Region = region;
attachment.Path = path;
}
return attachment;
} }
public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, String name) { public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, String name) {