diff --git a/spine-csharp/src/AnimationState.cs b/spine-csharp/src/AnimationState.cs index d616cb886..4d34a2123 100644 --- a/spine-csharp/src/AnimationState.cs +++ b/spine-csharp/src/AnimationState.cs @@ -43,14 +43,14 @@ namespace Spine { public AnimationStateData Data { get { return data; } } public float TimeScale { get { return timeScale; } set { timeScale = value; } } - public delegate void StartEndDelegate(AnimationState state, int trackIndex); + public delegate void StartEndDelegate (AnimationState state, int trackIndex); public event StartEndDelegate Start; public event StartEndDelegate End; - public delegate void EventDelegate(AnimationState state, int trackIndex, Event e); + public delegate void EventDelegate (AnimationState state, int trackIndex, Event e); public event EventDelegate Event; - - public delegate void CompleteDelegate(AnimationState state, int trackIndex, int loopCount); + + public delegate void CompleteDelegate (AnimationState state, int trackIndex, int loopCount); public event CompleteDelegate Complete; public AnimationState (AnimationStateData data) { diff --git a/spine-csharp/src/Atlas.cs b/spine-csharp/src/Atlas.cs index 12b15f4de..d6f0227d5 100644 --- a/spine-csharp/src/Atlas.cs +++ b/spine-csharp/src/Atlas.cs @@ -69,7 +69,7 @@ namespace Spine { using (StreamReader reader = new StreamReader(stream)) { #else - using (StreamReader reader = new StreamReader(path)) { + using (StreamReader reader = new StreamReader(path)) { #endif try { Load(reader, Path.GetDirectoryName(path), textureLoader); diff --git a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs index 0976e97c4..9fd84ab1f 100644 --- a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs +++ b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs @@ -97,7 +97,7 @@ namespace Spine { return new BoundingBoxAttachment(name); } - public AtlasRegion FindRegion(string name) { + public AtlasRegion FindRegion (string name) { AtlasRegion region; for (int i = 0; i < atlasArray.Length; i++) { diff --git a/spine-csharp/src/Bone.cs b/spine-csharp/src/Bone.cs index 748e35dc6..6d92871a8 100644 --- a/spine-csharp/src/Bone.cs +++ b/spine-csharp/src/Bone.cs @@ -33,7 +33,7 @@ using System; using System.Collections.Generic; namespace Spine { - public class Bone{ + public class Bone { static public bool yDown; internal BoneData data; diff --git a/spine-csharp/src/ExposedList.cs b/spine-csharp/src/ExposedList.cs index efac67ac2..45287c0d7 100644 --- a/spine-csharp/src/ExposedList.cs +++ b/spine-csharp/src/ExposedList.cs @@ -41,16 +41,15 @@ namespace Spine { public class ExposedList : IEnumerable { public T[] Items; public int Count; - private const int DefaultCapacity = 4; private static readonly T[] EmptyArray = new T[0]; private int version; - public ExposedList() { + public ExposedList () { Items = EmptyArray; } - public ExposedList(IEnumerable collection) { + public ExposedList (IEnumerable collection) { CheckCollection(collection); // initialize to needed size (if determinable) @@ -64,44 +63,44 @@ namespace Spine { } } - public ExposedList(int capacity) { + public ExposedList (int capacity) { if (capacity < 0) throw new ArgumentOutOfRangeException("capacity"); Items = new T[capacity]; } - internal ExposedList(T[] data, int size) { + internal ExposedList (T[] data, int size) { Items = data; Count = size; } - public void Add(T item) { + public void Add (T item) { // If we check to see if we need to grow before trying to grow // we can speed things up by 25% if (Count == Items.Length) GrowIfNeeded(1); - Items[Count ++] = item; + Items[Count++] = item; version++; } - public void GrowIfNeeded(int newCount) { + public void GrowIfNeeded (int newCount) { int minimumSize = Count + newCount; if (minimumSize > Items.Length) Capacity = Math.Max(Math.Max(Capacity * 2, DefaultCapacity), minimumSize); } - private void CheckRange(int idx, int count) { + private void CheckRange (int idx, int count) { if (idx < 0) throw new ArgumentOutOfRangeException("index"); if (count < 0) throw new ArgumentOutOfRangeException("count"); - if ((uint) idx + (uint) count > (uint) Count) + if ((uint)idx + (uint)count > (uint)Count) throw new ArgumentException("index and count exceed length of list"); } - private void AddCollection(ICollection collection) { + private void AddCollection (ICollection collection) { int collectionCount = collection.Count; if (collectionCount == 0) return; @@ -111,13 +110,13 @@ namespace Spine { Count += collectionCount; } - private void AddEnumerable(IEnumerable enumerable) { + private void AddEnumerable (IEnumerable enumerable) { foreach (T t in enumerable) { Add(t); } } - public void AddRange(IEnumerable collection) { + public void AddRange (IEnumerable collection) { CheckCollection(collection); ICollection c = collection as ICollection; @@ -128,20 +127,20 @@ namespace Spine { version++; } - public int BinarySearch(T item) { + public int BinarySearch (T item) { return Array.BinarySearch(Items, 0, Count, item); } - public int BinarySearch(T item, IComparer comparer) { + public int BinarySearch (T item, IComparer comparer) { return Array.BinarySearch(Items, 0, Count, item, comparer); } - public int BinarySearch(int index, int count, T item, IComparer comparer) { + public int BinarySearch (int index, int count, T item, IComparer comparer) { CheckRange(index, count); return Array.BinarySearch(Items, index, count, item, comparer); } - public void Clear(bool clearArray = true) { + public void Clear (bool clearArray = true) { if (clearArray) Array.Clear(Items, 0, Items.Length); @@ -149,11 +148,11 @@ namespace Spine { version++; } - public bool Contains(T item) { + public bool Contains (T item) { return Array.IndexOf(Items, item, 0, Count) != -1; } - public ExposedList ConvertAll(Converter converter) { + public ExposedList ConvertAll (Converter converter) { if (converter == null) throw new ArgumentNullException("converter"); ExposedList u = new ExposedList(Count); @@ -164,41 +163,41 @@ namespace Spine { return u; } - public void CopyTo(T[] array) { + public void CopyTo (T[] array) { Array.Copy(Items, 0, array, 0, Count); } - public void CopyTo(T[] array, int arrayIndex) { + public void CopyTo (T[] array, int arrayIndex) { Array.Copy(Items, 0, array, arrayIndex, Count); } - public void CopyTo(int index, T[] array, int arrayIndex, int count) { + public void CopyTo (int index, T[] array, int arrayIndex, int count) { CheckRange(index, count); Array.Copy(Items, index, array, arrayIndex, count); } - public bool Exists(Predicate match) { + public bool Exists (Predicate match) { CheckMatch(match); return GetIndex(0, Count, match) != -1; } - public T Find(Predicate match) { + public T Find (Predicate match) { CheckMatch(match); int i = GetIndex(0, Count, match); - return (i != -1) ? Items[i] : default (T); + return (i != -1) ? Items[i] : default(T); } - private static void CheckMatch(Predicate match) { + private static void CheckMatch (Predicate match) { if (match == null) throw new ArgumentNullException("match"); } - public ExposedList FindAll(Predicate match) { + public ExposedList FindAll (Predicate match) { CheckMatch(match); return FindAllList(match); } - private ExposedList FindAllList(Predicate match) { + private ExposedList FindAllList (Predicate match) { ExposedList results = new ExposedList(); for (int i = 0; i < Count; i++) if (match(Items[i])) @@ -207,105 +206,105 @@ namespace Spine { return results; } - public int FindIndex(Predicate match) { + public int FindIndex (Predicate match) { CheckMatch(match); return GetIndex(0, Count, match); } - public int FindIndex(int startIndex, Predicate match) { + public int FindIndex (int startIndex, Predicate match) { CheckMatch(match); CheckIndex(startIndex); return GetIndex(startIndex, Count - startIndex, match); } - public int FindIndex(int startIndex, int count, Predicate match) { + public int FindIndex (int startIndex, int count, Predicate match) { CheckMatch(match); CheckRange(startIndex, count); return GetIndex(startIndex, count, match); } - private int GetIndex(int startIndex, int count, Predicate match) { + private int GetIndex (int startIndex, int count, Predicate match) { int end = startIndex + count; - for (int i = startIndex; i < end; i ++) + for (int i = startIndex; i < end; i++) if (match(Items[i])) return i; return -1; } - public T FindLast(Predicate match) { + public T FindLast (Predicate match) { CheckMatch(match); int i = GetLastIndex(0, Count, match); - return i == -1 ? default (T) : Items[i]; + return i == -1 ? default(T) : Items[i]; } - public int FindLastIndex(Predicate match) { + public int FindLastIndex (Predicate match) { CheckMatch(match); return GetLastIndex(0, Count, match); } - public int FindLastIndex(int startIndex, Predicate match) { + public int FindLastIndex (int startIndex, Predicate match) { CheckMatch(match); CheckIndex(startIndex); return GetLastIndex(0, startIndex + 1, match); } - public int FindLastIndex(int startIndex, int count, Predicate match) { + public int FindLastIndex (int startIndex, int count, Predicate match) { CheckMatch(match); int start = startIndex - count + 1; CheckRange(start, count); return GetLastIndex(start, count, match); } - private int GetLastIndex(int startIndex, int count, Predicate match) { + private int GetLastIndex (int startIndex, int count, Predicate match) { // unlike FindLastIndex, takes regular params for search range - for (int i = startIndex + count; i != startIndex;) + for (int i = startIndex + count; i != startIndex; ) if (match(Items[--i])) return i; return -1; } - public void ForEach(Action action) { + public void ForEach (Action action) { if (action == null) throw new ArgumentNullException("action"); for (int i = 0; i < Count; i++) action(Items[i]); } - public Enumerator GetEnumerator() { + public Enumerator GetEnumerator () { return new Enumerator(this); } - public ExposedList GetRange(int index, int count) { + public ExposedList GetRange (int index, int count) { CheckRange(index, count); T[] tmpArray = new T[count]; Array.Copy(Items, index, tmpArray, 0, count); return new ExposedList(tmpArray, count); } - public int IndexOf(T item) { + public int IndexOf (T item) { return Array.IndexOf(Items, item, 0, Count); } - public int IndexOf(T item, int index) { + public int IndexOf (T item, int index) { CheckIndex(index); return Array.IndexOf(Items, item, index, Count - index); } - public int IndexOf(T item, int index, int count) { + public int IndexOf (T item, int index, int count) { if (index < 0) throw new ArgumentOutOfRangeException("index"); if (count < 0) throw new ArgumentOutOfRangeException("count"); - if ((uint) index + (uint) count > (uint) Count) + if ((uint)index + (uint)count > (uint)Count) throw new ArgumentOutOfRangeException("index and count exceed length of list"); return Array.IndexOf(Items, item, index, count); } - private void Shift(int start, int delta) { + private void Shift (int start, int delta) { if (delta < 0) start -= delta; @@ -318,12 +317,12 @@ namespace Spine { Array.Clear(Items, Count, -delta); } - private void CheckIndex(int index) { - if (index < 0 || (uint) index > (uint) Count) + private void CheckIndex (int index) { + if (index < 0 || (uint)index > (uint)Count) throw new ArgumentOutOfRangeException("index"); } - public void Insert(int index, T item) { + public void Insert (int index, T item) { CheckIndex(index); if (Count == Items.Length) GrowIfNeeded(1); @@ -332,12 +331,12 @@ namespace Spine { version++; } - private void CheckCollection(IEnumerable collection) { + private void CheckCollection (IEnumerable collection) { if (collection == null) throw new ArgumentNullException("collection"); } - public void InsertRange(int index, IEnumerable collection) { + public void InsertRange (int index, IEnumerable collection) { CheckCollection(collection); CheckIndex(index); if (collection == this) { @@ -356,7 +355,7 @@ namespace Spine { version++; } - private void InsertCollection(int index, ICollection collection) { + private void InsertCollection (int index, ICollection collection) { int collectionCount = collection.Count; GrowIfNeeded(collectionCount); @@ -364,21 +363,21 @@ namespace Spine { collection.CopyTo(Items, index); } - private void InsertEnumeration(int index, IEnumerable enumerable) { + private void InsertEnumeration (int index, IEnumerable enumerable) { foreach (T t in enumerable) Insert(index++, t); } - public int LastIndexOf(T item) { + public int LastIndexOf (T item) { return Array.LastIndexOf(Items, item, Count - 1, Count); } - public int LastIndexOf(T item, int index) { + public int LastIndexOf (T item, int index) { CheckIndex(index); return Array.LastIndexOf(Items, item, index, index + 1); } - public int LastIndexOf(T item, int index, int count) { + public int LastIndexOf (T item, int index, int count) { if (index < 0) throw new ArgumentOutOfRangeException("index", index, "index is negative"); @@ -391,7 +390,7 @@ namespace Spine { return Array.LastIndexOf(Items, item, index, count); } - public bool Remove(T item) { + public bool Remove (T item) { int loc = IndexOf(item); if (loc != -1) RemoveAt(loc); @@ -399,7 +398,7 @@ namespace Spine { return loc != -1; } - public int RemoveAll(Predicate match) { + public int RemoveAll (Predicate match) { CheckMatch(match); int i = 0; int j = 0; @@ -426,15 +425,15 @@ namespace Spine { return (j - i); } - public void RemoveAt(int index) { - if (index < 0 || (uint) index >= (uint) Count) + public void RemoveAt (int index) { + if (index < 0 || (uint)index >= (uint)Count) throw new ArgumentOutOfRangeException("index"); Shift(index, -1); Array.Clear(Items, Count, 1); version++; } - public void RemoveRange(int index, int count) { + public void RemoveRange (int index, int count) { CheckRange(index, count); if (count > 0) { Shift(index, -count); @@ -443,50 +442,50 @@ namespace Spine { } } - public void Reverse() { + public void Reverse () { Array.Reverse(Items, 0, Count); version++; } - public void Reverse(int index, int count) { + public void Reverse (int index, int count) { CheckRange(index, count); Array.Reverse(Items, index, count); version++; } - public void Sort() { + public void Sort () { Array.Sort(Items, 0, Count, Comparer.Default); version++; } - public void Sort(IComparer comparer) { + public void Sort (IComparer comparer) { Array.Sort(Items, 0, Count, comparer); version++; } - public void Sort(Comparison comparison) { + public void Sort (Comparison comparison) { Array.Sort(Items, comparison); version++; } - public void Sort(int index, int count, IComparer comparer) { + public void Sort (int index, int count, IComparer comparer) { CheckRange(index, count); Array.Sort(Items, index, count, comparer); version++; } - public T[] ToArray() { + public T[] ToArray () { T[] t = new T[Count]; Array.Copy(Items, t, Count); return t; } - public void TrimExcess() { + public void TrimExcess () { Capacity = Count; } - public bool TrueForAll(Predicate match) { + public bool TrueForAll (Predicate match) { CheckMatch(match); for (int i = 0; i < Count; i++) @@ -501,7 +500,7 @@ namespace Spine { return Items.Length; } set { - if ((uint) value < (uint) Count) + if ((uint)value < (uint)Count) throw new ArgumentOutOfRangeException(); Array.Resize(ref Items, value); @@ -510,11 +509,11 @@ namespace Spine { #region Interface implementations. - IEnumerator IEnumerable.GetEnumerator() { + IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator(); } - IEnumerator IEnumerable.GetEnumerator() { + IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator(); } @@ -525,28 +524,27 @@ namespace Spine { private ExposedList l; private int next; private int ver; - private T current; - internal Enumerator(ExposedList l) + internal Enumerator (ExposedList l) : this() { this.l = l; ver = l.version; } - public void Dispose() { + public void Dispose () { l = null; } - private void VerifyState() { + private void VerifyState () { if (l == null) throw new ObjectDisposedException(GetType().FullName); if (ver != l.version) throw new InvalidOperationException( - "Collection was modified; enumeration operation may not execute."); + "Collection was modified; enumeration operation may not execute."); } - public bool MoveNext() { + public bool MoveNext () { VerifyState(); if (next < 0) @@ -567,7 +565,7 @@ namespace Spine { } } - void IEnumerator.Reset() { + void IEnumerator.Reset () { VerifyState(); next = 0; } diff --git a/spine-csharp/src/Json.cs b/spine-csharp/src/Json.cs index 376dd7ef7..89b3c8c12 100644 --- a/spine-csharp/src/Json.cs +++ b/spine-csharp/src/Json.cs @@ -32,511 +32,502 @@ using System.Collections.Generic; using System.IO; using System.Text; using System.Globalization; - -namespace Spine -{ - // Example usage: - // - // using UnityEngine; - // using System.Collections; - // using System.Collections.Generic; - // using MiniJSON; - // - // public class MiniJSONTest : MonoBehaviour { - // void Start () { - // var jsonString = "{ \"array\": [1.44,2,3], " + - // "\"object\": {\"key1\":\"value1\", \"key2\":256}, " + - // "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " + - // "\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " + - // "\"int\": 65536, " + - // "\"float\": 3.1415926, " + - // "\"bool\": true, " + - // "\"null\": null }"; - // - // var dict = Json.Deserialize(jsonString) as Dictionary; - // - // Debug.Log("deserialized: " + dict.GetType()); - // Debug.Log("dict['array'][0]: " + ((List) dict["array"])[0]); - // Debug.Log("dict['string']: " + (string) dict["string"]); - // Debug.Log("dict['float']: " + (float) dict["float"]); - // Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs - // Debug.Log("dict['unicode']: " + (string) dict["unicode"]); - // - // var str = Json.Serialize(dict); - // - // Debug.Log("serialized: " + str); - // } - // } - - /// - /// This class encodes and decodes JSON strings. - /// Spec. details, see http://www.json.org/ - /// - /// JSON uses Arrays and Objects. These correspond here to the datatypes IList and IDictionary. - /// All numbers are parsed to floats. - /// - public static class Json { - /// - /// Parses the string json into a value - /// - /// A JSON string. - /// An List<object>, a Dictionary<string, object>, a float, an integer,a string, null, true, or false - public static object Deserialize (TextReader json) { - if (json == null) { - return null; - } - return Parser.Parse(json); - } - - sealed class Parser : IDisposable { - const string WHITE_SPACE = " \t\n\r"; - const string WORD_BREAK = " \t\n\r{}[],:\""; - - enum TOKEN { - NONE, - CURLY_OPEN, - CURLY_CLOSE, - SQUARED_OPEN, - SQUARED_CLOSE, - COLON, - COMMA, - STRING, - NUMBER, - TRUE, - FALSE, - NULL - }; - - TextReader json; - - Parser(TextReader reader) { - json = reader; - } - public static object Parse (TextReader reader) { - using (var instance = new Parser(reader)) { - return instance.ParseValue(); - } - } - - public void Dispose() { - json.Dispose(); - json = null; - } - - Dictionary ParseObject() { - Dictionary table = new Dictionary(); - - // ditch opening brace - json.Read(); - - // { - while (true) { - switch (NextToken) { - case TOKEN.NONE: - return null; - case TOKEN.COMMA: - continue; - case TOKEN.CURLY_CLOSE: - return table; - default: - // name - string name = ParseString(); - if (name == null) { - return null; - } - - // : - if (NextToken != TOKEN.COLON) { - return null; - } - // ditch the colon - json.Read(); - - // value - table[name] = ParseValue(); - break; - } - } - } - - List ParseArray() { - List array = new List(); - - // ditch opening bracket - json.Read(); - - // [ - var parsing = true; - while (parsing) { - TOKEN nextToken = NextToken; - - switch (nextToken) { - case TOKEN.NONE: - return null; - case TOKEN.COMMA: - continue; - case TOKEN.SQUARED_CLOSE: - parsing = false; - break; - default: - object value = ParseByToken(nextToken); - - array.Add(value); - break; - } - } - - return array; - } - - object ParseValue() { - TOKEN nextToken = NextToken; - return ParseByToken(nextToken); - } - - object ParseByToken(TOKEN token) { - switch (token) { - case TOKEN.STRING: - return ParseString(); - case TOKEN.NUMBER: - return ParseNumber(); - case TOKEN.CURLY_OPEN: - return ParseObject(); - case TOKEN.SQUARED_OPEN: - return ParseArray(); - case TOKEN.TRUE: - return true; - case TOKEN.FALSE: - return false; - case TOKEN.NULL: - return null; - default: - return null; - } - } - - string ParseString() { - StringBuilder s = new StringBuilder(); - char c; - - // ditch opening quote - json.Read(); - - bool parsing = true; - while (parsing) { - - if (json.Peek() == -1) { - parsing = false; - break; - } - - c = NextChar; - switch (c) { - case '"': - parsing = false; - break; - case '\\': - if (json.Peek() == -1) { - parsing = false; - break; - } - - c = NextChar; - switch (c) { - case '"': - case '\\': - case '/': - s.Append(c); - break; - case 'b': - s.Append('\b'); - break; - case 'f': - s.Append('\f'); - break; - case 'n': - s.Append('\n'); - break; - case 'r': - s.Append('\r'); - break; - case 't': - s.Append('\t'); - break; - case 'u': - var hex = new StringBuilder(); - - for (int i=0; i< 4; i++) { - hex.Append(NextChar); - } - - s.Append((char) Convert.ToInt32(hex.ToString(), 16)); - break; - } - break; - default: - s.Append(c); - break; - } - } - - return s.ToString(); - } - - object ParseNumber() { - string number = NextWord; - float parsedFloat; - float.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedFloat); - return parsedFloat; - } - - void EatWhitespace() { - while (WHITE_SPACE.IndexOf(PeekChar) != -1) { - json.Read(); - - if (json.Peek() == -1) { - break; - } - } - } - - char PeekChar { - get { - return Convert.ToChar(json.Peek()); - } - } - - char NextChar { - get { - return Convert.ToChar(json.Read()); - } - } - - string NextWord { - get { - StringBuilder word = new StringBuilder(); - - while (WORD_BREAK.IndexOf(PeekChar) == -1) { - word.Append(NextChar); - - if (json.Peek() == -1) { - break; - } - } - - return word.ToString(); - } - } - - TOKEN NextToken { - get { - EatWhitespace(); - - if (json.Peek() == -1) { - return TOKEN.NONE; - } - - char c = PeekChar; - switch (c) { - case '{': - return TOKEN.CURLY_OPEN; - case '}': - json.Read(); - return TOKEN.CURLY_CLOSE; - case '[': - return TOKEN.SQUARED_OPEN; - case ']': - json.Read(); - return TOKEN.SQUARED_CLOSE; - case ',': - json.Read(); - return TOKEN.COMMA; - case '"': - return TOKEN.STRING; - case ':': - return TOKEN.COLON; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - return TOKEN.NUMBER; - } - - string word = NextWord; - - switch (word) { - case "false": - return TOKEN.FALSE; - case "true": - return TOKEN.TRUE; - case "null": - return TOKEN.NULL; - } - - return TOKEN.NONE; - } - } - } - - /// - /// Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string - /// - /// A Dictionary<string, object> / List<object> - /// A JSON encoded string, or null if object 'json' is not serializable - public static string Serialize(object obj) { - return Serializer.Serialize(obj); - } - - sealed class Serializer { - StringBuilder builder; - - Serializer() { - builder = new StringBuilder(); - } - - public static string Serialize(object obj) { - var instance = new Serializer(); - - instance.SerializeValue(obj); - - return instance.builder.ToString(); - } - - void SerializeValue(object value) { - IList asList; - IDictionary asDict; - string asStr; - - if (value == null) { - builder.Append("null"); - } - else if ((asStr = value as string) != null) { - SerializeString(asStr); - } - else if (value is bool) { - builder.Append(value.ToString().ToLower()); - } - else if ((asList = value as IList) != null) { - SerializeArray(asList); - } - else if ((asDict = value as IDictionary) != null) { - SerializeObject(asDict); - } - else if (value is char) { - SerializeString(value.ToString()); - } - else { - SerializeOther(value); - } - } - - void SerializeObject(IDictionary obj) { - bool first = true; - - builder.Append('{'); - - foreach (object e in obj.Keys) { - if (!first) { - builder.Append(','); - } - - SerializeString(e.ToString()); - builder.Append(':'); - - SerializeValue(obj[e]); - - first = false; - } - - builder.Append('}'); - } - - void SerializeArray(IList anArray) { - builder.Append('['); - - bool first = true; - - foreach (object obj in anArray) { - if (!first) { - builder.Append(','); - } - - SerializeValue(obj); - - first = false; - } - - builder.Append(']'); - } - - void SerializeString(string str) { - builder.Append('\"'); - - char[] charArray = str.ToCharArray(); - foreach (var c in charArray) { - switch (c) { - case '"': - builder.Append("\\\""); - break; - case '\\': - builder.Append("\\\\"); - break; - case '\b': - builder.Append("\\b"); - break; - case '\f': - builder.Append("\\f"); - break; - case '\n': - builder.Append("\\n"); - break; - case '\r': - builder.Append("\\r"); - break; - case '\t': - builder.Append("\\t"); - break; - default: - int codepoint = Convert.ToInt32(c); - if ((codepoint >= 32) && (codepoint <= 126)) { - builder.Append(c); - } - else { - builder.Append("\\u" + Convert.ToString(codepoint, 16).PadLeft(4, '0')); - } - break; - } - } - - builder.Append('\"'); - } - - void SerializeOther(object value) { - if (value is float - || value is int - || value is uint - || value is long - || value is float - || value is sbyte - || value is byte - || value is short - || value is ushort - || value is ulong - || value is decimal) { - builder.Append(value.ToString()); - } - else { - SerializeString(value.ToString()); - } - } - } - } +namespace Spine { + // Example usage: + // + // using UnityEngine; + // using System.Collections; + // using System.Collections.Generic; + // using MiniJSON; + // + // public class MiniJSONTest : MonoBehaviour { + // void Start () { + // var jsonString = "{ \"array\": [1.44,2,3], " + + // "\"object\": {\"key1\":\"value1\", \"key2\":256}, " + + // "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " + + // "\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " + + // "\"int\": 65536, " + + // "\"float\": 3.1415926, " + + // "\"bool\": true, " + + // "\"null\": null }"; + // + // var dict = Json.Deserialize(jsonString) as Dictionary; + // + // Debug.Log("deserialized: " + dict.GetType()); + // Debug.Log("dict['array'][0]: " + ((List) dict["array"])[0]); + // Debug.Log("dict['string']: " + (string) dict["string"]); + // Debug.Log("dict['float']: " + (float) dict["float"]); + // Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs + // Debug.Log("dict['unicode']: " + (string) dict["unicode"]); + // + // var str = Json.Serialize(dict); + // + // Debug.Log("serialized: " + str); + // } + // } + + /// + /// This class encodes and decodes JSON strings. + /// Spec. details, see http://www.json.org/ + /// + /// JSON uses Arrays and Objects. These correspond here to the datatypes IList and IDictionary. + /// All numbers are parsed to floats. + /// + public static class Json { + /// + /// Parses the string json into a value + /// + /// A JSON string. + /// An List<object>, a Dictionary<string, object>, a float, an integer,a string, null, true, or false + public static object Deserialize (TextReader json) { + if (json == null) { + return null; + } + return Parser.Parse(json); + } + + sealed class Parser : IDisposable { + const string WHITE_SPACE = " \t\n\r"; + const string WORD_BREAK = " \t\n\r{}[],:\""; + + enum TOKEN { + NONE, + CURLY_OPEN, + CURLY_CLOSE, + SQUARED_OPEN, + SQUARED_CLOSE, + COLON, + COMMA, + STRING, + NUMBER, + TRUE, + FALSE, + NULL + }; + + TextReader json; + + Parser (TextReader reader) { + json = reader; + } + + public static object Parse (TextReader reader) { + using (var instance = new Parser(reader)) { + return instance.ParseValue(); + } + } + + public void Dispose () { + json.Dispose(); + json = null; + } + + Dictionary ParseObject () { + Dictionary table = new Dictionary(); + + // ditch opening brace + json.Read(); + + // { + while (true) { + switch (NextToken) { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.CURLY_CLOSE: + return table; + default: + // name + string name = ParseString(); + if (name == null) { + return null; + } + + // : + if (NextToken != TOKEN.COLON) { + return null; + } + // ditch the colon + json.Read(); + + // value + table[name] = ParseValue(); + break; + } + } + } + + List ParseArray () { + List array = new List(); + + // ditch opening bracket + json.Read(); + + // [ + var parsing = true; + while (parsing) { + TOKEN nextToken = NextToken; + + switch (nextToken) { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.SQUARED_CLOSE: + parsing = false; + break; + default: + object value = ParseByToken(nextToken); + + array.Add(value); + break; + } + } + + return array; + } + + object ParseValue () { + TOKEN nextToken = NextToken; + return ParseByToken(nextToken); + } + + object ParseByToken (TOKEN token) { + switch (token) { + case TOKEN.STRING: + return ParseString(); + case TOKEN.NUMBER: + return ParseNumber(); + case TOKEN.CURLY_OPEN: + return ParseObject(); + case TOKEN.SQUARED_OPEN: + return ParseArray(); + case TOKEN.TRUE: + return true; + case TOKEN.FALSE: + return false; + case TOKEN.NULL: + return null; + default: + return null; + } + } + + string ParseString () { + StringBuilder s = new StringBuilder(); + char c; + + // ditch opening quote + json.Read(); + + bool parsing = true; + while (parsing) { + + if (json.Peek() == -1) { + parsing = false; + break; + } + + c = NextChar; + switch (c) { + case '"': + parsing = false; + break; + case '\\': + if (json.Peek() == -1) { + parsing = false; + break; + } + + c = NextChar; + switch (c) { + case '"': + case '\\': + case '/': + s.Append(c); + break; + case 'b': + s.Append('\b'); + break; + case 'f': + s.Append('\f'); + break; + case 'n': + s.Append('\n'); + break; + case 'r': + s.Append('\r'); + break; + case 't': + s.Append('\t'); + break; + case 'u': + var hex = new StringBuilder(); + + for (int i = 0; i < 4; i++) { + hex.Append(NextChar); + } + + s.Append((char)Convert.ToInt32(hex.ToString(), 16)); + break; + } + break; + default: + s.Append(c); + break; + } + } + + return s.ToString(); + } + + object ParseNumber () { + string number = NextWord; + float parsedFloat; + float.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedFloat); + return parsedFloat; + } + + void EatWhitespace () { + while (WHITE_SPACE.IndexOf(PeekChar) != -1) { + json.Read(); + + if (json.Peek() == -1) { + break; + } + } + } + + char PeekChar { + get { + return Convert.ToChar(json.Peek()); + } + } + + char NextChar { + get { + return Convert.ToChar(json.Read()); + } + } + + string NextWord { + get { + StringBuilder word = new StringBuilder(); + + while (WORD_BREAK.IndexOf(PeekChar) == -1) { + word.Append(NextChar); + + if (json.Peek() == -1) { + break; + } + } + + return word.ToString(); + } + } + + TOKEN NextToken { + get { + EatWhitespace(); + + if (json.Peek() == -1) { + return TOKEN.NONE; + } + + char c = PeekChar; + switch (c) { + case '{': + return TOKEN.CURLY_OPEN; + case '}': + json.Read(); + return TOKEN.CURLY_CLOSE; + case '[': + return TOKEN.SQUARED_OPEN; + case ']': + json.Read(); + return TOKEN.SQUARED_CLOSE; + case ',': + json.Read(); + return TOKEN.COMMA; + case '"': + return TOKEN.STRING; + case ':': + return TOKEN.COLON; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + return TOKEN.NUMBER; + } + + string word = NextWord; + + switch (word) { + case "false": + return TOKEN.FALSE; + case "true": + return TOKEN.TRUE; + case "null": + return TOKEN.NULL; + } + + return TOKEN.NONE; + } + } + } + + /// + /// Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string + /// + /// A Dictionary<string, object> / List<object> + /// A JSON encoded string, or null if object 'json' is not serializable + public static string Serialize (object obj) { + return Serializer.Serialize(obj); + } + + sealed class Serializer { + StringBuilder builder; + + Serializer () { + builder = new StringBuilder(); + } + + public static string Serialize (object obj) { + var instance = new Serializer(); + + instance.SerializeValue(obj); + + return instance.builder.ToString(); + } + + void SerializeValue (object value) { + IList asList; + IDictionary asDict; + string asStr; + + if (value == null) { + builder.Append("null"); + } else if ((asStr = value as string) != null) { + SerializeString(asStr); + } else if (value is bool) { + builder.Append(value.ToString().ToLower()); + } else if ((asList = value as IList) != null) { + SerializeArray(asList); + } else if ((asDict = value as IDictionary) != null) { + SerializeObject(asDict); + } else if (value is char) { + SerializeString(value.ToString()); + } else { + SerializeOther(value); + } + } + + void SerializeObject (IDictionary obj) { + bool first = true; + + builder.Append('{'); + + foreach (object e in obj.Keys) { + if (!first) { + builder.Append(','); + } + + SerializeString(e.ToString()); + builder.Append(':'); + + SerializeValue(obj[e]); + + first = false; + } + + builder.Append('}'); + } + + void SerializeArray (IList anArray) { + builder.Append('['); + + bool first = true; + + foreach (object obj in anArray) { + if (!first) { + builder.Append(','); + } + + SerializeValue(obj); + + first = false; + } + + builder.Append(']'); + } + + void SerializeString (string str) { + builder.Append('\"'); + + char[] charArray = str.ToCharArray(); + foreach (var c in charArray) { + switch (c) { + case '"': + builder.Append("\\\""); + break; + case '\\': + builder.Append("\\\\"); + break; + case '\b': + builder.Append("\\b"); + break; + case '\f': + builder.Append("\\f"); + break; + case '\n': + builder.Append("\\n"); + break; + case '\r': + builder.Append("\\r"); + break; + case '\t': + builder.Append("\\t"); + break; + default: + int codepoint = Convert.ToInt32(c); + if ((codepoint >= 32) && (codepoint <= 126)) { + builder.Append(c); + } else { + builder.Append("\\u" + Convert.ToString(codepoint, 16).PadLeft(4, '0')); + } + break; + } + } + + builder.Append('\"'); + } + + void SerializeOther (object value) { + if (value is float + || value is int + || value is uint + || value is long + || value is float + || value is sbyte + || value is byte + || value is short + || value is ushort + || value is ulong + || value is decimal) { + builder.Append(value.ToString()); + } else { + SerializeString(value.ToString()); + } + } + } + } } \ No newline at end of file diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index 8cd9b91f1..dbd0ac831 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -133,7 +133,7 @@ namespace Spine { current = current.parent; } while (current != null); nonIkBones.Add(bone); - outer: {} + outer: { } } } @@ -181,7 +181,7 @@ namespace Spine { drawOrder.Clear(); for (int i = 0, n = slots.Count; i < n; i++) drawOrder.Add(slots.Items[i]); - + for (int i = 0, n = slots.Count; i < n; i++) slots.Items[i].SetToSetupPose(i); } diff --git a/spine-csharp/src/SkeletonBinary.cs b/spine-csharp/src/SkeletonBinary.cs index 4cbd34f1c..f4d3a7e4b 100644 --- a/spine-csharp/src/SkeletonBinary.cs +++ b/spine-csharp/src/SkeletonBinary.cs @@ -217,95 +217,95 @@ namespace Spine { switch ((AttachmentType)input.ReadByte()) { case AttachmentType.region: { - String path = ReadString(input); - if (path == null) path = name; - RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path); - if (region == null) return null; - region.Path = path; - region.x = ReadFloat(input) * scale; - region.y = ReadFloat(input) * scale; - region.scaleX = ReadFloat(input); - region.scaleY = ReadFloat(input); - region.rotation = ReadFloat(input); - region.width = ReadFloat(input) * scale; - region.height = ReadFloat(input) * scale; - int color = ReadInt(input); - region.r = ((color & 0xff000000) >> 24) / 255f; - region.g = ((color & 0x00ff0000) >> 16) / 255f; - region.b = ((color & 0x0000ff00) >> 8) / 255f; - region.a = ((color & 0x000000ff)) / 255f; - region.UpdateOffset(); - return region; - } + String path = ReadString(input); + if (path == null) path = name; + RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path); + if (region == null) return null; + region.Path = path; + region.x = ReadFloat(input) * scale; + region.y = ReadFloat(input) * scale; + region.scaleX = ReadFloat(input); + region.scaleY = ReadFloat(input); + region.rotation = ReadFloat(input); + region.width = ReadFloat(input) * scale; + region.height = ReadFloat(input) * scale; + int color = ReadInt(input); + region.r = ((color & 0xff000000) >> 24) / 255f; + region.g = ((color & 0x00ff0000) >> 16) / 255f; + region.b = ((color & 0x0000ff00) >> 8) / 255f; + region.a = ((color & 0x000000ff)) / 255f; + region.UpdateOffset(); + return region; + } case AttachmentType.boundingbox: { - BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name); - if (box == null) return null; - box.vertices = ReadFloatArray(input, scale); - return box; - } + BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name); + if (box == null) return null; + box.vertices = ReadFloatArray(input, scale); + return box; + } case AttachmentType.mesh: { - String path = ReadString(input); - if (path == null) path = name; - MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path); - if (mesh == null) return null; - mesh.Path = path; - mesh.regionUVs = ReadFloatArray(input, 1); - mesh.triangles = ReadShortArray(input); - mesh.vertices = ReadFloatArray(input, scale); - mesh.UpdateUVs(); - int color = ReadInt(input); - mesh.r = ((color & 0xff000000) >> 24) / 255f; - mesh.g = ((color & 0x00ff0000) >> 16) / 255f; - mesh.b = ((color & 0x0000ff00) >> 8) / 255f; - mesh.a = ((color & 0x000000ff)) / 255f; - mesh.HullLength = ReadInt(input, true) * 2; - if (nonessential) { - mesh.Edges = ReadIntArray(input); - mesh.Width = ReadFloat(input) * scale; - mesh.Height = ReadFloat(input) * scale; - } - return mesh; - } - case AttachmentType.skinnedmesh: { - String path = ReadString(input); - if (path == null) path = name; - SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path); - if (mesh == null) return null; - mesh.Path = path; - float[] uvs = ReadFloatArray(input, 1); - int[] triangles = ReadShortArray(input); - - int vertexCount = ReadInt(input, true); - var weights = new List(uvs.Length * 3 * 3); - var bones = new List(uvs.Length * 3); - for (int i = 0; i < vertexCount; i++) { - int boneCount = (int)ReadFloat(input); - bones.Add(boneCount); - for (int nn = i + boneCount * 4; i < nn; i += 4) { - bones.Add((int)ReadFloat(input)); - weights.Add(ReadFloat(input) * scale); - weights.Add(ReadFloat(input) * scale); - weights.Add(ReadFloat(input)); + String path = ReadString(input); + if (path == null) path = name; + MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path); + if (mesh == null) return null; + mesh.Path = path; + mesh.regionUVs = ReadFloatArray(input, 1); + mesh.triangles = ReadShortArray(input); + mesh.vertices = ReadFloatArray(input, scale); + mesh.UpdateUVs(); + int color = ReadInt(input); + mesh.r = ((color & 0xff000000) >> 24) / 255f; + mesh.g = ((color & 0x00ff0000) >> 16) / 255f; + mesh.b = ((color & 0x0000ff00) >> 8) / 255f; + mesh.a = ((color & 0x000000ff)) / 255f; + mesh.HullLength = ReadInt(input, true) * 2; + if (nonessential) { + mesh.Edges = ReadIntArray(input); + mesh.Width = ReadFloat(input) * scale; + mesh.Height = ReadFloat(input) * scale; } + return mesh; } - mesh.bones = bones.ToArray(); - mesh.weights = weights.ToArray(); - mesh.triangles = triangles; - mesh.regionUVs = uvs; - mesh.UpdateUVs(); - int color = ReadInt(input); - mesh.r = ((color & 0xff000000) >> 24) / 255f; - mesh.g = ((color & 0x00ff0000) >> 16) / 255f; - mesh.b = ((color & 0x0000ff00) >> 8) / 255f; - mesh.a = ((color & 0x000000ff)) / 255f; - mesh.HullLength = ReadInt(input, true) * 2; - if (nonessential) { - mesh.Edges = ReadIntArray(input); - mesh.Width = ReadFloat(input) * scale; - mesh.Height = ReadFloat(input) * scale; + case AttachmentType.skinnedmesh: { + String path = ReadString(input); + if (path == null) path = name; + SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path); + if (mesh == null) return null; + mesh.Path = path; + float[] uvs = ReadFloatArray(input, 1); + int[] triangles = ReadShortArray(input); + + int vertexCount = ReadInt(input, true); + var weights = new List(uvs.Length * 3 * 3); + var bones = new List(uvs.Length * 3); + for (int i = 0; i < vertexCount; i++) { + int boneCount = (int)ReadFloat(input); + bones.Add(boneCount); + for (int nn = i + boneCount * 4; i < nn; i += 4) { + bones.Add((int)ReadFloat(input)); + weights.Add(ReadFloat(input) * scale); + weights.Add(ReadFloat(input) * scale); + weights.Add(ReadFloat(input)); + } + } + mesh.bones = bones.ToArray(); + mesh.weights = weights.ToArray(); + mesh.triangles = triangles; + mesh.regionUVs = uvs; + mesh.UpdateUVs(); + int color = ReadInt(input); + mesh.r = ((color & 0xff000000) >> 24) / 255f; + mesh.g = ((color & 0x00ff0000) >> 16) / 255f; + mesh.b = ((color & 0x0000ff00) >> 8) / 255f; + mesh.a = ((color & 0x000000ff)) / 255f; + mesh.HullLength = ReadInt(input, true) * 2; + if (nonessential) { + mesh.Edges = ReadIntArray(input); + mesh.Width = ReadFloat(input) * scale; + mesh.Height = ReadFloat(input) * scale; + } + return mesh; } - return mesh; - } } return null; } @@ -343,7 +343,7 @@ namespace Spine { var timelines = new ExposedList(); float scale = Scale; float duration = 0; - + // Slot timelines. for (int i = 0, n = ReadInt(input, true); i < n; i++) { int slotIndex = ReadInt(input, true); @@ -352,31 +352,31 @@ namespace Spine { int frameCount = ReadInt(input, true); switch (timelineType) { case TIMELINE_COLOR: { - ColorTimeline timeline = new ColorTimeline(frameCount); - timeline.slotIndex = slotIndex; - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { - float time = ReadFloat(input); - int color = ReadInt(input); - float r = ((color & 0xff000000) >> 24) / 255f; - float g = ((color & 0x00ff0000) >> 16) / 255f; - float b = ((color & 0x0000ff00) >> 8) / 255f; - float a = ((color & 0x000000ff)) / 255f; - timeline.SetFrame(frameIndex, time, r, g, b, a); - if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); + ColorTimeline timeline = new ColorTimeline(frameCount); + timeline.slotIndex = slotIndex; + for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { + float time = ReadFloat(input); + int color = ReadInt(input); + float r = ((color & 0xff000000) >> 24) / 255f; + float g = ((color & 0x00ff0000) >> 16) / 255f; + float b = ((color & 0x0000ff00) >> 8) / 255f; + float a = ((color & 0x000000ff)) / 255f; + timeline.SetFrame(frameIndex, time, r, g, b, a); + if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); + } + timelines.Add(timeline); + duration = Math.Max(duration, timeline.frames[frameCount * 5 - 5]); + break; } - timelines.Add(timeline); - duration = Math.Max(duration, timeline.frames[frameCount * 5 - 5]); - break; - } case TIMELINE_ATTACHMENT: { - AttachmentTimeline timeline = new AttachmentTimeline(frameCount); - timeline.slotIndex = slotIndex; - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) - timeline.SetFrame(frameIndex, ReadFloat(input), ReadString(input)); - timelines.Add(timeline); - duration = Math.Max(duration, timeline.frames[frameCount - 1]); - break; - } + AttachmentTimeline timeline = new AttachmentTimeline(frameCount); + timeline.slotIndex = slotIndex; + for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) + timeline.SetFrame(frameIndex, ReadFloat(input), ReadString(input)); + timelines.Add(timeline); + duration = Math.Max(duration, timeline.frames[frameCount - 1]); + break; + } } } } @@ -389,47 +389,47 @@ namespace Spine { int frameCount = ReadInt(input, true); switch (timelineType) { case TIMELINE_ROTATE: { - RotateTimeline timeline = new RotateTimeline(frameCount); - timeline.boneIndex = boneIndex; - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { - timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input)); - if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); + RotateTimeline timeline = new RotateTimeline(frameCount); + timeline.boneIndex = boneIndex; + for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { + timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input)); + if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); + } + timelines.Add(timeline); + duration = Math.Max(duration, timeline.frames[frameCount * 2 - 2]); + break; } - timelines.Add(timeline); - duration = Math.Max(duration, timeline.frames[frameCount * 2 - 2]); - break; - } case TIMELINE_TRANSLATE: case TIMELINE_SCALE: { - TranslateTimeline timeline; - float timelineScale = 1; - if (timelineType == TIMELINE_SCALE) - timeline = new ScaleTimeline(frameCount); - else { - timeline = new TranslateTimeline(frameCount); - timelineScale = scale; + TranslateTimeline timeline; + float timelineScale = 1; + if (timelineType == TIMELINE_SCALE) + timeline = new ScaleTimeline(frameCount); + else { + timeline = new TranslateTimeline(frameCount); + timelineScale = scale; + } + timeline.boneIndex = boneIndex; + for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { + timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input) * timelineScale, ReadFloat(input) + * timelineScale); + if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); + } + timelines.Add(timeline); + duration = Math.Max(duration, timeline.frames[frameCount * 3 - 3]); + break; } - timeline.boneIndex = boneIndex; - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { - timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input) * timelineScale, ReadFloat(input) - * timelineScale); - if (frameIndex < frameCount - 1) ReadCurve(input, frameIndex, timeline); - } - timelines.Add(timeline); - duration = Math.Max(duration, timeline.frames[frameCount * 3 - 3]); - break; - } case TIMELINE_FLIPX: case TIMELINE_FLIPY: { - FlipXTimeline timeline = timelineType == TIMELINE_FLIPX ? new FlipXTimeline(frameCount) : new FlipYTimeline( - frameCount); - timeline.boneIndex = boneIndex; - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) - timeline.SetFrame(frameIndex, ReadFloat(input), ReadBoolean(input)); - timelines.Add(timeline); - duration = Math.Max(duration, timeline.frames[frameCount * 2 - 2]); - break; - } + FlipXTimeline timeline = timelineType == TIMELINE_FLIPX ? new FlipXTimeline(frameCount) : new FlipYTimeline( + frameCount); + timeline.boneIndex = boneIndex; + for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) + timeline.SetFrame(frameIndex, ReadFloat(input), ReadBoolean(input)); + timelines.Add(timeline); + duration = Math.Max(duration, timeline.frames[frameCount * 2 - 2]); + break; + } } } } diff --git a/spine-csharp/src/SkeletonData.cs b/spine-csharp/src/SkeletonData.cs index 5976a24ad..f7b41a35a 100644 --- a/spine-csharp/src/SkeletonData.cs +++ b/spine-csharp/src/SkeletonData.cs @@ -105,7 +105,7 @@ namespace Spine { } // --- Skins. - + /// May be null. public Skin FindSkin (String skinName) { if (skinName == null) throw new ArgumentNullException("skinName cannot be null."); @@ -125,7 +125,7 @@ namespace Spine { } // --- Animations. - + /// May be null. public Animation FindAnimation (String animationName) { if (animationName == null) throw new ArgumentNullException("animationName cannot be null."); diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index bf31c0441..ba530941b 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -256,7 +256,7 @@ namespace Spine { MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path); if (mesh == null) return null; - mesh.Path = path; + mesh.Path = path; mesh.vertices = GetFloatArray(map, "vertices", Scale); mesh.triangles = GetIntArray(map, "triangles"); mesh.regionUVs = GetFloatArray(map, "uvs", 1); diff --git a/spine-csharp/src/Skin.cs b/spine-csharp/src/Skin.cs index 4b8408334..4c1c1edaa 100644 --- a/spine-csharp/src/Skin.cs +++ b/spine-csharp/src/Skin.cs @@ -91,7 +91,7 @@ namespace Spine { internal static readonly AttachmentKeyTupleComparer Instance = new AttachmentKeyTupleComparer(); bool IEqualityComparer.Equals (AttachmentKeyTuple o1, AttachmentKeyTuple o2) { - return o1.SlotIndex == o2.SlotIndex && o1.NameHashCode == o2.NameHashCode && o1.Name == o2.Name; + return o1.SlotIndex == o2.SlotIndex && o1.NameHashCode == o2.NameHashCode && o1.Name == o2.Name; } int IEqualityComparer.GetHashCode (AttachmentKeyTuple o) { @@ -99,16 +99,16 @@ namespace Spine { } } - private class AttachmentKeyTuple { - public readonly int SlotIndex; - public readonly string Name; - public readonly int NameHashCode; + private class AttachmentKeyTuple { + public readonly int SlotIndex; + public readonly string Name; + public readonly int NameHashCode; - public AttachmentKeyTuple(int slotIndex, string name) { - SlotIndex = slotIndex; - Name = name; - NameHashCode = Name.GetHashCode(); - } - } + public AttachmentKeyTuple (int slotIndex, string name) { + SlotIndex = slotIndex; + Name = name; + NameHashCode = Name.GetHashCode(); + } + } } } diff --git a/spine-unity/Assets/spine-unity/AtlasAsset.cs b/spine-unity/Assets/spine-unity/AtlasAsset.cs index 64d3cddaa..19dadb509 100644 --- a/spine-unity/Assets/spine-unity/AtlasAsset.cs +++ b/spine-unity/Assets/spine-unity/AtlasAsset.cs @@ -84,7 +84,7 @@ public class AtlasAsset : ScriptableObject { return sprite; } - public Mesh GenerateMesh(string name, Mesh mesh, out Material material, float scale = 0.01f){ + public Mesh GenerateMesh (string name, Mesh mesh, out Material material, float scale = 0.01f) { AtlasRegion region = atlas.FindRegion(name); material = null; if (region != null) { @@ -92,10 +92,10 @@ public class AtlasAsset : ScriptableObject { mesh = new Mesh(); mesh.name = name; } - + Vector3[] verts = new Vector3[4]; Vector2[] uvs = new Vector2[4]; - Color[] colors = new Color[4]{Color.white, Color.white, Color.white, Color.white}; + Color[] colors = new Color[4] { Color.white, Color.white, Color.white, Color.white }; int[] triangles = new int[6] { 0, 1, 2, 2, 3, 0 }; float left, right, top, bottom; @@ -118,7 +118,7 @@ public class AtlasAsset : ScriptableObject { uvs[0] = new Vector2(u, v2); uvs[1] = new Vector2(u, v); uvs[2] = new Vector2(u2, v); - uvs[3] = new Vector2(u2, v2); + uvs[3] = new Vector2(u2, v2); } else { uvs[0] = new Vector2(u2, v2); uvs[1] = new Vector2(u, v2); @@ -145,11 +145,11 @@ public class AtlasAsset : ScriptableObject { public class MaterialsTextureLoader : TextureLoader { AtlasAsset atlasAsset; - + public MaterialsTextureLoader (AtlasAsset atlasAsset) { this.atlasAsset = atlasAsset; } - + public void Load (AtlasPage page, String path) { String name = Path.GetFileNameWithoutExtension(path); Material material = null; diff --git a/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs b/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs index 408f5b19b..84fef5f45 100644 --- a/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs +++ b/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs @@ -50,14 +50,14 @@ public class AtlasRegionAttacher : MonoBehaviour { Atlas atlas; - void Awake() { + void Awake () { GetComponent().OnReset += Apply; } - void Apply(SkeletonRenderer skeletonRenderer) { + void Apply (SkeletonRenderer skeletonRenderer) { atlas = atlasAsset.GetAtlas(); - + AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas); float scaleMultiplier = skeletonRenderer.skeletonDataAsset.scale; diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index 24bfaa6d4..0866f1f62 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -58,7 +58,7 @@ public class BoneFollower : MonoBehaviour { /// If a bone isn't set, boneName is used to find the bone. - + [SpineBone(dataField: "skeletonRenderer")] public String boneName; public bool resetOnAwake = true; diff --git a/spine-unity/Assets/spine-unity/CustomSkin.cs b/spine-unity/Assets/spine-unity/CustomSkin.cs index 67f1647ab..ea74d572a 100644 --- a/spine-unity/Assets/spine-unity/CustomSkin.cs +++ b/spine-unity/Assets/spine-unity/CustomSkin.cs @@ -51,7 +51,7 @@ public class CustomSkin : MonoBehaviour { public Skin customSkin; SkeletonRenderer skeletonRenderer; - void Start() { + void Start () { skeletonRenderer = GetComponent(); Skeleton skeleton = skeletonRenderer.skeleton; diff --git a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs index ee86a3920..6ce7dfefb 100644 --- a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs +++ b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs @@ -24,7 +24,7 @@ public class SkeletonGhostRenderer : MonoBehaviour { StopAllCoroutines(); gameObject.SetActive(true); - + meshRenderer.sharedMaterials = materials; meshRenderer.sortingOrder = sortingOrder; @@ -83,7 +83,7 @@ public class SkeletonGhostRenderer : MonoBehaviour { c = colors[i]; black.a = c.a; if (c.r > 0 || c.g > 0 || c.b > 0) - breakout = false; + breakout = false; colors[i] = Color32.Lerp(c, black, Time.deltaTime * fadeSpeed); } diff --git a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs index 24cb9f6c1..c2ce22116 100644 --- a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs +++ b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs @@ -67,7 +67,7 @@ public class SkeletonRagdoll : MonoBehaviour { private Rigidbody rootRigidbody; private ISkeletonAnimation skeletonAnim; private Skeleton skeleton; - private Dictionary boneTable = new Dictionary(); + private Dictionary boneTable = new Dictionary(); private Bone startingBone; private Transform ragdollRoot; private Vector3 rootOffset; @@ -121,7 +121,7 @@ public class SkeletonRagdoll : MonoBehaviour { Rigidbody[] arr = new Rigidbody[boneTable.Count]; int i = 0; - foreach(Transform t in boneTable.Values){ + foreach (Transform t in boneTable.Values) { arr[i] = t.GetComponent(); i++; } @@ -242,7 +242,7 @@ public class SkeletonRagdoll : MonoBehaviour { Debug.LogWarning(msg); } } - + if (disableIK) { foreach (IkConstraint ik in skeleton.IkConstraints) { ik.Mix = 0; diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs index 0384417bd..7277ce233 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs @@ -42,7 +42,7 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation { public bool loop; public Spine.AnimationState state; - + public event UpdateBonesDelegate UpdateLocal { add { _UpdateLocal += value; } @@ -114,17 +114,17 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation { state.Update(deltaTime); state.Apply(skeleton); - if (_UpdateLocal != null) + if (_UpdateLocal != null) _UpdateLocal(this); skeleton.UpdateWorldTransform(); - if (_UpdateWorld != null) { + if (_UpdateWorld != null) { _UpdateWorld(this); skeleton.UpdateWorldTransform(); } - if (_UpdateComplete != null) { + if (_UpdateComplete != null) { _UpdateComplete(this); } } diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index 7994a661f..cd8d7726a 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -81,7 +81,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { //apply int layerCount = animator.layerCount; - + for (int i = 0; i < layerCount; i++) { float layerWeight = animator.GetLayerWeight(i); @@ -191,7 +191,7 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation { lastTime = Time.time; } - private int GetAnimationClipNameHashCode(AnimationClip clip) { + private int GetAnimationClipNameHashCode (AnimationClip clip) { int clipNameHashCode; if (!clipNameHashCodeTable.TryGetValue(clip, out clipNameHashCode)) { clipNameHashCode = clip.name.GetHashCode(); diff --git a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs index d378a338c..6a8b991c5 100644 --- a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs +++ b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs @@ -50,12 +50,12 @@ public class SkeletonDataAsset : ScriptableObject { private SkeletonData skeletonData; private AnimationStateData stateData; - public void Reset() { + public void Reset () { skeletonData = null; stateData = null; } - public SkeletonData GetSkeletonData(bool quiet) { + public SkeletonData GetSkeletonData (bool quiet) { if (atlasAssets == null) { atlasAssets = new AtlasAsset[0]; if (!quiet) @@ -98,7 +98,7 @@ public class SkeletonDataAsset : ScriptableObject { if (skeletonData != null) return skeletonData; - + AttachmentLoader attachmentLoader; float skeletonDataScale; @@ -161,7 +161,7 @@ public class SkeletonDataAsset : ScriptableObject { } } - public AnimationStateData GetAnimationStateData() { + public AnimationStateData GetAnimationStateData () { if (stateData != null) return stateData; GetSkeletonData(false); diff --git a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs index 9bf5e8b3f..03cf57536 100644 --- a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs @@ -17,7 +17,7 @@ public static class SkeletonExtensions { skeleton.G = color.g; skeleton.B = color.b; } - + public static void SetColor (this Skeleton skeleton, Color32 color) { skeleton.A = color.a / 255f; skeleton.R = color.r / 255f; diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index 193e907dc..3a36eded3 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -211,7 +211,7 @@ public class SkeletonRenderer : MonoBehaviour { int attachmentVertexCount, attachmentTriangleCount; bool worldScaleXIsPositive = bone.worldScaleX >= 0f; bool worldScaleYIsPositive = bone.worldScaleY >= 0f; - bool worldScaleIsSameSigns = (worldScaleXIsPositive && worldScaleYIsPositive) || + bool worldScaleIsSameSigns = (worldScaleXIsPositive && worldScaleYIsPositive) || (!worldScaleXIsPositive && !worldScaleYIsPositive); bool flip = frontFacing && ((bone.worldFlipX != bone.worldFlipY) == worldScaleIsSameSigns); attachmentsFlipStateTemp.Items[i] = flip; @@ -247,7 +247,7 @@ public class SkeletonRenderer : MonoBehaviour { #else Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject; #endif - if ((lastMaterial != null && lastMaterial.GetInstanceID() != material.GetInstanceID()) || + if ((lastMaterial != null && lastMaterial.GetInstanceID() != material.GetInstanceID()) || (submeshSeparatorSlotsCount > 0 && submeshSeparatorSlots.Contains(slot))) { addSubmeshArgumentsTemp.Add( new LastState.AddSubmeshArguments(lastMaterial, submeshStartSlotIndex, i, submeshTriangleCount, submeshFirstVertex, false) @@ -266,7 +266,7 @@ public class SkeletonRenderer : MonoBehaviour { addSubmeshArgumentsTemp.Add( new LastState.AddSubmeshArguments(lastMaterial, submeshStartSlotIndex, drawOrderCount, submeshTriangleCount, submeshFirstVertex, true) ); - + bool mustUpdateMeshStructure = CheckIfMustUpdateMeshStructure(attachmentsTriangleCountTemp, attachmentsFlipStateTemp, addSubmeshArgumentsTemp); if (mustUpdateMeshStructure) { submeshMaterials.Clear(); @@ -305,7 +305,7 @@ public class SkeletonRenderer : MonoBehaviour { } else { // Too many vertices, zero the extra. Vector3 zero = Vector3.zero; - for (int i = vertexCount, n = lastState.vertexCount ; i < n; i++) + for (int i = vertexCount, n = lastState.vertexCount; i < n; i++) vertices[i] = zero; } lastState.vertexCount = vertexCount; @@ -575,7 +575,7 @@ public class SkeletonRenderer : MonoBehaviour { useMesh1 = !useMesh1; } - private bool CheckIfMustUpdateMeshStructure(ExposedList attachmentsTriangleCountTemp, ExposedList attachmentsFlipStateTemp, ExposedList addSubmeshArgumentsTemp) { + private bool CheckIfMustUpdateMeshStructure (ExposedList attachmentsTriangleCountTemp, ExposedList attachmentsFlipStateTemp, ExposedList addSubmeshArgumentsTemp) { // Check if any mesh settings were changed bool mustUpdateMeshStructure = immutableTriangles != (useMesh1 ? lastState.immutableTrianglesMesh1 : lastState.immutableTrianglesMesh2); @@ -771,7 +771,7 @@ public class SkeletonRenderer : MonoBehaviour { public int firstVertex; public bool lastSubmesh; - public AddSubmeshArguments(Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh) { + public AddSubmeshArguments (Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh) { this.material = material; this.startSlot = startSlot; this.endSlot = endSlot; @@ -780,14 +780,14 @@ public class SkeletonRenderer : MonoBehaviour { this.lastSubmesh = lastSubmesh; } - public bool Equals(ref AddSubmeshArguments other) { + public bool Equals (ref AddSubmeshArguments other) { return !ReferenceEquals(material, null) && !ReferenceEquals(other.material, null) && material.GetInstanceID() == other.material.GetInstanceID() && - startSlot == other.startSlot && - endSlot == other.endSlot && - triangleCount == other.triangleCount && + startSlot == other.startSlot && + endSlot == other.endSlot && + triangleCount == other.triangleCount && firstVertex == other.firstVertex; } } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs index 60eb7bab5..49f775893 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs @@ -56,18 +56,18 @@ public class SkeletonUtility : MonoBehaviour { float[] floats = boundingBox.Vertices; int floatCount = floats.Length; int vertCount = floatCount / 2; - + Vector2[] verts = new Vector2[vertCount]; int v = 0; for (int i = 0; i < floatCount; i += 2, v++) { verts[v].x = floats[i]; - verts[v].y = floats[i+1]; + verts[v].y = floats[i + 1]; } collider.SetPath(0, verts); return collider; - + } return null; @@ -139,7 +139,7 @@ public class SkeletonUtility : MonoBehaviour { public List utilityBones = new List(); [System.NonSerialized] public List utilityConstraints = new List(); -// Dictionary utilityBoneTable; + // Dictionary utilityBoneTable; protected bool hasTransformBones; protected bool hasUtilityConstraints; @@ -170,7 +170,7 @@ public class SkeletonUtility : MonoBehaviour { void Start () { //recollect because order of operations failure when switching between game mode and edit mode... -// CollectBones(); + // CollectBones(); } void OnDisable () { @@ -182,7 +182,7 @@ public class SkeletonUtility : MonoBehaviour { skeletonAnimation.UpdateComplete -= UpdateComplete; } } - + void HandleRendererReset (SkeletonRenderer r) { if (OnReset != null) OnReset(); @@ -212,7 +212,7 @@ public class SkeletonUtility : MonoBehaviour { needToReprocessBones = true; } } - + public void UnregisterConstraint (SkeletonUtilityConstraint constraint) { utilityConstraints.Remove(constraint); } @@ -351,11 +351,11 @@ public class SkeletonUtility : MonoBehaviour { return go; } - + public GameObject SpawnBone (Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) { GameObject go = new GameObject(bone.Data.Name); go.transform.parent = parent; - + SkeletonUtilityBone b = go.AddComponent(); b.skeletonUtility = this; b.position = pos; @@ -371,16 +371,16 @@ public class SkeletonUtility : MonoBehaviour { if (mode == SkeletonUtilityBone.Mode.Override) { if (rot) go.transform.localRotation = Quaternion.Euler(0, 0, b.bone.RotationIK); - + if (pos) go.transform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0); - + go.transform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0); } return go; } - + public void SpawnSubRenderers (bool disablePrimaryRenderer) { int submeshCount = GetComponent().sharedMesh.subMeshCount; diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs index fcf2c2280..0b67b91df 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs @@ -34,7 +34,7 @@ public class SkeletonUtilityBone : MonoBehaviour { public bool scale; public bool flip; public bool flipX; - [Range(0f,1f)] + [Range(0f, 1f)] public float overrideAlpha = 1; /// If a bone isn't set, boneName is used to find the bone. @@ -109,10 +109,10 @@ public class SkeletonUtilityBone : MonoBehaviour { } } - + float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f; - + float flipCompensation = 0; if (flip && (flipX || (flipX != bone.flipX)) && bone.parent != null) { flipCompensation = bone.parent.WorldRotation * -2; @@ -133,7 +133,7 @@ public class SkeletonUtilityBone : MonoBehaviour { if (bone.Data.InheritRotation) { if (bone.FlipX) { cachedTransform.localRotation = Quaternion.Euler(0, 180, bone.rotationIK - flipCompensation); - } else { + } else { cachedTransform.localRotation = Quaternion.Euler(0, 0, bone.rotationIK); } } else { @@ -153,90 +153,90 @@ public class SkeletonUtilityBone : MonoBehaviour { - if (transformLerpComplete) - return; - - if (parentReference == null) { - if (position) { - bone.x = Mathf.Lerp(bone.x, cachedTransform.localPosition.x, overrideAlpha); - bone.y = Mathf.Lerp(bone.y, cachedTransform.localPosition.y, overrideAlpha); - } - - if (rotation) { - float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; - - if (flip) { - if ((!flipX && bone.flipX)) { - angle -= flipCompensation; - } - - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } - - bone.Rotation = angle; - bone.RotationIK = angle; - } - - if (scale) { - bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); - bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); - } - - if (flip) { - bone.flipX = flipX; - } - } else { - - if (transformLerpComplete) - return; - - if (position) { - Vector3 pos = parentReference.InverseTransformPoint(cachedTransform.position); - bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha); - bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); - } - - if (rotation) { - float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; - - if (flip) { - if ((!flipX && bone.flipX)) { - angle -= flipCompensation; - } - - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } - - bone.Rotation = angle; - bone.RotationIK = angle; - } - - //TODO: Something about this - if (scale) { - bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); - bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); - } - - if (flip) { - bone.flipX = flipX; - } + if (transformLerpComplete) + return; + if (parentReference == null) { + if (position) { + bone.x = Mathf.Lerp(bone.x, cachedTransform.localPosition.x, overrideAlpha); + bone.y = Mathf.Lerp(bone.y, cachedTransform.localPosition.y, overrideAlpha); } - transformLerpComplete = true; - } + if (rotation) { + float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; + + if (flip) { + if ((!flipX && bone.flipX)) { + angle -= flipCompensation; + } + + //TODO fix this... + if (angle >= 360) + angle -= 360; + else if (angle <= -360) + angle += 360; + } + + bone.Rotation = angle; + bone.RotationIK = angle; + } + + if (scale) { + bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); + bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); + + nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + } + + if (flip) { + bone.flipX = flipX; + } + } else { + + if (transformLerpComplete) + return; + + if (position) { + Vector3 pos = parentReference.InverseTransformPoint(cachedTransform.position); + bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha); + bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); + } + + if (rotation) { + float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; + + if (flip) { + if ((!flipX && bone.flipX)) { + angle -= flipCompensation; + } + + //TODO fix this... + if (angle >= 360) + angle -= 360; + else if (angle <= -360) + angle += 360; + } + + bone.Rotation = angle; + bone.RotationIK = angle; + } + + //TODO: Something about this + if (scale) { + bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); + bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); + + nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + } + + if (flip) { + bone.flipX = flipX; + } + + } + + transformLerpComplete = true; + } } public void FlipX (bool state) { @@ -246,9 +246,9 @@ public class SkeletonUtilityBone : MonoBehaviour { skeletonUtility.skeletonAnimation.LateUpdate(); return; } else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) { - skeletonUtility.skeletonAnimation.LateUpdate(); - return; - } + skeletonUtility.skeletonAnimation.LateUpdate(); + return; + } } bone.FlipX = state; diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs index b19cdcc6e..7b0e81430 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs @@ -41,7 +41,7 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint { public float speed = 10; Vector3[] origins; Vector3 centerPoint; - + protected override void OnEnable () { if (!Application.isPlaying) return; @@ -57,14 +57,14 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint { centerPoint = centerBounds.center; } - + protected override void OnDisable () { if (!Application.isPlaying) return; base.OnDisable(); } - + public override void DoUpdate () { if (target != null) @@ -75,13 +75,13 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint { Vector3 center = transform.TransformPoint(centerPoint); Vector3 dir = goal - center; - if (dir.magnitude > 1) + if (dir.magnitude > 1) dir.Normalize(); for (int i = 0; i < eyes.Length; i++) { center = transform.TransformPoint(origins[i]); eyes[i].position = Vector3.MoveTowards(eyes[i].position, center + (dir * radius), speed * Time.deltaTime); } - - } + + } } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs index 2cf37db78..371b5f170 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs @@ -128,7 +128,7 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint { Vector3 v = transform.position; v.y = Mathf.Clamp(v.y, Mathf.Min(lastHitY, hitY), float.MaxValue); transform.position = v; - + utilBone.bone.X = transform.localPosition.x; utilBone.bone.Y = transform.localPosition.y; diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs index ca32891ba..8f88297be 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs @@ -44,7 +44,7 @@ public class SkeletonUtilityKinematicShadow : MonoBehaviour { if (hideShadow) shadowRoot.hideFlags = HideFlags.HideInHierarchy; - if(parent == null) + if (parent == null) shadowRoot.transform.parent = transform.root; else shadowRoot.transform.parent = parent; diff --git a/spine-unity/Assets/spine-unity/SpineAttributes.cs b/spine-unity/Assets/spine-unity/SpineAttributes.cs index d59515b71..c102bdae4 100644 --- a/spine-unity/Assets/spine-unity/SpineAttributes.cs +++ b/spine-unity/Assets/spine-unity/SpineAttributes.cs @@ -21,7 +21,7 @@ public class SpineSlot : PropertyAttribute { /// If left empty and the script the attribute is applied to is derived from Component, GetComponent() will be called as a fallback. /// /// Disables popup results that don't contain bounding box attachments when true. - public SpineSlot(string startsWith = "", string dataField = "", bool containsBoundingBoxes = false) { + public SpineSlot (string startsWith = "", string dataField = "", bool containsBoundingBoxes = false) { this.startsWith = startsWith; this.dataField = dataField; this.containsBoundingBoxes = containsBoundingBoxes; @@ -40,7 +40,7 @@ public class SpineSkin : PropertyAttribute { /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives) /// If left empty and the script the attribute is applied to is derived from Component, GetComponent() will be called as a fallback. /// - public SpineSkin(string startsWith = "", string dataField = "") { + public SpineSkin (string startsWith = "", string dataField = "") { this.startsWith = startsWith; this.dataField = dataField; } @@ -57,7 +57,7 @@ public class SpineAnimation : PropertyAttribute { /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives) /// If left empty and the script the attribute is applied to is derived from Component, GetComponent() will be called as a fallback. /// - public SpineAnimation(string startsWith = "", string dataField = "") { + public SpineAnimation (string startsWith = "", string dataField = "") { this.startsWith = startsWith; this.dataField = dataField; } @@ -71,7 +71,7 @@ public class SpineAttachment : PropertyAttribute { public string slotField = ""; - public SpineAttachment() { + public SpineAttachment () { } @@ -86,19 +86,19 @@ public class SpineAttachment : PropertyAttribute { /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives) /// If left empty and the script the attribute is applied to is derived from Component, GetComponent() will be called as a fallback. /// - public SpineAttachment(bool currentSkinOnly = true, bool returnAttachmentPath = false, bool placeholdersOnly = false, string slotField = "", string dataField = "") { + public SpineAttachment (bool currentSkinOnly = true, bool returnAttachmentPath = false, bool placeholdersOnly = false, string slotField = "", string dataField = "") { this.currentSkinOnly = currentSkinOnly; this.returnAttachmentPath = returnAttachmentPath; this.placeholdersOnly = placeholdersOnly; this.slotField = slotField; - this.dataField = dataField; + this.dataField = dataField; } - public static Hierarchy GetHierarchy(string fullPath) { + public static Hierarchy GetHierarchy (string fullPath) { return new Hierarchy(fullPath); } - public static Spine.Attachment GetAttachment(string attachmentPath, Spine.SkeletonData skeletonData) { + public static Spine.Attachment GetAttachment (string attachmentPath, Spine.SkeletonData skeletonData) { var hierarchy = SpineAttachment.GetHierarchy(attachmentPath); if (hierarchy.name == "") return null; @@ -106,7 +106,7 @@ public class SpineAttachment : PropertyAttribute { return skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name); } - public static Spine.Attachment GetAttachment(string attachmentPath, SkeletonDataAsset skeletonDataAsset) { + public static Spine.Attachment GetAttachment (string attachmentPath, SkeletonDataAsset skeletonDataAsset) { return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true)); } @@ -115,15 +115,14 @@ public class SpineAttachment : PropertyAttribute { public string slot; public string name; - public Hierarchy(string fullPath) { - string[] chunks = fullPath.Split(new char[]{'/'}, System.StringSplitOptions.RemoveEmptyEntries); + public Hierarchy (string fullPath) { + string[] chunks = fullPath.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries); if (chunks.Length == 0) { skin = ""; slot = ""; name = ""; return; - } - else if (chunks.Length < 2) { + } else if (chunks.Length < 2) { throw new System.Exception("Cannot generate Attachment Hierarchy from string! Not enough components! [" + fullPath + "]"); } skin = chunks[0]; @@ -148,19 +147,19 @@ public class SpineBone : PropertyAttribute { /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives) /// If left empty and the script the attribute is applied to is derived from Component, GetComponent() will be called as a fallback. /// - public SpineBone(string startsWith = "", string dataField = "") { + public SpineBone (string startsWith = "", string dataField = "") { this.startsWith = startsWith; this.dataField = dataField; } - public static Spine.Bone GetBone(string boneName, SkeletonRenderer renderer) { + public static Spine.Bone GetBone (string boneName, SkeletonRenderer renderer) { if (renderer.skeleton == null) return null; return renderer.skeleton.FindBone(boneName); } - public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) { + public static Spine.BoneData GetBoneData (string boneName, SkeletonDataAsset skeletonDataAsset) { var data = skeletonDataAsset.GetSkeletonData(true); return data.FindBone(boneName);