From 0635c19fef5fa129c254562eb5a44f87d9e6e690 Mon Sep 17 00:00:00 2001 From: ZimM Date: Thu, 26 Feb 2015 05:37:28 +0200 Subject: [PATCH] replace some more List with ExposedList fix some stupidity from previous commit --- spine-csharp/src/Animation.cs | 46 +- spine-csharp/src/AnimationState.cs | 26 +- spine-csharp/src/ExposedList.cs | 1327 +++++++++-------- spine-csharp/src/ExposedList.cs.meta | 8 - spine-csharp/src/Skeleton.cs | 4 +- spine-csharp/src/SkeletonBounds.cs | 2 +- spine-csharp/src/SkeletonData.cs | 48 +- spine-csharp/src/SkeletonJson.cs | 2 +- .../Editor/BoneFollowerInspector.cs | 2 +- .../Editor/SkeletonAnimationInspector.cs | 2 +- .../spine-unity/Editor/SkeletonBaker.cs | 52 +- .../Editor/SkeletonDataAssetInspector.cs | 8 +- .../Editor/SkeletonRendererInspector.cs | 2 +- .../Editor/SpineAttributeDrawers.cs | 18 +- .../Editor/SpineEditorUtilities.cs | 4 +- .../Assets/spine-unity/SkeletonRenderer.cs | 20 +- .../SkeletonUtility/SkeletonUtility.cs | 8 +- 17 files changed, 804 insertions(+), 775 deletions(-) delete mode 100644 spine-csharp/src/ExposedList.cs.meta diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index a31b12c10..65374fccf 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -33,15 +33,15 @@ using System.Collections.Generic; namespace Spine { public class Animation { - internal List timelines; + internal ExposedList timelines; internal float duration; internal String name; public String Name { get { return name; } } - public List Timelines { get { return timelines; } set { timelines = value; } } + public ExposedList Timelines { get { return timelines; } set { timelines = value; } } public float Duration { get { return duration; } set { duration = value; } } - public Animation (String name, List timelines, float duration) { + public Animation (String name, ExposedList timelines, float duration) { if (name == null) throw new ArgumentNullException("name cannot be null."); if (timelines == null) throw new ArgumentNullException("timelines cannot be null."); this.name = name; @@ -52,7 +52,7 @@ namespace Spine { /// Poses the skeleton at the specified time for this animation. /// The last time the animation was applied. /// Any triggered events are added. - public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, List events) { + public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList events) { if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null."); if (loop && duration != 0) { @@ -60,16 +60,16 @@ namespace Spine { lastTime %= duration; } - List timelines = this.timelines; + ExposedList timelines = this.timelines; for (int i = 0, n = timelines.Count; i < n; i++) - timelines[i].Apply(skeleton, lastTime, time, events, 1); + timelines.Items[i].Apply(skeleton, lastTime, time, events, 1); } /// Poses the skeleton at the specified time for this animation mixed with the current pose. /// The last time the animation was applied. /// Any triggered events are added. /// The amount of this animation that affects the current pose. - public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, List events, float alpha) { + public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList events, float alpha) { if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null."); if (loop && duration != 0) { @@ -77,9 +77,9 @@ namespace Spine { lastTime %= duration; } - List timelines = this.timelines; + ExposedList timelines = this.timelines; for (int i = 0, n = timelines.Count; i < n; i++) - timelines[i].Apply(skeleton, lastTime, time, events, alpha); + timelines.Items[i].Apply(skeleton, lastTime, time, events, alpha); } /// After the first and before the last entry. @@ -124,7 +124,7 @@ namespace Spine { public interface Timeline { /// Sets the value(s) for the specified time. /// May be null to not collect fired events. - void Apply (Skeleton skeleton, float lastTime, float time, List events, float alpha); + void Apply (Skeleton skeleton, float lastTime, float time, ExposedList events, float alpha); } /// Base class for frames that use an interpolation bezier curve. @@ -139,7 +139,7 @@ namespace Spine { curves = new float[(frameCount - 1) * BEZIER_SIZE]; } - abstract public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha); + abstract public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha); public void SetLinear (int frameIndex) { curves[frameIndex * BEZIER_SIZE] = LINEAR; @@ -229,7 +229,7 @@ namespace Spine { frames[frameIndex + 1] = angle; } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -292,7 +292,7 @@ namespace Spine { frames[frameIndex + 2] = y; } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -322,7 +322,7 @@ namespace Spine { : base(frameCount) { } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -374,7 +374,7 @@ namespace Spine { frames[frameIndex + 4] = a; } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -438,7 +438,7 @@ namespace Spine { attachmentNames[frameIndex] = attachmentName; } - public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) { if (lastTime > time) Apply(skeleton, lastTime, int.MaxValue, null, 0); @@ -475,7 +475,7 @@ namespace Spine { } /// Fires events for frames > lastTime and <= time. - public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { if (firedEvents == null) return; float[] frames = this.frames; int frameCount = frames.Length; @@ -523,7 +523,7 @@ namespace Spine { drawOrders[frameIndex] = drawOrder; } - public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -538,8 +538,8 @@ namespace Spine { int[] drawOrderToSetupIndex = drawOrders[frameIndex]; if (drawOrderToSetupIndex == null) { 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++) + drawOrder.Add(slots.Items[i]); } else { for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++) drawOrder.Items[i] = slots.Items[drawOrderToSetupIndex[i]]; @@ -570,7 +570,7 @@ namespace Spine { frameVertices[frameIndex] = vertices; } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { Slot slot = skeleton.slots.Items[slotIndex]; if (slot.attachment != attachment) return; @@ -649,7 +649,7 @@ namespace Spine { frames[frameIndex + 2] = bendDirection; } - override public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) return; // Time is before first frame. @@ -693,7 +693,7 @@ namespace Spine { frames[frameIndex + 1] = flip ? 1 : 0; } - public void Apply (Skeleton skeleton, float lastTime, float time, List firedEvents, float alpha) { + public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha) { float[] frames = this.frames; if (time < frames[0]) { if (lastTime > time) Apply(skeleton, lastTime, int.MaxValue, null, 0); diff --git a/spine-csharp/src/AnimationState.cs b/spine-csharp/src/AnimationState.cs index 3a774b330..6262a9375 100644 --- a/spine-csharp/src/AnimationState.cs +++ b/spine-csharp/src/AnimationState.cs @@ -35,8 +35,8 @@ using System.Text; namespace Spine { public class AnimationState { private AnimationStateData data; - private List tracks = new List(); - private List events = new List(); + private ExposedList tracks = new ExposedList(); + private ExposedList events = new ExposedList(); private float timeScale = 1; public AnimationStateData Data { get { return data; } } @@ -60,7 +60,7 @@ namespace Spine { public void Update (float delta) { delta *= timeScale; for (int i = 0; i < tracks.Count; i++) { - TrackEntry current = tracks[i]; + TrackEntry current = tracks.Items[i]; if (current == null) continue; float trackDelta = delta * current.timeScale; @@ -92,10 +92,10 @@ namespace Spine { } public void Apply (Skeleton skeleton) { - List events = this.events; + ExposedList events = this.events; for (int i = 0; i < tracks.Count; i++) { - TrackEntry current = tracks[i]; + TrackEntry current = tracks.Items[i]; if (current == null) continue; events.Clear(); @@ -124,7 +124,7 @@ namespace Spine { } for (int ii = 0, nn = events.Count; ii < nn; ii++) { - Event e = events[ii]; + Event e = events.Items[ii]; current.OnEvent(this, i, e); if (Event != null) Event(this, i, e); } @@ -141,17 +141,17 @@ namespace Spine { public void ClearTrack (int trackIndex) { if (trackIndex >= tracks.Count) return; - TrackEntry current = tracks[trackIndex]; + TrackEntry current = tracks.Items[trackIndex]; if (current == null) return; current.OnEnd(this, trackIndex); if (End != null) End(this, trackIndex); - tracks[trackIndex] = null; + tracks.Items[trackIndex] = null; } private TrackEntry ExpandToIndex (int index) { - if (index < tracks.Count) return tracks[index]; + if (index < tracks.Count) return tracks.Items[index]; while (index >= tracks.Count) tracks.Add(null); return null; @@ -177,7 +177,7 @@ namespace Spine { } } - tracks[index] = entry; + tracks.Items[index] = entry; entry.OnStart(this, index); if (Start != null) Start(this, index); @@ -223,7 +223,7 @@ namespace Spine { last = last.next; last.next = entry; } else - tracks[trackIndex] = entry; + tracks.Items[trackIndex] = entry; if (delay <= 0) { if (last != null) @@ -239,13 +239,13 @@ namespace Spine { /// May be null. public TrackEntry GetCurrent (int trackIndex) { if (trackIndex >= tracks.Count) return null; - return tracks[trackIndex]; + return tracks.Items[trackIndex]; } override public String ToString () { StringBuilder buffer = new StringBuilder(); for (int i = 0, n = tracks.Count; i < n; i++) { - TrackEntry entry = tracks[i]; + TrackEntry entry = tracks.Items[i]; if (entry == null) continue; if (buffer.Length > 0) buffer.Append(", "); buffer.Append(entry.ToString()); diff --git a/spine-csharp/src/ExposedList.cs b/spine-csharp/src/ExposedList.cs index 7d4469bf6..03eaa6c23 100644 --- a/spine-csharp/src/ExposedList.cs +++ b/spine-csharp/src/ExposedList.cs @@ -2,666 +2,701 @@ using System.Collections.Generic; namespace Spine { - /// - /// Represents a strongly typed list of objects that can be accessed by index. Provides methods to search and manipulate lists. - /// - /// The type of elements in the list. - public class ExposedList : IEnumerable { - private const int _defaultCapacity = 4; - private static readonly T[] _emptyArray = new T[0]; - public T[] Items; + /// + /// Represents a strongly typed list of objects that can be accessed by index. Provides methods to search and manipulate lists. + /// + /// The type of elements in the list. + public class ExposedList : IEnumerable { + private const int defaultCapacity = 4; + private static readonly T[] emptyArray = new T[0]; + public T[] Items; - private int _size; + private int size; - /// - /// Initializes a new instance of the class that is empty and has the default initial capacity. - /// - public ExposedList() { - Items = _emptyArray; - } + /// + /// Initializes a new instance of the class that is empty and has the default initial capacity. + /// + public ExposedList() { + Items = emptyArray; + } - /// - /// Initializes a new instance of the class that is empty and has the specified initial capacity. - /// - /// The number of elements that the new list can initially store. - /// - /// is less than 0. - /// - public ExposedList(int capacity) { - if (capacity < 0) { - throw new ArgumentOutOfRangeException("capacity"); - } - Items = new T[capacity]; - } + /// + /// Initializes a new instance of the class that is empty and has the specified initial capacity. + /// + /// The number of elements that the new list can initially store. + /// + /// is less than 0. + /// + public ExposedList(int capacity) { + if (capacity < 0) { + throw new ArgumentOutOfRangeException("capacity"); + } + Items = new T[capacity]; + } - /// - /// Gets or sets the total number of elements the internal data structure can hold without resizing. - /// - /// - /// The number of elements that the can contain before resizing is required. - /// - /// - /// is set to a value that is less than - /// - /// . - /// - /// There is not enough memory available on the system. - public int Capacity { - get { - return Items.Length; - } - set { - if (value == Items.Length) { - return; - } - if (value < _size) { - throw new ArgumentOutOfRangeException("value"); - } - if (value > 0) { - var objArray = new T[value]; - if (_size > 0) { - Array.Copy(Items, 0, objArray, 0, _size); - } - Items = objArray; - } else { - Items = _emptyArray; - } - } - } - - /// - /// Gets the number of elements actually contained in the . - /// - /// - /// The number of elements actually contained in the . - /// - public int Count { - get { - return _size; - } - } - - /// - /// Adds an object to the end of the . - /// - /// - /// The object to be added to the end of the . The value can be null for reference types. - /// - public void Add(T item) { - if (_size == Items.Length) { - EnsureCapacity(_size + 1); - } - Items[_size++] = item; - } - - /// - /// Removes all elements from the . - /// - public void Clear() { - if (_size > 0) { - Array.Clear(Items, 0, _size); - _size = 0; - } - } - - /// - /// Determines whether an element is in the . - /// - /// - /// true if is found in the ; otherwise, false. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - public bool Contains(T item) { - if (item == null) { - for (int index = 0; index < _size; ++index) { - if (Items[index] == null) { - return true; - } - } - return false; - } else { - EqualityComparer @default = EqualityComparer.Default; - for (int index = 0; index < _size; ++index) { - if (@default.Equals(Items[index], item)) { - return true; - } - } - return false; - } - } - - /// - /// Copies the entire to a compatible one-dimensional array, starting at the specified index of the target array. - /// - /// - /// The one-dimensional that is the destination of the elements copied from - /// - /// . The must have zero-based indexing. - /// - /// - /// The zero-based index in at which copying begins. - /// - /// - /// is null. - /// - /// - /// is less than 0. - /// - /// - /// The number of elements in the source is greater than the available space from - /// - /// to the end of the destination . - /// - public void CopyTo(T[] array, int arrayIndex) { - Array.Copy(Items, 0, array, arrayIndex, _size); - } - - /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire - /// - /// . - /// - /// - /// The zero-based index of the first occurrence of within the entire - /// - /// , if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - public int IndexOf(T item) { - return Array.IndexOf(Items, item, 0, _size); - } - - /// - /// Inserts an element into the at the specified index. - /// - /// - /// The zero-based index at which should be inserted. - /// - /// The object to insert. The value can be null for reference types. - /// - /// is less than 0.-or- is greater than - /// - /// . - /// - public void Insert(int index, T item) { - if ((uint) index > (uint) _size) { - throw new ArgumentOutOfRangeException("index"); - } - if (_size == Items.Length) { - EnsureCapacity(_size + 1); - } - if (index < _size) { - Array.Copy(Items, index, Items, index + 1, _size - index); - } - Items[index] = item; - ++_size; - } - - /// - /// Removes the first occurrence of a specific object from the . - /// - /// - /// true if is successfully removed; otherwise, false. This method also returns false if - /// - /// was not found in the . - /// - /// - /// The object to remove from the . The value can be null for reference types. - /// - public bool Remove(T item) { - int index = IndexOf(item); - if (index < 0) { - return false; - } - RemoveAt(index); - return true; - } - - /// - /// Removes the element at the specified index of the . - /// - /// The zero-based index of the element to remove. - /// - /// is less than 0.-or- is equal to or greater than - /// - /// . - /// - public void RemoveAt(int index) { - if ((uint) index >= (uint) _size) { - throw new ArgumentOutOfRangeException(); - } - --_size; - if (index < _size) { - Array.Copy(Items, index + 1, Items, index, _size - index); - } - Items[_size] = default (T); - } - - /// - /// Copies the entire to a compatible one-dimensional array, starting at the beginning of the target array. - /// - /// - /// The one-dimensional that is the destination of the elements copied from - /// - /// . The must have zero-based indexing. - /// - /// - /// is null. - /// - /// - /// The number of elements in the source is greater than the number of elements that the destination - /// - /// can contain. - /// - public void CopyTo(T[] array) { - CopyTo(array, 0); - } - - /// - /// Copies a range of elements from the to a compatible one-dimensional array, starting at the specified index of the target array. - /// - /// - /// The zero-based index in the source at which copying begins. - /// - /// - /// The one-dimensional that is the destination of the elements copied from - /// - /// . The must have zero-based indexing. - /// - /// - /// The zero-based index in at which copying begins. - /// - /// The number of elements to copy. - /// - /// is null. - /// - /// - /// is less than 0.-or- is less than 0.-or- - /// - /// is less than 0. - /// - /// - /// is equal to or greater than the of the source - /// - /// .-or-The number of elements from to the end of the source - /// - /// is greater than the available space from - /// - /// to the end of the destination . - /// - public void CopyTo(int index, T[] array, int arrayIndex, int count) { - if (_size - index < count) { - throw new ArgumentException("Invalid length"); - } - Array.Copy(Items, index, array, arrayIndex, count); - } - - private void EnsureCapacity(int min) { - if (Items.Length >= min) { - return; - } - int num = Items.Length == 0 ? 4 : Items.Length * 2; - if (num < min) { - num = min; - } - Capacity = num; - } - - /// - /// Creates a shallow copy of a range of elements in the source . - /// - /// - /// A shallow copy of a range of elements in the source . - /// - /// - /// The zero-based index at which the range starts. - /// - /// The number of elements in the range. - /// - /// is less than 0.-or- is less than 0. - /// - /// - /// and do not denote a valid range of elements in the - /// - /// . - /// - public ExposedList GetRange(int index, int count) { - if (index < 0 || count < 0) { - throw new ArgumentOutOfRangeException("index || count"); - } - if (_size - index < count) { - throw new ArgumentException("Invalid length"); - } - var list = new ExposedList(count); - Array.Copy(Items, index, list.Items, 0, count); - list._size = count; - return list; - } - - /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the - /// - /// that extends from the specified index to the last element. - /// - /// - /// The zero-based index of the first occurrence of within the range of elements in the - /// - /// that extends from to the last element, if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - /// The zero-based starting index of the search. 0 (zero) is valid in an empty list. - /// - /// is outside the range of valid indexes for the - /// - /// . - /// - public int IndexOf(T item, int index) { - if (index > _size) { - throw new ArgumentOutOfRangeException("index"); - } - return Array.IndexOf(Items, item, index, _size - index); - } - - /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the - /// - /// that starts at the specified index and contains the specified number of elements. - /// - /// - /// The zero-based index of the first occurrence of within the range of elements in the - /// - /// that starts at and contains - /// - /// number of elements, if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - /// The zero-based starting index of the search. 0 (zero) is valid in an empty list. - /// The number of elements in the section to search. - /// - /// is outside the range of valid indexes for the - /// - /// .-or- is less than 0.-or- - /// - /// and do not specify a valid section in the - /// - /// . - /// - public int IndexOf(T item, int index, int count) { - if (index > _size) { - throw new ArgumentOutOfRangeException("index"); - } - if (count < 0 || index > _size - count) { - throw new ArgumentOutOfRangeException("count"); - } - return Array.IndexOf(Items, item, index, count); - } - - /// - /// Searches for the specified object and returns the zero-based index of the last occurrence within the entire - /// - /// . - /// - /// - /// The zero-based index of the last occurrence of within the entire the - /// - /// , if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - public int LastIndexOf(T item) { - return LastIndexOf(item, _size - 1, _size); - } - - /// - /// Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the - /// - /// that extends from the first element to the specified index. - /// - /// - /// The zero-based index of the last occurrence of within the range of elements in the - /// - /// that extends from the first element to , if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - /// The zero-based starting index of the backward search. - /// - /// is outside the range of valid indexes for the - /// - /// . - /// - public int LastIndexOf(T item, int index) { - if (index >= _size) { - throw new ArgumentOutOfRangeException("index"); - } - return LastIndexOf(item, index, index + 1); - } - - /// - /// Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the - /// - /// that contains the specified number of elements and ends at the specified index. - /// - /// - /// The zero-based index of the last occurrence of within the range of elements in the - /// - /// that contains number of elements and ends at - /// - /// , if found; otherwise, –1. - /// - /// - /// The object to locate in the . The value can be null for reference types. - /// - /// The zero-based starting index of the backward search. - /// The number of elements in the section to search. - /// - /// is outside the range of valid indexes for the - /// - /// .-or- is less than 0.-or- - /// - /// and do not specify a valid section in the - /// - /// . - /// - public int LastIndexOf(T item, int index, int count) { - if (_size == 0) { - return -1; - } - if (index < 0 || count < 0) { - throw new ArgumentOutOfRangeException("index || count"); - } - if (index >= _size || count > index + 1) { - throw new ArgumentOutOfRangeException("size || count"); - } - return Array.LastIndexOf(Items, item, index, count); - } - - /// - /// Removes a range of elements from the . - /// - /// The zero-based starting index of the range of elements to remove. - /// The number of elements to remove. - /// - /// is less than 0.-or- is less than 0. - /// - /// - /// and do not denote a valid range of elements in the - /// - /// . - /// - public void RemoveRange(int index, int count) { - if (index < 0 || count < 0) { - throw new ArgumentOutOfRangeException("index || count"); - } - if (_size - index < count) { - throw new ArgumentException("Invalid length"); - } - if (count <= 0) { - return; - } - _size -= count; - if (index < _size) { - Array.Copy(Items, index + count, Items, index, _size - index); - } - Array.Clear(Items, _size, count); - } - - //public void Sort(Comparison comparison) - //{ - // if (comparison == null) - // ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); - // if (this._size <= 0) - // return; - // Array.Sort(this._items, 0, this._size, (IComparer) new Array.FunctorComparer(comparison)); - //} - /// - /// Sorts the elements in the entire using the specified - /// - /// . - /// - /// - /// The to use when comparing elements. - /// - /// - /// is null. - /// - /// - /// The implementation of caused an error during the sort. For example, - /// - /// might not return 0 when comparing an item with itself. - /// - /// - /// Copies the elements of the to a new array. - /// - /// - /// An array containing copies of the elements of the . - /// - public T[] ToArray() { - var objArray = new T[_size]; - Array.Copy(Items, 0, objArray, 0, _size); - return objArray; - } - - // Returns an enumerator for this list with the given - // permission for removal of elements. If modifications made to the list - // while an enumeration is in progress, the MoveNext and - // GetObject methods of the enumerator will throw an exception. - // - public Enumerator GetEnumerator() { - return new Enumerator(this); - } - /// - IEnumerator IEnumerable.GetEnumerator() { - return new Enumerator(this); - } + // Constructs a List, copying the contents of the given collection. The + // size and capacity of the new list will both be equal to the size of the + // given collection. + // + public ExposedList(IEnumerable collection) { + if (collection==null) + throw new ArgumentNullException("collection"); - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { - return new Enumerator(this); - } + ICollection c = collection as ICollection; + if( c != null) { + int count = c.Count; + Items = new T[count]; + c.CopyTo(Items, 0); + size = count; + } + else { + size = 0; + Items = new T[defaultCapacity]; - [Serializable()] - public struct Enumerator : IEnumerator, System.Collections.IEnumerator - { - private readonly ExposedList _list; - private int _index; - private T _current; + using(IEnumerator en = collection.GetEnumerator()) { + while(en.MoveNext()) { + Add(en.Current); + } + } + } + } + + /// + /// Gets or sets the total number of elements the internal data structure can hold without resizing. + /// + /// + /// The number of elements that the can contain before resizing is required. + /// + /// + /// is set to a value that is less than + /// + /// . + /// + /// There is not enough memory available on the system. + public int Capacity { + get { + return Items.Length; + } + set { + if (value == Items.Length) { + return; + } + if (value < size) { + throw new ArgumentOutOfRangeException("value"); + } + if (value > 0) { + var objArray = new T[value]; + if (size > 0) { + Array.Copy(Items, 0, objArray, 0, size); + } + Items = objArray; + } else { + Items = emptyArray; + } + } + } + + /// + /// Gets the number of elements actually contained in the . + /// + /// + /// The number of elements actually contained in the . + /// + public int Count { + get { + return size; + } + } + + /// + /// Adds an object to the end of the . + /// + /// + /// The object to be added to the end of the . The value can be null for reference types. + /// + public void Add(T item) { + if (size == Items.Length) { + EnsureCapacity(size + 1); + } + Items[size++] = item; + } + + /// + /// Removes all elements from the . + /// + public void Clear() { + if (size > 0) { + Array.Clear(Items, 0, size); + size = 0; + } + } + + /// + /// Determines whether an element is in the . + /// + /// + /// true if is found in the ; otherwise, false. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + public bool Contains(T item) { + if (item == null) { + for (int index = 0; index < size; ++index) { + if (Items[index] == null) { + return true; + } + } + return false; + } else { + EqualityComparer @default = EqualityComparer.Default; + for (int index = 0; index < size; ++index) { + if (@default.Equals(Items[index], item)) { + return true; + } + } + return false; + } + } + + /// + /// Copies the entire to a compatible one-dimensional array, starting at the specified index of the target array. + /// + /// + /// The one-dimensional that is the destination of the elements copied from + /// + /// . The must have zero-based indexing. + /// + /// + /// The zero-based index in at which copying begins. + /// + /// + /// is null. + /// + /// + /// is less than 0. + /// + /// + /// The number of elements in the source is greater than the available space from + /// + /// to the end of the destination . + /// + public void CopyTo(T[] array, int arrayIndex) { + Array.Copy(Items, 0, array, arrayIndex, size); + } + + /// + /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire + /// + /// . + /// + /// + /// The zero-based index of the first occurrence of within the entire + /// + /// , if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + public int IndexOf(T item) { + return Array.IndexOf(Items, item, 0, size); + } + + /// + /// Inserts an element into the at the specified index. + /// + /// + /// The zero-based index at which should be inserted. + /// + /// The object to insert. The value can be null for reference types. + /// + /// is less than 0.-or- is greater than + /// + /// . + /// + public void Insert(int index, T item) { + if ((uint) index > (uint) size) { + throw new ArgumentOutOfRangeException("index"); + } + if (size == Items.Length) { + EnsureCapacity(size + 1); + } + if (index < size) { + Array.Copy(Items, index, Items, index + 1, size - index); + } + Items[index] = item; + ++size; + } + + /// + /// Removes the first occurrence of a specific object from the . + /// + /// + /// true if is successfully removed; otherwise, false. This method also returns false if + /// + /// was not found in the . + /// + /// + /// The object to remove from the . The value can be null for reference types. + /// + public bool Remove(T item) { + int index = IndexOf(item); + if (index < 0) { + return false; + } + RemoveAt(index); + return true; + } + + /// + /// Removes the element at the specified index of the . + /// + /// The zero-based index of the element to remove. + /// + /// is less than 0.-or- is equal to or greater than + /// + /// . + /// + public void RemoveAt(int index) { + if ((uint) index >= (uint) size) { + throw new ArgumentOutOfRangeException(); + } + --size; + if (index < size) { + Array.Copy(Items, index + 1, Items, index, size - index); + } + Items[size] = default (T); + } + + /// + /// Copies the entire to a compatible one-dimensional array, starting at the beginning of the target array. + /// + /// + /// The one-dimensional that is the destination of the elements copied from + /// + /// . The must have zero-based indexing. + /// + /// + /// is null. + /// + /// + /// The number of elements in the source is greater than the number of elements that the destination + /// + /// can contain. + /// + public void CopyTo(T[] array) { + CopyTo(array, 0); + } + + /// + /// Copies a range of elements from the to a compatible one-dimensional array, starting at the specified index of the target array. + /// + /// + /// The zero-based index in the source at which copying begins. + /// + /// + /// The one-dimensional that is the destination of the elements copied from + /// + /// . The must have zero-based indexing. + /// + /// + /// The zero-based index in at which copying begins. + /// + /// The number of elements to copy. + /// + /// is null. + /// + /// + /// is less than 0.-or- is less than 0.-or- + /// + /// is less than 0. + /// + /// + /// is equal to or greater than the of the source + /// + /// .-or-The number of elements from to the end of the source + /// + /// is greater than the available space from + /// + /// to the end of the destination . + /// + public void CopyTo(int index, T[] array, int arrayIndex, int count) { + if (size - index < count) { + throw new ArgumentException("Invalid length"); + } + Array.Copy(Items, index, array, arrayIndex, count); + } + + private void EnsureCapacity(int min) { + if (Items.Length >= min) { + return; + } + int num = Items.Length == 0 ? 4 : Items.Length * 2; + if (num < min) { + num = min; + } + Capacity = num; + } + + /// + /// Creates a shallow copy of a range of elements in the source . + /// + /// + /// A shallow copy of a range of elements in the source . + /// + /// + /// The zero-based index at which the range starts. + /// + /// The number of elements in the range. + /// + /// is less than 0.-or- is less than 0. + /// + /// + /// and do not denote a valid range of elements in the + /// + /// . + /// + public ExposedList GetRange(int index, int count) { + if (index < 0 || count < 0) { + throw new ArgumentOutOfRangeException("index || count"); + } + if (size - index < count) { + throw new ArgumentException("Invalid length"); + } + var list = new ExposedList(count); + Array.Copy(Items, index, list.Items, 0, count); + list.size = count; + return list; + } + + /// + /// Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the + /// + /// that extends from the specified index to the last element. + /// + /// + /// The zero-based index of the first occurrence of within the range of elements in the + /// + /// that extends from to the last element, if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + /// The zero-based starting index of the search. 0 (zero) is valid in an empty list. + /// + /// is outside the range of valid indexes for the + /// + /// . + /// + public int IndexOf(T item, int index) { + if (index > size) { + throw new ArgumentOutOfRangeException("index"); + } + return Array.IndexOf(Items, item, index, size - index); + } + + /// + /// Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the + /// + /// that starts at the specified index and contains the specified number of elements. + /// + /// + /// The zero-based index of the first occurrence of within the range of elements in the + /// + /// that starts at and contains + /// + /// number of elements, if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + /// The zero-based starting index of the search. 0 (zero) is valid in an empty list. + /// The number of elements in the section to search. + /// + /// is outside the range of valid indexes for the + /// + /// .-or- is less than 0.-or- + /// + /// and do not specify a valid section in the + /// + /// . + /// + public int IndexOf(T item, int index, int count) { + if (index > size) { + throw new ArgumentOutOfRangeException("index"); + } + if (count < 0 || index > size - count) { + throw new ArgumentOutOfRangeException("count"); + } + return Array.IndexOf(Items, item, index, count); + } + + /// + /// Searches for the specified object and returns the zero-based index of the last occurrence within the entire + /// + /// . + /// + /// + /// The zero-based index of the last occurrence of within the entire the + /// + /// , if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + public int LastIndexOf(T item) { + return LastIndexOf(item, size - 1, size); + } + + /// + /// Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the + /// + /// that extends from the first element to the specified index. + /// + /// + /// The zero-based index of the last occurrence of within the range of elements in the + /// + /// that extends from the first element to , if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + /// The zero-based starting index of the backward search. + /// + /// is outside the range of valid indexes for the + /// + /// . + /// + public int LastIndexOf(T item, int index) { + if (index >= size) { + throw new ArgumentOutOfRangeException("index"); + } + return LastIndexOf(item, index, index + 1); + } + + /// + /// Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the + /// + /// that contains the specified number of elements and ends at the specified index. + /// + /// + /// The zero-based index of the last occurrence of within the range of elements in the + /// + /// that contains number of elements and ends at + /// + /// , if found; otherwise, –1. + /// + /// + /// The object to locate in the . The value can be null for reference types. + /// + /// The zero-based starting index of the backward search. + /// The number of elements in the section to search. + /// + /// is outside the range of valid indexes for the + /// + /// .-or- is less than 0.-or- + /// + /// and do not specify a valid section in the + /// + /// . + /// + public int LastIndexOf(T item, int index, int count) { + if (size == 0) { + return -1; + } + if (index < 0 || count < 0) { + throw new ArgumentOutOfRangeException("index || count"); + } + if (index >= size || count > index + 1) { + throw new ArgumentOutOfRangeException("size || count"); + } + return Array.LastIndexOf(Items, item, index, count); + } + + /// + /// Removes a range of elements from the . + /// + /// The zero-based starting index of the range of elements to remove. + /// The number of elements to remove. + /// + /// is less than 0.-or- is less than 0. + /// + /// + /// and do not denote a valid range of elements in the + /// + /// . + /// + public void RemoveRange(int index, int count) { + if (index < 0 || count < 0) { + throw new ArgumentOutOfRangeException("index || count"); + } + if (size - index < count) { + throw new ArgumentException("Invalid length"); + } + if (count <= 0) { + return; + } + size -= count; + if (index < size) { + Array.Copy(Items, index + count, Items, index, size - index); + } + Array.Clear(Items, size, count); + } + + public void TrimExcess() { + int threshold = (int)(((double) Items.Length) * 0.9); + if( size < threshold ) { + Capacity = size; + } + } + + //public void Sort(Comparison comparison) + //{ + // if (comparison == null) + // ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); + // if (this.size <= 0) + // return; + // Array.Sort(this._items, 0, this.size, (IComparer) new Array.FunctorComparer(comparison)); + //} + + /// + /// Sorts the elements in the entire using the specified + /// + /// . + /// + /// + /// The to use when comparing elements. + /// + /// + /// is null. + /// + /// + /// The implementation of caused an error during the sort. For example, + /// + /// might not return 0 when comparing an item with itself. + /// + /// + /// Copies the elements of the to a new array. + /// + /// + /// An array containing copies of the elements of the . + /// + public T[] ToArray() { + var objArray = new T[size]; + Array.Copy(Items, 0, objArray, 0, size); + return objArray; + } + + // Returns an enumerator for this list with the given + // permission for removal of elements. If modifications made to the list + // while an enumeration is in progress, the MoveNext and + // GetObject methods of the enumerator will throw an exception. + // + public Enumerator GetEnumerator() { + return new Enumerator(this); + } + + IEnumerator IEnumerable.GetEnumerator() { + return new Enumerator(this); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { + return new Enumerator(this); + } + + [Serializable()] + public struct Enumerator : IEnumerator, System.Collections.IEnumerator + { + private readonly ExposedList list; + private int index; + private T current; - internal Enumerator(ExposedList list) { - _list = list; - _index = 0; - _current = default(T); - } + internal Enumerator(ExposedList list) { + this.list = list; + index = 0; + current = default(T); + } - public void Dispose() { - } + public void Dispose() { + } - public bool MoveNext() { - ExposedList localList = _list; + public bool MoveNext() { + ExposedList localList = list; - if (((uint)_index < (uint)localList._size)) { - _current = localList.Items[_index]; - _index++; - return true; - } - return MoveNextRare(); - } + if (((uint)index < (uint)localList.size)) { + current = localList.Items[index]; + index++; + return true; + } + return MoveNextRare(); + } - private bool MoveNextRare() - { - _index = _list._size + 1; - _current = default(T); - return false; - } + private bool MoveNextRare() + { + index = list.size + 1; + current = default(T); + return false; + } - public T Current { - get { - return _current; - } - } + public T Current { + get { + return current; + } + } - Object System.Collections.IEnumerator.Current { - get { - if( _index == 0 || _index == _list._size + 1) - throw new InvalidOperationException(); - return Current; - } - } + Object System.Collections.IEnumerator.Current { + get { + if( index == 0 || index == list.size + 1) + throw new InvalidOperationException(); + return Current; + } + } - void System.Collections.IEnumerator.Reset() { - _index = 0; - _current = default(T); - } + void System.Collections.IEnumerator.Reset() { + index = 0; + current = default(T); + } - } - } + } + } } \ No newline at end of file diff --git a/spine-csharp/src/ExposedList.cs.meta b/spine-csharp/src/ExposedList.cs.meta deleted file mode 100644 index e12f21463..000000000 --- a/spine-csharp/src/ExposedList.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 540cf6a03c85e284e83831880e3f25a8 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index 56f1c421b..c8c26df69 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -178,8 +178,8 @@ namespace Spine { public void SetSlotsToSetupPose () { ExposedList slots = this.slots; 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++) + 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/SkeletonBounds.cs b/spine-csharp/src/SkeletonBounds.cs index 0c1a146f2..9fe27ae9d 100644 --- a/spine-csharp/src/SkeletonBounds.cs +++ b/spine-csharp/src/SkeletonBounds.cs @@ -57,7 +57,7 @@ namespace Spine { int slotCount = slots.Count; boundingBoxes.Clear(); - for (int i = 0, n = polygons.Count; i < n; i++) + for (int i = 0, n = polygons.Count; i < n; i++) polygonPool.Add(polygons.Items[n]); polygons.Clear(); diff --git a/spine-csharp/src/SkeletonData.cs b/spine-csharp/src/SkeletonData.cs index 48b500363..4e62dfed4 100644 --- a/spine-csharp/src/SkeletonData.cs +++ b/spine-csharp/src/SkeletonData.cs @@ -34,25 +34,25 @@ using System.Collections.Generic; namespace Spine { public class SkeletonData { internal String name; - internal List bones = new List(); - internal List slots = new List(); - internal List skins = new List(); + internal ExposedList bones = new ExposedList(); + internal ExposedList slots = new ExposedList(); + internal ExposedList skins = new ExposedList(); internal Skin defaultSkin; - internal List events = new List(); - internal List animations = new List(); - internal List ikConstraints = new List(); + internal ExposedList events = new ExposedList(); + internal ExposedList animations = new ExposedList(); + internal ExposedList ikConstraints = new ExposedList(); internal float width, height; internal String version, hash; public String Name { get { return name; } set { name = value; } } - public List Bones { get { return bones; } } // Ordered parents first. - public List Slots { get { return slots; } } // Setup pose draw order. - public List Skins { get { return skins; } set { skins = value; } } + public ExposedList Bones { get { return bones; } } // Ordered parents first. + public ExposedList Slots { get { return slots; } } // Setup pose draw order. + public ExposedList Skins { get { return skins; } set { skins = value; } } /// May be null. public Skin DefaultSkin { get { return defaultSkin; } set { defaultSkin = value; } } - public List Events { get { return events; } set { events = value; } } - public List Animations { get { return animations; } set { animations = value; } } - public List IkConstraints { get { return ikConstraints; } set { ikConstraints = value; } } + public ExposedList Events { get { return events; } set { events = value; } } + public ExposedList Animations { get { return animations; } set { animations = value; } } + public ExposedList IkConstraints { get { return ikConstraints; } set { ikConstraints = value; } } public float Width { get { return width; } set { width = value; } } public float Height { get { return height; } set { height = value; } } /// The Spine version used to export this data. @@ -64,9 +64,9 @@ namespace Spine { /// May be null. public BoneData FindBone (String boneName) { if (boneName == null) throw new ArgumentNullException("boneName cannot be null."); - List bones = this.bones; + ExposedList bones = this.bones; for (int i = 0, n = bones.Count; i < n; i++) { - BoneData bone = bones[i]; + BoneData bone = bones.Items[i]; if (bone.name == boneName) return bone; } return null; @@ -75,9 +75,9 @@ namespace Spine { /// -1 if the bone was not found. public int FindBoneIndex (String boneName) { if (boneName == null) throw new ArgumentNullException("boneName cannot be null."); - List bones = this.bones; + ExposedList bones = this.bones; for (int i = 0, n = bones.Count; i < n; i++) - if (bones[i].name == boneName) return i; + if (bones.Items[i].name == boneName) return i; return -1; } @@ -86,9 +86,9 @@ namespace Spine { /// May be null. public SlotData FindSlot (String slotName) { if (slotName == null) throw new ArgumentNullException("slotName cannot be null."); - List slots = this.slots; + ExposedList slots = this.slots; for (int i = 0, n = slots.Count; i < n; i++) { - SlotData slot = slots[i]; + SlotData slot = slots.Items[i]; if (slot.name == slotName) return slot; } return null; @@ -97,9 +97,9 @@ namespace Spine { /// -1 if the bone was not found. public int FindSlotIndex (String slotName) { if (slotName == null) throw new ArgumentNullException("slotName cannot be null."); - List slots = this.slots; + ExposedList slots = this.slots; for (int i = 0, n = slots.Count; i < n; i++) - if (slots[i].name == slotName) return i; + if (slots.Items[i].name == slotName) return i; return -1; } @@ -128,9 +128,9 @@ namespace Spine { /// May be null. public Animation FindAnimation (String animationName) { if (animationName == null) throw new ArgumentNullException("animationName cannot be null."); - List animations = this.animations; + ExposedList animations = this.animations; for (int i = 0, n = animations.Count; i < n; i++) { - Animation animation = animations[i]; + Animation animation = animations.Items[i]; if (animation.name == animationName) return animation; } return null; @@ -141,9 +141,9 @@ namespace Spine { /// May be null. public IkConstraintData FindIkConstraint (String ikConstraintName) { if (ikConstraintName == null) throw new ArgumentNullException("ikConstraintName cannot be null."); - List ikConstraints = this.ikConstraints; + ExposedList ikConstraints = this.ikConstraints; for (int i = 0, n = ikConstraints.Count; i < n; i++) { - IkConstraintData ikConstraint = ikConstraints[i]; + IkConstraintData ikConstraint = ikConstraints.Items[i]; if (ikConstraint.name == ikConstraintName) return ikConstraint; } return null; diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index b83f88a82..0dea14062 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -376,7 +376,7 @@ namespace Spine { } private void ReadAnimation (String name, Dictionary map, SkeletonData skeletonData) { - var timelines = new List(); + var timelines = new ExposedList(); float duration = 0; float scale = Scale; diff --git a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs index 943a98715..e59610626 100644 --- a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs @@ -80,7 +80,7 @@ public class BoneFollowerInspector : Editor { bones[0] = ""; for (int i = 0; i < bones.Length - 1; i++) - bones[i + 1] = component.skeletonRenderer.skeleton.Data.Bones[i].Name; + bones[i + 1] = component.skeletonRenderer.skeleton.Data.Bones.Items[i].Name; Array.Sort(bones); int boneIndex = Math.Max(0, Array.IndexOf(bones, boneName.stringValue)); diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs index f338626b2..27a590b19 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs @@ -74,7 +74,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector { animations[0] = ""; int animationIndex = 0; for (int i = 0; i < animations.Length - 1; i++) { - String name = component.skeleton.Data.Animations[i].Name; + String name = component.skeleton.Data.Animations.Items[i].Name; animations[i + 1] = name; if (name == animationName.stringValue) animationIndex = i + 1; diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs index 4fa1a0161..db2ba8420 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs @@ -76,7 +76,7 @@ public static class SkeletonBaker { /// const float bakeIncrement = 1 / 60f; - public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, List skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver) { + public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, ExposedList skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver) { if (skeletonDataAsset == null || skeletonDataAsset.GetSkeletonData(true) == null) { Debug.LogError("Could not export Spine Skeleton because SkeletonDataAsset is null or invalid!"); return; @@ -135,7 +135,7 @@ public static class SkeletonBaker { for (int s = 0; s < skeletonData.Slots.Count; s++) { List attachmentNames = new List(); for (int i = 0; i < skinCount; i++) { - var skin = skins[i]; + var skin = skins.Items[i]; List temp = new List(); skin.FindNamesForSlot(s, temp); foreach (string str in temp) { @@ -216,7 +216,7 @@ public static class SkeletonBaker { //create bones for (int i = 0; i < skeletonData.Bones.Count; i++) { - var boneData = skeletonData.Bones[i]; + var boneData = skeletonData.Bones.Items[i]; Transform boneTransform = new GameObject(boneData.Name).transform; boneTransform.parent = prefabRoot.transform; boneTable.Add(boneTransform.name, boneTransform); @@ -225,7 +225,7 @@ public static class SkeletonBaker { for (int i = 0; i < skeletonData.Bones.Count; i++) { - var boneData = skeletonData.Bones[i]; + var boneData = skeletonData.Bones.Items[i]; Transform boneTransform = boneTable[boneData.Name]; Transform parentTransform = null; if (i > 0) @@ -246,7 +246,7 @@ public static class SkeletonBaker { //create slots and attachments for (int i = 0; i < skeletonData.Slots.Count; i++) { - var slotData = skeletonData.Slots[i]; + var slotData = skeletonData.Slots.Items[i]; Transform slotTransform = new GameObject(slotData.Name).transform; slotTransform.parent = prefabRoot.transform; slotTable.Add(slotData.Name, slotTransform); @@ -807,26 +807,26 @@ public static class SkeletonBaker { List ignoreRotateTimelineIndexes = new List(); - //if (bakeIK) { - // foreach (IkConstraint i in skeleton.IkConstraints) { - // foreach (Bone b in i.Bones) { - // int index = skeleton.FindBoneIndex(b.Data.Name); - // ignoreRotateTimelineIndexes.Add(index); - // BakeBone(b, animation, clip); - // } - // } - //} + if (bakeIK) { + foreach (IkConstraint i in skeleton.IkConstraints) { + foreach (Bone b in i.Bones) { + int index = skeleton.FindBoneIndex(b.Data.Name); + ignoreRotateTimelineIndexes.Add(index); + BakeBone(b, animation, clip); + } + } + } - //foreach (Bone b in skeleton.Bones) { - // if (b.Data.InheritRotation == false) { - // int index = skeleton.FindBoneIndex(b.Data.Name); + foreach (Bone b in skeleton.Bones) { + if (b.Data.InheritRotation == false) { + int index = skeleton.FindBoneIndex(b.Data.Name); - // if (ignoreRotateTimelineIndexes.Contains(index) == false) { - // ignoreRotateTimelineIndexes.Add(index); - // BakeBone(b, animation, clip); - // } - // } - //} + if (ignoreRotateTimelineIndexes.Contains(index) == false) { + ignoreRotateTimelineIndexes.Add(index); + BakeBone(b, animation, clip); + } + } + } foreach (Timeline t in timelines) { skeleton.SetToSetupPose(); @@ -1061,7 +1061,7 @@ public static class SkeletonBaker { } static void ParseTranslateTimeline (Skeleton skeleton, TranslateTimeline timeline, AnimationClip clip) { - var boneData = skeleton.Data.Bones[timeline.BoneIndex]; + var boneData = skeleton.Data.Bones.Items[timeline.BoneIndex]; var bone = skeleton.Bones.Items[timeline.BoneIndex]; AnimationCurve xCurve = new AnimationCurve(); @@ -1207,7 +1207,7 @@ public static class SkeletonBaker { } static void ParseScaleTimeline (Skeleton skeleton, ScaleTimeline timeline, AnimationClip clip) { - var boneData = skeleton.Data.Bones[timeline.BoneIndex]; + var boneData = skeleton.Data.Bones.Items[timeline.BoneIndex]; var bone = skeleton.Bones.Items[timeline.BoneIndex]; AnimationCurve xCurve = new AnimationCurve(); @@ -1340,7 +1340,7 @@ public static class SkeletonBaker { } static void ParseRotateTimeline (Skeleton skeleton, RotateTimeline timeline, AnimationClip clip) { - var boneData = skeleton.Data.Bones[timeline.BoneIndex]; + var boneData = skeleton.Data.Bones.Items[timeline.BoneIndex]; var bone = skeleton.Bones.Items[timeline.BoneIndex]; AnimationCurve curve = new AnimationCurve(); diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs index 81d2c37a0..ed7c90e05 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -186,7 +186,7 @@ public class SkeletonDataAssetInspector : Editor { Skin bakeSkin = m_skeletonAnimation.skeleton.Skin; if (bakeSkin == null) { skinName = "Default"; - bakeSkin = m_skeletonData.Skins[0]; + bakeSkin = m_skeletonData.Skins.Items[0]; } else skinName = m_skeletonAnimation.skeleton.Skin.Name; @@ -195,7 +195,7 @@ public class SkeletonDataAssetInspector : Editor { try { GUILayout.BeginVertical(); if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250))) - SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new List(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions); + SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50)); @@ -259,7 +259,7 @@ public class SkeletonDataAssetInspector : Editor { // Animation names String[] animations = new String[m_skeletonData.Animations.Count]; for (int i = 0; i < animations.Length; i++) - animations[i] = m_skeletonData.Animations[i].Name; + animations[i] = m_skeletonData.Animations.Items[i].Name; for (int i = 0; i < fromAnimation.arraySize; i++) { SerializedProperty from = fromAnimation.GetArrayElementAtIndex(i); @@ -350,7 +350,7 @@ public class SkeletonDataAssetInspector : Editor { List slotAttachments = new List(); List slotAttachmentNames = new List(); List defaultSkinAttachmentNames = new List(); - var defaultSkin = m_skeletonData.Skins[0]; + var defaultSkin = m_skeletonData.Skins.Items[0]; Skin skin = m_skeletonAnimation.skeleton.Skin; if (skin == null) { skin = defaultSkin; diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs index e2f8ff52f..bb8961aac 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs @@ -78,7 +78,7 @@ public class SkeletonRendererInspector : Editor { String[] skins = new String[component.skeleton.Data.Skins.Count]; int skinIndex = 0; for (int i = 0; i < skins.Length; i++) { - String name = component.skeleton.Data.Skins[i].Name; + String name = component.skeleton.Data.Skins.Items[i].Name; skins[i] = name; if (name == initialSkinName.stringValue) skinIndex = i; diff --git a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs index 9d9e3b3d2..703b54bad 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs @@ -113,7 +113,7 @@ public class SpineSlotDrawer : PropertyDrawer { menu.AddSeparator(""); for (int i = 0; i < data.Slots.Count; i++) { - string name = data.Slots[i].Name; + string name = data.Slots.Items[i].Name; if (name.StartsWith(attrib.startsWith)) menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); } @@ -191,7 +191,7 @@ public class SpineSkinDrawer : PropertyDrawer { menu.AddSeparator(""); for (int i = 0; i < data.Skins.Count; i++) { - string name = data.Skins[i].Name; + string name = data.Skins.Items[i].Name; if (name.StartsWith(attrib.startsWith)) menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); } @@ -331,7 +331,7 @@ public class SpineAnimationDrawer : PropertyDrawer { var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations; for (int i = 0; i < animations.Count; i++) { - string name = animations[i].Name; + string name = animations.Items[i].Name; if (name.StartsWith(attrib.startsWith)) menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); } @@ -417,7 +417,7 @@ public class SpineAttachmentDrawer : PropertyDrawer { if (skeletonRenderer.skeleton.Skin != null) { validSkins.Add(skeletonRenderer.skeleton.Skin); } else { - validSkins.Add(data.Skins[0]); + validSkins.Add(data.Skins.Items[0]); } } else { foreach (Skin skin in data.Skins) { @@ -441,7 +441,7 @@ public class SpineAttachmentDrawer : PropertyDrawer { menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property)); menu.AddSeparator(""); - Skin defaultSkin = data.Skins[0]; + Skin defaultSkin = data.Skins.Items[0]; SerializedProperty slotProperty = property.serializedObject.FindProperty(attrib.slotField); string slotMatch = ""; @@ -458,7 +458,7 @@ public class SpineAttachmentDrawer : PropertyDrawer { prefix = skinPrefix; for (int i = 0; i < data.Slots.Count; i++) { - if (slotMatch.Length > 0 && data.Slots[i].Name.ToLower().Contains(slotMatch) == false) + if (slotMatch.Length > 0 && data.Slots.Items[i].Name.ToLower().Contains(slotMatch) == false) continue; attachmentNames.Clear(); @@ -474,11 +474,11 @@ public class SpineAttachmentDrawer : PropertyDrawer { for (int a = 0; a < attachmentNames.Count; a++) { string attachmentPath = attachmentNames[a]; - string menuPath = prefix + data.Slots[i].Name + "/" + attachmentPath; + string menuPath = prefix + data.Slots.Items[i].Name + "/" + attachmentPath; string name = attachmentNames[a]; if (attrib.returnAttachmentPath) - name = skin.Name + "/" + data.Slots[i].Name + "/" + attachmentPath; + name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath; if (attrib.placeholdersOnly && placeholderNames.Contains(attachmentPath) == false) { menu.AddDisabledItem(new GUIContent(menuPath)); @@ -565,7 +565,7 @@ public class SpineBoneDrawer : PropertyDrawer { menu.AddSeparator(""); for (int i = 0; i < data.Bones.Count; i++) { - string name = data.Bones[i].Name; + string name = data.Bones.Items[i].Name; if (name.StartsWith(attrib.startsWith)) menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); } diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index c1ebb804f..93936e985 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -779,7 +779,7 @@ public class SpineEditorUtilities : AssetPostprocessor { skin = data.DefaultSkin; if (skin == null) - skin = data.Skins[0]; + skin = data.Skins.Items[0]; anim.Reset(); @@ -865,7 +865,7 @@ public class SpineEditorUtilities : AssetPostprocessor { skin = data.DefaultSkin; if (skin == null) - skin = data.Skins[0]; + skin = data.Skins.Items[0]; anim.Reset(); diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index 450e7b50b..524e9ef12 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -190,18 +190,20 @@ public class SkeletonRenderer : MonoBehaviour { } else { if (!renderMeshes) continue; - if (attachment is MeshAttachment) { - MeshAttachment meshAttachment = (MeshAttachment)attachment; + MeshAttachment meshAttachment = attachment as MeshAttachment; + if (meshAttachment != null) { rendererObject = meshAttachment.RendererObject; attachmentVertexCount = meshAttachment.vertices.Length >> 1; attachmentTriangleCount = meshAttachment.triangles.Length; - } else if (attachment is SkinnedMeshAttachment) { - SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; - rendererObject = meshAttachment.RendererObject; - attachmentVertexCount = meshAttachment.uvs.Length >> 1; - attachmentTriangleCount = meshAttachment.triangles.Length; - } else - continue; + } else { + SkinnedMeshAttachment skinnedMeshAttachment = attachment as SkinnedMeshAttachment; + if (skinnedMeshAttachment != null) { + rendererObject = skinnedMeshAttachment.RendererObject; + attachmentVertexCount = skinnedMeshAttachment.uvs.Length >> 1; + attachmentTriangleCount = skinnedMeshAttachment.triangles.Length; + } else + continue; + } } // Populate submesh when material changes. diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs index 37e84e884..5183f42f0 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs @@ -170,8 +170,8 @@ public class SkeletonUtility : MonoBehaviour { if (boneRoot != null) { List constraintTargetNames = new List(); - ExposedList ikConstraints = skeletonRenderer.skeleton.IkConstraints; - for (int i = 0, n = ikConstraints.Count; i < n; i++) + ExposedList ikConstraints = skeletonRenderer.skeleton.IkConstraints; + for (int i = 0, n = ikConstraints.Count; i < n; i++) constraintTargetNames.Add(ikConstraints.Items[n].Target.Data.Name); foreach (var b in utilityBones) { @@ -290,8 +290,8 @@ public class SkeletonUtility : MonoBehaviour { GameObject go = SpawnBone(bone, parent, mode, pos, rot, sca); ExposedList childrenBones = bone.Children; - for (int i = 0, n = childrenBones.Count; i < n; i++) { - Bone child = childrenBones.Items[i]; + for (int i = 0, n = childrenBones.Count; i < n; i++) { + Bone child = childrenBones.Items[i]; SpawnBoneRecursively(child, go.transform, mode, pos, rot, sca); }