replace some more List<T> with ExposedList<T>

fix some stupidity from previous commit
This commit is contained in:
ZimM 2015-02-26 05:37:28 +02:00
parent 9ae48c2aac
commit 0635c19fef
17 changed files with 804 additions and 775 deletions

View File

@ -33,15 +33,15 @@ using System.Collections.Generic;
namespace Spine {
public class Animation {
internal List<Timeline> timelines;
internal ExposedList<Timeline> timelines;
internal float duration;
internal String name;
public String Name { get { return name; } }
public List<Timeline> Timelines { get { return timelines; } set { timelines = value; } }
public ExposedList<Timeline> Timelines { get { return timelines; } set { timelines = value; } }
public float Duration { get { return duration; } set { duration = value; } }
public Animation (String name, List<Timeline> timelines, float duration) {
public Animation (String name, ExposedList<Timeline> 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 {
/// <summary>Poses the skeleton at the specified time for this animation.</summary>
/// <param name="lastTime">The last time the animation was applied.</param>
/// <param name="events">Any triggered events are added.</param>
public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events) {
public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList<Event> events) {
if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
if (loop && duration != 0) {
@ -60,16 +60,16 @@ namespace Spine {
lastTime %= duration;
}
List<Timeline> timelines = this.timelines;
ExposedList<Timeline> 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);
}
/// <summary>Poses the skeleton at the specified time for this animation mixed with the current pose.</summary>
/// <param name="lastTime">The last time the animation was applied.</param>
/// <param name="events">Any triggered events are added.</param>
/// <param name="alpha">The amount of this animation that affects the current pose.</param>
public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events, float alpha) {
public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList<Event> 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<Timeline> timelines = this.timelines;
ExposedList<Timeline> 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);
}
/// <param name="target">After the first and before the last entry.</param>
@ -124,7 +124,7 @@ namespace Spine {
public interface Timeline {
/// <summary>Sets the value(s) for the specified time.</summary>
/// <param name="events">May be null to not collect fired events.</param>
void Apply (Skeleton skeleton, float lastTime, float time, List<Event> events, float alpha);
void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> events, float alpha);
}
/// <summary>Base class for frames that use an interpolation bezier curve.</summary>
@ -139,7 +139,7 @@ namespace Spine {
curves = new float[(frameCount - 1) * BEZIER_SIZE];
}
abstract public void Apply (Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha);
abstract public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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 {
}
/// <summary>Fires events for frames > lastTime and <= time.</summary>
public void Apply (Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha) {
public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> firedEvents, float alpha) {
float[] frames = this.frames;
if (time < frames[0]) return; // Time is before first frame.
@ -570,7 +570,7 @@ namespace Spine {
frameVertices[frameIndex] = vertices;
}
override public void Apply (Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> 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<Event> firedEvents, float alpha) {
public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> firedEvents, float alpha) {
float[] frames = this.frames;
if (time < frames[0]) {
if (lastTime > time) Apply(skeleton, lastTime, int.MaxValue, null, 0);

View File

@ -35,8 +35,8 @@ using System.Text;
namespace Spine {
public class AnimationState {
private AnimationStateData data;
private List<TrackEntry> tracks = new List<TrackEntry>();
private List<Event> events = new List<Event>();
private ExposedList<TrackEntry> tracks = new ExposedList<TrackEntry>();
private ExposedList<Event> events = new ExposedList<Event>();
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<Event> events = this.events;
ExposedList<Event> 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 {
/// <returns>May be null.</returns>
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());

View File

@ -7,17 +7,17 @@ namespace Spine {
/// </summary>
/// <typeparam name="T">The type of elements in the list.</typeparam>
public class ExposedList<T> : IEnumerable<T> {
private const int _defaultCapacity = 4;
private static readonly T[] _emptyArray = new T[0];
private const int defaultCapacity = 4;
private static readonly T[] emptyArray = new T[0];
public T[] Items;
private int _size;
private int size;
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Collections.Generic.List`1" /> class that is empty and has the default initial capacity.
/// </summary>
public ExposedList() {
Items = _emptyArray;
Items = emptyArray;
}
/// <summary>
@ -34,6 +34,34 @@ namespace Spine {
Items = new T[capacity];
}
// 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<T> collection) {
if (collection==null)
throw new ArgumentNullException("collection");
ICollection<T> c = collection as ICollection<T>;
if( c != null) {
int count = c.Count;
Items = new T[count];
c.CopyTo(Items, 0);
size = count;
}
else {
size = 0;
Items = new T[defaultCapacity];
using(IEnumerator<T> en = collection.GetEnumerator()) {
while(en.MoveNext()) {
Add(en.Current);
}
}
}
}
/// <summary>
/// Gets or sets the total number of elements the internal data structure can hold without resizing.
/// </summary>
@ -55,17 +83,17 @@ namespace Spine {
if (value == Items.Length) {
return;
}
if (value < _size) {
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);
if (size > 0) {
Array.Copy(Items, 0, objArray, 0, size);
}
Items = objArray;
} else {
Items = _emptyArray;
Items = emptyArray;
}
}
}
@ -78,7 +106,7 @@ namespace Spine {
/// </returns>
public int Count {
get {
return _size;
return size;
}
}
@ -89,19 +117,19 @@ namespace Spine {
/// The object to be added to the end of the <see cref="T:System.Collections.Generic.List`1" />. The value can be null for reference types.
/// </param>
public void Add(T item) {
if (_size == Items.Length) {
EnsureCapacity(_size + 1);
if (size == Items.Length) {
EnsureCapacity(size + 1);
}
Items[_size++] = item;
Items[size++] = item;
}
/// <summary>
/// Removes all elements from the <see cref="T:System.Collections.Generic.List`1" />.
/// </summary>
public void Clear() {
if (_size > 0) {
Array.Clear(Items, 0, _size);
_size = 0;
if (size > 0) {
Array.Clear(Items, 0, size);
size = 0;
}
}
@ -116,7 +144,7 @@ namespace Spine {
/// </param>
public bool Contains(T item) {
if (item == null) {
for (int index = 0; index < _size; ++index) {
for (int index = 0; index < size; ++index) {
if (Items[index] == null) {
return true;
}
@ -124,7 +152,7 @@ namespace Spine {
return false;
} else {
EqualityComparer<T> @default = EqualityComparer<T>.Default;
for (int index = 0; index < _size; ++index) {
for (int index = 0; index < size; ++index) {
if (@default.Equals(Items[index], item)) {
return true;
}
@ -158,7 +186,7 @@ namespace Spine {
/// to the end of the destination <paramref name="array" />.
/// </exception>
public void CopyTo(T[] array, int arrayIndex) {
Array.Copy(Items, 0, array, arrayIndex, _size);
Array.Copy(Items, 0, array, arrayIndex, size);
}
/// <summary>
@ -177,7 +205,7 @@ namespace Spine {
/// The object to locate in the <see cref="T:System.Collections.Generic.List`1" />. The value can be null for reference types.
/// </param>
public int IndexOf(T item) {
return Array.IndexOf(Items, item, 0, _size);
return Array.IndexOf(Items, item, 0, size);
}
/// <summary>
@ -194,17 +222,17 @@ namespace Spine {
/// .
/// </exception>
public void Insert(int index, T item) {
if ((uint) index > (uint) _size) {
if ((uint) index > (uint) size) {
throw new ArgumentOutOfRangeException("index");
}
if (_size == Items.Length) {
EnsureCapacity(_size + 1);
if (size == Items.Length) {
EnsureCapacity(size + 1);
}
if (index < _size) {
Array.Copy(Items, index, Items, index + 1, _size - index);
if (index < size) {
Array.Copy(Items, index, Items, index + 1, size - index);
}
Items[index] = item;
++_size;
++size;
}
/// <summary>
@ -239,14 +267,14 @@ namespace Spine {
/// .
/// </exception>
public void RemoveAt(int index) {
if ((uint) index >= (uint) _size) {
if ((uint) index >= (uint) size) {
throw new ArgumentOutOfRangeException();
}
--_size;
if (index < _size) {
Array.Copy(Items, index + 1, Items, index, _size - index);
--size;
if (index < size) {
Array.Copy(Items, index + 1, Items, index, size - index);
}
Items[_size] = default (T);
Items[size] = default (T);
}
/// <summary>
@ -309,7 +337,7 @@ namespace Spine {
/// to the end of the destination <paramref name="array" />.
/// </exception>
public void CopyTo(int index, T[] array, int arrayIndex, int count) {
if (_size - index < count) {
if (size - index < count) {
throw new ArgumentException("Invalid length");
}
Array.Copy(Items, index, array, arrayIndex, count);
@ -349,12 +377,12 @@ namespace Spine {
if (index < 0 || count < 0) {
throw new ArgumentOutOfRangeException("index || count");
}
if (_size - index < count) {
if (size - index < count) {
throw new ArgumentException("Invalid length");
}
var list = new ExposedList<T>(count);
Array.Copy(Items, index, list.Items, 0, count);
list._size = count;
list.size = count;
return list;
}
@ -381,10 +409,10 @@ namespace Spine {
/// .
/// </exception>
public int IndexOf(T item, int index) {
if (index > _size) {
if (index > size) {
throw new ArgumentOutOfRangeException("index");
}
return Array.IndexOf(Items, item, index, _size - index);
return Array.IndexOf(Items, item, index, size - index);
}
/// <summary>
@ -420,10 +448,10 @@ namespace Spine {
/// .
/// </exception>
public int IndexOf(T item, int index, int count) {
if (index > _size) {
if (index > size) {
throw new ArgumentOutOfRangeException("index");
}
if (count < 0 || index > _size - count) {
if (count < 0 || index > size - count) {
throw new ArgumentOutOfRangeException("count");
}
return Array.IndexOf(Items, item, index, count);
@ -445,7 +473,7 @@ namespace Spine {
/// The object to locate in the <see cref="T:System.Collections.Generic.List`1" />. The value can be null for reference types.
/// </param>
public int LastIndexOf(T item) {
return LastIndexOf(item, _size - 1, _size);
return LastIndexOf(item, size - 1, size);
}
/// <summary>
@ -471,7 +499,7 @@ namespace Spine {
/// .
/// </exception>
public int LastIndexOf(T item, int index) {
if (index >= _size) {
if (index >= size) {
throw new ArgumentOutOfRangeException("index");
}
return LastIndexOf(item, index, index + 1);
@ -510,13 +538,13 @@ namespace Spine {
/// .
/// </exception>
public int LastIndexOf(T item, int index, int count) {
if (_size == 0) {
if (size == 0) {
return -1;
}
if (index < 0 || count < 0) {
throw new ArgumentOutOfRangeException("index || count");
}
if (index >= _size || count > index + 1) {
if (index >= size || count > index + 1) {
throw new ArgumentOutOfRangeException("size || count");
}
return Array.LastIndexOf(Items, item, index, count);
@ -540,27 +568,35 @@ namespace Spine {
if (index < 0 || count < 0) {
throw new ArgumentOutOfRangeException("index || count");
}
if (_size - 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);
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;
}
Array.Clear(Items, _size, count);
}
//public void Sort(Comparison<T> comparison)
//{
// if (comparison == null)
// ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
// if (this._size <= 0)
// if (this.size <= 0)
// return;
// Array.Sort<T>(this._items, 0, this._size, (IComparer<T>) new Array.FunctorComparer<T>(comparison));
// Array.Sort<T>(this._items, 0, this.size, (IComparer<T>) new Array.FunctorComparer<T>(comparison));
//}
/// <summary>
/// Sorts the elements in the entire <see cref="T:System.Collections.Generic.List`1" /> using the specified
/// <see
@ -586,8 +622,8 @@ namespace Spine {
/// An array containing copies of the elements of the <see cref="T:System.Collections.Generic.List`1" />.
/// </returns>
public T[] ToArray() {
var objArray = new T[_size];
Array.Copy(Items, 0, objArray, 0, _size);
var objArray = new T[size];
Array.Copy(Items, 0, objArray, 0, size);
return objArray;
}
@ -600,7 +636,6 @@ namespace Spine {
return new Enumerator(this);
}
/// <internalonly/>
IEnumerator<T> IEnumerable<T>.GetEnumerator() {
return new Enumerator(this);
}
@ -612,25 +647,25 @@ namespace Spine {
[Serializable()]
public struct Enumerator : IEnumerator<T>, System.Collections.IEnumerator
{
private readonly ExposedList<T> _list;
private int _index;
private T _current;
private readonly ExposedList<T> list;
private int index;
private T current;
internal Enumerator(ExposedList<T> list) {
_list = list;
_index = 0;
_current = default(T);
this.list = list;
index = 0;
current = default(T);
}
public void Dispose() {
}
public bool MoveNext() {
ExposedList<T> localList = _list;
ExposedList<T> localList = list;
if (((uint)_index < (uint)localList._size)) {
_current = localList.Items[_index];
_index++;
if (((uint)index < (uint)localList.size)) {
current = localList.Items[index];
index++;
return true;
}
return MoveNextRare();
@ -638,28 +673,28 @@ namespace Spine {
private bool MoveNextRare()
{
_index = _list._size + 1;
_current = default(T);
index = list.size + 1;
current = default(T);
return false;
}
public T Current {
get {
return _current;
return current;
}
}
Object System.Collections.IEnumerator.Current {
get {
if( _index == 0 || _index == _list._size + 1)
if( index == 0 || index == list.size + 1)
throw new InvalidOperationException();
return Current;
}
}
void System.Collections.IEnumerator.Reset() {
_index = 0;
_current = default(T);
index = 0;
current = default(T);
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 540cf6a03c85e284e83831880e3f25a8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -34,25 +34,25 @@ using System.Collections.Generic;
namespace Spine {
public class SkeletonData {
internal String name;
internal List<BoneData> bones = new List<BoneData>();
internal List<SlotData> slots = new List<SlotData>();
internal List<Skin> skins = new List<Skin>();
internal ExposedList<BoneData> bones = new ExposedList<BoneData>();
internal ExposedList<SlotData> slots = new ExposedList<SlotData>();
internal ExposedList<Skin> skins = new ExposedList<Skin>();
internal Skin defaultSkin;
internal List<EventData> events = new List<EventData>();
internal List<Animation> animations = new List<Animation>();
internal List<IkConstraintData> ikConstraints = new List<IkConstraintData>();
internal ExposedList<EventData> events = new ExposedList<EventData>();
internal ExposedList<Animation> animations = new ExposedList<Animation>();
internal ExposedList<IkConstraintData> ikConstraints = new ExposedList<IkConstraintData>();
internal float width, height;
internal String version, hash;
public String Name { get { return name; } set { name = value; } }
public List<BoneData> Bones { get { return bones; } } // Ordered parents first.
public List<SlotData> Slots { get { return slots; } } // Setup pose draw order.
public List<Skin> Skins { get { return skins; } set { skins = value; } }
public ExposedList<BoneData> Bones { get { return bones; } } // Ordered parents first.
public ExposedList<SlotData> Slots { get { return slots; } } // Setup pose draw order.
public ExposedList<Skin> Skins { get { return skins; } set { skins = value; } }
/// <summary>May be null.</summary>
public Skin DefaultSkin { get { return defaultSkin; } set { defaultSkin = value; } }
public List<EventData> Events { get { return events; } set { events = value; } }
public List<Animation> Animations { get { return animations; } set { animations = value; } }
public List<IkConstraintData> IkConstraints { get { return ikConstraints; } set { ikConstraints = value; } }
public ExposedList<EventData> Events { get { return events; } set { events = value; } }
public ExposedList<Animation> Animations { get { return animations; } set { animations = value; } }
public ExposedList<IkConstraintData> 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; } }
/// <summary>The Spine version used to export this data.</summary>
@ -64,9 +64,9 @@ namespace Spine {
/// <returns>May be null.</returns>
public BoneData FindBone (String boneName) {
if (boneName == null) throw new ArgumentNullException("boneName cannot be null.");
List<BoneData> bones = this.bones;
ExposedList<BoneData> 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 {
/// <returns>-1 if the bone was not found.</returns>
public int FindBoneIndex (String boneName) {
if (boneName == null) throw new ArgumentNullException("boneName cannot be null.");
List<BoneData> bones = this.bones;
ExposedList<BoneData> 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 {
/// <returns>May be null.</returns>
public SlotData FindSlot (String slotName) {
if (slotName == null) throw new ArgumentNullException("slotName cannot be null.");
List<SlotData> slots = this.slots;
ExposedList<SlotData> 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 {
/// <returns>-1 if the bone was not found.</returns>
public int FindSlotIndex (String slotName) {
if (slotName == null) throw new ArgumentNullException("slotName cannot be null.");
List<SlotData> slots = this.slots;
ExposedList<SlotData> 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 {
/// <returns>May be null.</returns>
public Animation FindAnimation (String animationName) {
if (animationName == null) throw new ArgumentNullException("animationName cannot be null.");
List<Animation> animations = this.animations;
ExposedList<Animation> 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 {
/// <returns>May be null.</returns>
public IkConstraintData FindIkConstraint (String ikConstraintName) {
if (ikConstraintName == null) throw new ArgumentNullException("ikConstraintName cannot be null.");
List<IkConstraintData> ikConstraints = this.ikConstraints;
ExposedList<IkConstraintData> 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;

View File

@ -376,7 +376,7 @@ namespace Spine {
}
private void ReadAnimation (String name, Dictionary<String, Object> map, SkeletonData skeletonData) {
var timelines = new List<Timeline>();
var timelines = new ExposedList<Timeline>();
float duration = 0;
float scale = Scale;

View File

@ -80,7 +80,7 @@ public class BoneFollowerInspector : Editor {
bones[0] = "<None>";
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<String>(bones);
int boneIndex = Math.Max(0, Array.IndexOf(bones, boneName.stringValue));

View File

@ -74,7 +74,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
animations[0] = "<None>";
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;

View File

@ -76,7 +76,7 @@ public static class SkeletonBaker {
/// </summary>
const float bakeIncrement = 1 / 60f;
public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, List<Skin> skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver) {
public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, ExposedList<Skin> 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<string> attachmentNames = new List<string>();
for (int i = 0; i < skinCount; i++) {
var skin = skins[i];
var skin = skins.Items[i];
List<string> temp = new List<string>();
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<int> ignoreRotateTimelineIndexes = new List<int>();
//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();

View File

@ -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<Skin>(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList<Skin>(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<Attachment> slotAttachments = new List<Attachment>();
List<string> slotAttachmentNames = new List<string>();
List<string> defaultSkinAttachmentNames = new List<string>();
var defaultSkin = m_skeletonData.Skins[0];
var defaultSkin = m_skeletonData.Skins.Items[0];
Skin skin = m_skeletonAnimation.skeleton.Skin;
if (skin == null) {
skin = defaultSkin;

View File

@ -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;

View File

@ -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));
}

View File

@ -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();

View File

@ -190,19 +190,21 @@ 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 {
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.
Material material = (Material)((AtlasRegion)rendererObject).page.rendererObject;