mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge pull request #504 from EsotericSoftware/unity-uwp-fix
Unity UWP Fix
This commit is contained in:
commit
392a95590e
@ -45,7 +45,8 @@ namespace Spine {
|
|||||||
List<AtlasRegion> regions = new List<AtlasRegion>();
|
List<AtlasRegion> regions = new List<AtlasRegion>();
|
||||||
TextureLoader textureLoader;
|
TextureLoader textureLoader;
|
||||||
|
|
||||||
#if WINDOWS_STOREAPP
|
#if !(UNITY_5 || UNITY_4 || UNITY_WSA || UNITY_WP8 || UNITY_WP8_1) // !UNITY
|
||||||
|
#if WINDOWS_STOREAPP
|
||||||
private async Task ReadFile(string path, TextureLoader textureLoader) {
|
private async Task ReadFile(string path, TextureLoader textureLoader) {
|
||||||
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
||||||
var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false);
|
var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false);
|
||||||
@ -61,24 +62,28 @@ namespace Spine {
|
|||||||
public Atlas(String path, TextureLoader textureLoader) {
|
public Atlas(String path, TextureLoader textureLoader) {
|
||||||
this.ReadFile(path, textureLoader).Wait();
|
this.ReadFile(path, textureLoader).Wait();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
public Atlas (String path, TextureLoader textureLoader) {
|
public Atlas (String path, TextureLoader textureLoader) {
|
||||||
|
|
||||||
#if WINDOWS_PHONE
|
#if WINDOWS_PHONE
|
||||||
Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
|
Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
|
||||||
using (StreamReader reader = new StreamReader(stream))
|
using (StreamReader reader = new StreamReader(stream)) {
|
||||||
{
|
#else
|
||||||
#else
|
|
||||||
using (StreamReader reader = new StreamReader(path)) {
|
using (StreamReader reader = new StreamReader(path)) {
|
||||||
#endif
|
#endif // WINDOWS_PHONE
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Load(reader, Path.GetDirectoryName(path), textureLoader);
|
Load(reader, Path.GetDirectoryName(path), textureLoader);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new Exception("Error reading atlas file: " + path, ex);
|
throw new Exception("Error reading atlas file: " + path, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // WINDOWS_STOREAPP
|
||||||
|
|
||||||
|
#endif // !(UNITY)
|
||||||
|
|
||||||
public Atlas (TextReader reader, String dir, TextureLoader textureLoader) {
|
public Atlas (TextReader reader, String dir, TextureLoader textureLoader) {
|
||||||
Load(reader, dir, textureLoader);
|
Load(reader, dir, textureLoader);
|
||||||
@ -105,18 +110,18 @@ namespace Spine {
|
|||||||
page = new AtlasPage();
|
page = new AtlasPage();
|
||||||
page.name = line;
|
page.name = line;
|
||||||
|
|
||||||
if (readTuple(reader, tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker.
|
if (ReadTuple(reader, tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker.
|
||||||
page.width = int.Parse(tuple[0]);
|
page.width = int.Parse(tuple[0]);
|
||||||
page.height = int.Parse(tuple[1]);
|
page.height = int.Parse(tuple[1]);
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
}
|
}
|
||||||
page.format = (Format)Enum.Parse(typeof(Format), tuple[0], false);
|
page.format = (Format)Enum.Parse(typeof(Format), tuple[0], false);
|
||||||
|
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], false);
|
page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], false);
|
||||||
page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], false);
|
page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], false);
|
||||||
|
|
||||||
String direction = readValue(reader);
|
String direction = ReadValue(reader);
|
||||||
page.uWrap = TextureWrap.ClampToEdge;
|
page.uWrap = TextureWrap.ClampToEdge;
|
||||||
page.vWrap = TextureWrap.ClampToEdge;
|
page.vWrap = TextureWrap.ClampToEdge;
|
||||||
if (direction == "x")
|
if (direction == "x")
|
||||||
@ -135,13 +140,13 @@ namespace Spine {
|
|||||||
region.name = line;
|
region.name = line;
|
||||||
region.page = page;
|
region.page = page;
|
||||||
|
|
||||||
region.rotate = Boolean.Parse(readValue(reader));
|
region.rotate = Boolean.Parse(ReadValue(reader));
|
||||||
|
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
int x = int.Parse(tuple[0]);
|
int x = int.Parse(tuple[0]);
|
||||||
int y = int.Parse(tuple[1]);
|
int y = int.Parse(tuple[1]);
|
||||||
|
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
int width = int.Parse(tuple[0]);
|
int width = int.Parse(tuple[0]);
|
||||||
int height = int.Parse(tuple[1]);
|
int height = int.Parse(tuple[1]);
|
||||||
|
|
||||||
@ -159,33 +164,33 @@ namespace Spine {
|
|||||||
region.width = Math.Abs(width);
|
region.width = Math.Abs(width);
|
||||||
region.height = Math.Abs(height);
|
region.height = Math.Abs(height);
|
||||||
|
|
||||||
if (readTuple(reader, tuple) == 4) { // split is optional
|
if (ReadTuple(reader, tuple) == 4) { // split is optional
|
||||||
region.splits = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
|
region.splits = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
|
||||||
int.Parse(tuple[2]), int.Parse(tuple[3])};
|
int.Parse(tuple[2]), int.Parse(tuple[3])};
|
||||||
|
|
||||||
if (readTuple(reader, tuple) == 4) { // pad is optional, but only present with splits
|
if (ReadTuple(reader, tuple) == 4) { // pad is optional, but only present with splits
|
||||||
region.pads = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
|
region.pads = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
|
||||||
int.Parse(tuple[2]), int.Parse(tuple[3])};
|
int.Parse(tuple[2]), int.Parse(tuple[3])};
|
||||||
|
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
region.originalWidth = int.Parse(tuple[0]);
|
region.originalWidth = int.Parse(tuple[0]);
|
||||||
region.originalHeight = int.Parse(tuple[1]);
|
region.originalHeight = int.Parse(tuple[1]);
|
||||||
|
|
||||||
readTuple(reader, tuple);
|
ReadTuple(reader, tuple);
|
||||||
region.offsetX = int.Parse(tuple[0]);
|
region.offsetX = int.Parse(tuple[0]);
|
||||||
region.offsetY = int.Parse(tuple[1]);
|
region.offsetY = int.Parse(tuple[1]);
|
||||||
|
|
||||||
region.index = int.Parse(readValue(reader));
|
region.index = int.Parse(ReadValue(reader));
|
||||||
|
|
||||||
regions.Add(region);
|
regions.Add(region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String readValue (TextReader reader) {
|
static String ReadValue (TextReader reader) {
|
||||||
String line = reader.ReadLine();
|
String line = reader.ReadLine();
|
||||||
int colon = line.IndexOf(':');
|
int colon = line.IndexOf(':');
|
||||||
if (colon == -1) throw new Exception("Invalid line: " + line);
|
if (colon == -1) throw new Exception("Invalid line: " + line);
|
||||||
@ -193,7 +198,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns the number of tuple values read (1, 2 or 4).</summary>
|
/// <summary>Returns the number of tuple values read (1, 2 or 4).</summary>
|
||||||
static int readTuple (TextReader reader, String[] tuple) {
|
static int ReadTuple (TextReader reader, String[] tuple) {
|
||||||
String line = reader.ReadLine();
|
String line = reader.ReadLine();
|
||||||
int colon = line.IndexOf(':');
|
int colon = line.IndexOf(':');
|
||||||
if (colon == -1) throw new Exception("Invalid line: " + line);
|
if (colon == -1) throw new Exception("Invalid line: " + line);
|
||||||
|
|||||||
@ -67,7 +67,9 @@ namespace Spine {
|
|||||||
Scale = 1;
|
Scale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WINDOWS_STOREAPP
|
#if !(UNITY_5 || UNITY_4 || UNITY_WSA || UNITY_WP8 || UNITY_WP8_1)
|
||||||
|
#if WINDOWS_STOREAPP
|
||||||
|
|
||||||
private async Task<SkeletonData> ReadFile(string path) {
|
private async Task<SkeletonData> ReadFile(string path) {
|
||||||
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
||||||
using (var input = new BufferedStream(await folder.GetFileAsync(path).AsTask().ConfigureAwait(false))) {
|
using (var input = new BufferedStream(await folder.GetFileAsync(path).AsTask().ConfigureAwait(false))) {
|
||||||
@ -80,26 +82,21 @@ namespace Spine {
|
|||||||
public SkeletonData ReadSkeletonData (String path) {
|
public SkeletonData ReadSkeletonData (String path) {
|
||||||
return this.ReadFile(path).Result;
|
return this.ReadFile(path).Result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public SkeletonData ReadSkeletonData (String path) {
|
public SkeletonData ReadSkeletonData (String path) {
|
||||||
#if WINDOWS_PHONE
|
#if WINDOWS_PHONE
|
||||||
using (var input = new BufferedStream(Microsoft.Xna.Framework.TitleContainer.OpenStream(path)))
|
using (var input = new BufferedStream(Microsoft.Xna.Framework.TitleContainer.OpenStream(path))) {
|
||||||
{
|
#else
|
||||||
#else
|
using (var input = new BufferedStream(new FileStream(path, FileMode.Open))) {
|
||||||
#if UNITY_WP8 || UNITY_WP8_1
|
#endif // WINDOWS_PHONE
|
||||||
using (var input = new FileStream(path, FileMode.Open))
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
using (var input = new BufferedStream(new FileStream(path, FileMode.Open)))
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
SkeletonData skeletonData = ReadSkeletonData(input);
|
SkeletonData skeletonData = ReadSkeletonData(input);
|
||||||
skeletonData.name = Path.GetFileNameWithoutExtension(path);
|
skeletonData.name = Path.GetFileNameWithoutExtension(path);
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // WINDOWS_STOREAPP
|
||||||
|
#endif // !(UNITY)
|
||||||
|
|
||||||
public SkeletonData ReadSkeletonData (Stream input) {
|
public SkeletonData ReadSkeletonData (Stream input) {
|
||||||
if (input == null) throw new ArgumentNullException("input cannot be null.");
|
if (input == null) throw new ArgumentNullException("input cannot be null.");
|
||||||
|
|||||||
@ -53,7 +53,9 @@ namespace Spine {
|
|||||||
Scale = 1;
|
Scale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WINDOWS_STOREAPP
|
#if !(UNITY_5 || UNITY_4 || UNITY_WSA || UNITY_WP8 || UNITY_WP8_1)
|
||||||
|
#if WINDOWS_STOREAPP
|
||||||
|
|
||||||
private async Task<SkeletonData> ReadFile(string path) {
|
private async Task<SkeletonData> ReadFile(string path) {
|
||||||
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
||||||
var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false);
|
var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false);
|
||||||
@ -67,20 +69,22 @@ namespace Spine {
|
|||||||
public SkeletonData ReadSkeletonData (String path) {
|
public SkeletonData ReadSkeletonData (String path) {
|
||||||
return this.ReadFile(path).Result;
|
return this.ReadFile(path).Result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public SkeletonData ReadSkeletonData (String path) {
|
public SkeletonData ReadSkeletonData (String path) {
|
||||||
#if WINDOWS_PHONE
|
#if WINDOWS_PHONE
|
||||||
Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
|
Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
|
||||||
using (StreamReader reader = new StreamReader(stream)) {
|
using (StreamReader reader = new StreamReader(stream)) {
|
||||||
#else
|
#else
|
||||||
using (StreamReader reader = new StreamReader(path)) {
|
using (StreamReader reader = new StreamReader(path)) {
|
||||||
#endif
|
#endif // WINDOWS_PHONE
|
||||||
SkeletonData skeletonData = ReadSkeletonData(reader);
|
SkeletonData skeletonData = ReadSkeletonData(reader);
|
||||||
skeletonData.name = Path.GetFileNameWithoutExtension(path);
|
skeletonData.name = Path.GetFileNameWithoutExtension(path);
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // WINDOWS_STOREAPP
|
||||||
|
#endif // !UNITY
|
||||||
|
|
||||||
public SkeletonData ReadSkeletonData (TextReader reader) {
|
public SkeletonData ReadSkeletonData (TextReader reader) {
|
||||||
if (reader == null) throw new ArgumentNullException("reader cannot be null.");
|
if (reader == null) throw new ArgumentNullException("reader cannot be null.");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user