10using System.Collections;
11using System.Collections.Generic;
19 public abstract class MultiTypedList {
37 public abstract int Count {
get; }
45 public abstract BaseType
this[
int index] {
get;
set; }
47 public abstract void Add(BaseType obj);
52 for (
int i = 0; i <
Count; i++) {
53 if (
this[i].Equals(item)) {
60 public void CopyTo(BaseType[] array,
int arrayIndex) {
61 for (
int i = 0; i <
Count; i++) {
62 array[i + arrayIndex] =
this[i];
71 for (
int i = 0; i <
Count; i++) {
72 if (
this[i].Equals(item)) {
79 public abstract void Insert(
int index, BaseType item);
96 private BaseType _current;
101 _current =
default(BaseType);
110 object IEnumerator.Current {
112 throw new NotImplementedException();
118 _current =
default(BaseType);
122 if (_index >= _list.
Count) {
125 _current = _list[_index++];
132 _current =
default(BaseType);
136 IEnumerator IEnumerable.GetEnumerator() {
137 return new Enumerator(
this);
140 IEnumerator<BaseType> IEnumerable<BaseType>.GetEnumerator() {
141 return new Enumerator(
this);
148 public const string ID_NAME_TABLE =
"abcdefghijklmnopqrstuvwxyz";
149 public static Dictionary<int, string> _nameCache =
new Dictionary<int, string>();
150 private static string getName(
int id) {
152 if (!_nameCache.TryGetValue(
id, out name)) {
153 name =
"_" + ID_NAME_TABLE[id];
154 _nameCache[id] = name;
159 public static SerializedProperty GetTableProperty(SerializedProperty list) {
160 return list.FindPropertyRelative(
"_table");
163 public static SerializedProperty GetArrayElementAtIndex(SerializedProperty list,
int index) {
164 var tableProp = GetTableProperty(list);
165 var idIndexProp = tableProp.GetArrayElementAtIndex(index);
167 return GetReferenceProperty(list, idIndexProp);
170 public static SerializedProperty GetReferenceProperty(SerializedProperty list, SerializedProperty idIndexProp) {
171 var idProp = idIndexProp.FindPropertyRelative(
"id");
172 var indexProp = idIndexProp.FindPropertyRelative(
"index");
174 string listPropName = getName(idProp.intValue);
175 var listProp = list.FindPropertyRelative(listPropName);
176 return listProp.GetArrayElementAtIndex(indexProp.intValue);
187 private List<Key> _table =
new List<Key>();
190 private List<A> _a =
new List<A>();
193 private List<B> _b =
new List<B>();
201 public override void Add(BaseType obj) {
211 public override void Insert(
int index, BaseType obj) {
217 var removedKey = _table[index];
218 _table.RemoveAt(index);
220 getList(removedKey.id).RemoveAt(removedKey.index);
222 for (
int i = 0; i < _table.Count; i++) {
224 if (key.id == removedKey.id && key.index > removedKey.index) {
231 public override BaseType
this[
int index] {
233 Key key = _table[index];
237 Key oldKey = _table[index];
241 _table[index] = newKey;
257 }
else if (obj is
B) {
260 throw new ArgumentException(
"This multi typed list does not support type " + obj.GetType().Name);
267 }
else if (
id == 1) {
270 throw new Exception(
"This multi typed list does not have a list with id " +
id);
281 private List<C> _c =
new List<C>();
284 return obj is C ?
addHelper(_c, obj, 2) : base.addInternal(obj);
288 return id == 2 ? _c : base.getList(
id);
304 private List<D> _d =
new List<D>();
307 return obj is D ?
addHelper(_d, obj, 3) : base.addInternal(obj);
311 return id == 3 ? _d : base.getList(
id);
328 private List<E> _e =
new List<E>();
331 return obj is E ?
addHelper(_e, obj, 4) : base.addInternal(obj);
335 return id == 4 ? _e : base.getList(
id);
344 public class MultiTypedList<BaseType,
A,
B, C, D, E, F> :
MultiTypedList<BaseType, A, B, C, D, E>
353 private List<F> _f =
new List<F>();
356 return obj is F ?
addHelper(_f, obj, 5) : base.addInternal(obj);
360 return id == 5 ? _f : base.getList(
id);
369 public class MultiTypedList<BaseType,
A,
B, C, D, E, F,
G> :
MultiTypedList<BaseType, A, B, C, D, E, F>
379 private List<G> _g =
new List<G>();
382 return obj is
G ?
addHelper(_g, obj, 6) : base.addInternal(obj);
386 return id == 6 ? _g : base.getList(
id);
395 public class MultiTypedList<BaseType,
A,
B, C, D, E, F,
G, H> :
MultiTypedList<BaseType, A, B, C, D, E, F, G>
406 private List<H> _h =
new List<H>();
409 return obj is H ?
addHelper(_h, obj, 7) : base.addInternal(obj);
413 return id == 7 ? _h : base.getList(
id);
Represents an ordered collection of objects of type BaseType.
abstract void Add(BaseType obj)
bool Remove(BaseType item)
override void Insert(int index, BaseType obj)
int IndexOf(BaseType item)
virtual IList getList(int id)
Key addHelper(IList list, BaseType instance, int id)
override IList getList(int id)
override void Add(BaseType obj)
Enumerator GetEnumerator()
bool Contains(BaseType item)
override Key addInternal(BaseType obj)
abstract void RemoveAt(int index)
void CopyTo(BaseType[] array, int arrayIndex)
virtual Key addInternal(BaseType obj)
override void RemoveAt(int index)
abstract void Insert(int index, BaseType item)
Enumerator(MultiTypedList< BaseType > list)