-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDataTaxonSlice.cs
66 lines (63 loc) · 2.43 KB
/
DataTaxonSlice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
namespace VodeoECS
{
/// <summary>
/// A slice into the Data Components associated with a single Taxon.
/// The order of Entities associated with each Component in a Taxon Slice is preserved across all Component Pools sharing the Taxon.
/// Can be passed to Burst Compiled jobs.
/// </summary>
/// <typeparam name="T">The type of the Data Components accessed by this Taxon Slice.</typeparam>
public struct DataTaxonSlice<T> : IEnumerable<T> where T : unmanaged, IDataComponent
{
/// <summary>
/// Number of Data Components in this Slice.
/// </summary>
public int Length { get { return slice.Length; } }
private NativeSlice<T> slice;
/// <summary>
/// For internal use by the Data Component Pool class. Constructs a Data Taxon Slice.
/// </summary>
/// <param name="slice">A NativeSlice into the Data Components for a single Taxon.</param>
public DataTaxonSlice ( NativeSlice<T> slice )
{
this.slice = slice;
}
/// <summary>
/// The Data Component at a specific position in the Taxon Slice.
/// The order of Entities associated with each Component in a Taxon Slice is preserved across all Component Pools sharing the Taxon.
/// </summary>
/// <param name="i">The position of the Data Component in the Taxon Slice.</param>
/// <returns>The value of the Data Component at the given position.</returns>
public T this[int i]
{
get
{
return slice[i];
}
set
{
this.slice[i] = value;
}
}
/// <summary>
/// Enumerates through all Data Component values in this Taxon Slice.
/// The order of Entities associated with each Component in a Taxon Slice is preserved across all Component Pools sharing the Taxon.
/// </summary>
/// <returns>Each Data Component value in the Taxon Slice.</returns>
public IEnumerator<T> GetEnumerator ( )
{
for ( int i = 0; i < this.Length; i++ )
{
yield return slice[i];
}
}
IEnumerator IEnumerable.GetEnumerator ( )
{
return GetEnumerator( );
}
}
}