Created
January 20, 2018 17:57
-
-
Save shole/50d145ff6aa8b0763c5340d0f684a5db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class CombinedRefList<T> : IEnumerable { | |
public List<IList<T>> lists = new List<IList<T>>(); | |
public T this[int index] { | |
get { | |
if ( lists.Count != 0 ) { | |
int indexes = 0; | |
foreach ( IList<T> list in lists ) { | |
if ( indexes + list.Count > index ) { | |
return list[index - indexes]; | |
} | |
indexes += list.Count; | |
} | |
} | |
throw new Exception("Invalid index " + index); | |
} | |
set { | |
if ( lists.Count != 0 ) { | |
int indexes = 0; | |
foreach ( IList<T> list in lists ) { | |
if ( indexes + list.Count > index ) { | |
list[index - indexes] = value; | |
return; | |
} | |
indexes += list.Count; | |
} | |
} | |
throw new Exception("Invalid index " + index); | |
} | |
} | |
public int Count { | |
get { | |
int indexes = 0; | |
foreach ( IList<T> list in lists ) { | |
indexes += list.Count; | |
} | |
return indexes; | |
} | |
} | |
public IEnumerator GetEnumerator() { | |
foreach ( IList<T> list in lists ) { | |
foreach ( T item in list ) { | |
yield return item; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for testing;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class combinedlisttest : MonoBehaviour {
}