33 lines
876 B
C#
33 lines
876 B
C#
using Godot;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public abstract class ReadOnlyResourceList<T> : Resource, IReadOnlyList<T> where T : Resource
|
|
{
|
|
[Export]
|
|
private List<Resource> _resources = new List<Resource>();
|
|
private List<T> Collection
|
|
{
|
|
get
|
|
{
|
|
if (_collection != null)
|
|
return _collection;
|
|
|
|
_collection = new List<T>();
|
|
foreach (var resource in _resources)
|
|
{
|
|
_collection.Add((T)resource);
|
|
}
|
|
return _collection;
|
|
}
|
|
}
|
|
private List<T> _collection = null;
|
|
|
|
public T this[int index] => Collection[index];
|
|
|
|
public int Count => Collection.Count;
|
|
|
|
public IEnumerator<T> GetEnumerator() => Collection.GetEnumerator();
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => Collection.GetEnumerator();
|
|
} |