@@ -39,45 +39,40 @@ public enum EntityQueryMode
3939public sealed class EntityQuery < T > : ISceneQuery
4040 where T : IComponent
4141{
42- private T [ ] contents = [ ] ;
43- private T content ;
44- private ( Entity , T ) [ ] contentEntities = [ ] ;
45- private ( Entity , T ) contentEntity ;
46-
4742 private readonly EntityQueryMode queryMode ;
4843 private readonly Entity target ;
4944 private readonly bool getEntities ;
5045
51- public int Length => contents . Length ;
46+ public int Length => Contents . Length ;
5247
5348 /// <summary>
5449 /// Contained content. Only valid if we have a single element.
5550 /// </summary>
56- public T Content => content ;
51+ public T Content { get ; private set ; }
5752
5853 /// <summary>
5954 /// Contained content. Only valid if we have a single element.
6055 /// </summary>
61- public T [ ] Contents => contents ;
56+ public T [ ] Contents { get ; private set ; } = [ ] ;
6257
6358 /// <summary>
6459 /// The content with its entity, if available.
6560 /// </summary>
66- public ( Entity , T ) ContentEntity => contentEntity ;
61+ public ( Entity , T ) ContentEntity { get ; private set ; }
6762
6863 /// <summary>
6964 /// The content with its entity, if available.
7065 /// </summary>
71- public ( Entity , T ) [ ] ContentEntities => contentEntities ;
66+ public ( Entity , T ) [ ] ContentEntities { get ; private set ; } = [ ] ;
7267
73- public T this [ int index ] => contents [ index ] ;
68+ public T this [ int index ] => Contents [ index ] ;
7469
7570 /// <summary>
7671 /// Gets an entity and component at a specific index
7772 /// </summary>
7873 /// <param name="index">The index to get at</param>
7974 /// <returns>The entity and component as a tuple, if valid</returns>
80- public ( Entity , T ) ContentEntityAt ( int index ) => index >= 0 && index < contentEntities . Length ? contentEntities [ index ] : default ;
75+ public ( Entity , T ) ContentEntityAt ( int index ) => index >= 0 && index < ContentEntities . Length ? ContentEntities [ index ] : default ;
8176
8277 /// <summary>
8378 /// Creates an entity query for a specific entity.
@@ -101,20 +96,20 @@ public void Unregister()
10196 {
10297 World . RemoveSceneQuery ( this ) ;
10398
104- content = default ;
105- contentEntity = default ;
99+ Content = default ;
100+ ContentEntity = default ;
106101
107- contents = [ ] ;
108- contentEntities = [ ] ;
102+ Contents = [ ] ;
103+ ContentEntities = [ ] ;
109104 }
110105
111106 public void WorldChanged ( )
112107 {
113- content = default ;
114- contentEntity = default ;
108+ Content = default ;
109+ ContentEntity = default ;
115110
116- contents = [ ] ;
117- contentEntities = [ ] ;
111+ Contents = [ ] ;
112+ ContentEntities = [ ] ;
118113
119114 if ( ! target . IsValid )
120115 {
@@ -143,7 +138,7 @@ public void WorldChanged()
143138 count ++ ;
144139 }
145140
146- contents = new T [ count ] ;
141+ Contents = new T [ count ] ;
147142
148143 for ( int i = 0 , counter = 0 ; i < items . Length ; i ++ )
149144 {
@@ -152,27 +147,29 @@ public void WorldChanged()
152147 continue ;
153148 }
154149
155- contents [ counter ++ ] = ( T ) items [ i ] ;
150+ Contents [ counter ++ ] = items [ i ] ;
156151 }
157152
158- if ( count == 1 && contents [ 0 ] != null )
153+ if ( count == 1 && Contents [ 0 ] != null )
159154 {
160- content = contents [ 0 ] ;
155+ Content = Contents [ 0 ] ;
161156 }
162157
163- if ( getEntities )
158+ if ( ! getEntities )
164159 {
165- contentEntities = new ( Entity , T ) [ count ] ;
160+ return ;
161+ }
162+
163+ ContentEntities = new ( Entity , T ) [ count ] ;
166164
167- for ( var i = 0 ; i < items . Length ; i ++ )
168- {
169- contentEntities [ i ] = ( World . Current . GetComponentEntity ( contents [ i ] ) , contents [ i ] ) ;
170- }
165+ for ( var i = 0 ; i < items . Length ; i ++ )
166+ {
167+ ContentEntities [ i ] = ( World . Current . GetComponentEntity ( Contents [ i ] ) , Contents [ i ] ) ;
168+ }
171169
172- if ( count == 1 && contents [ 0 ] != null )
173- {
174- contentEntity = contentEntities [ 0 ] ;
175- }
170+ if ( count == 1 && Contents [ 0 ] != null )
171+ {
172+ ContentEntity = ContentEntities [ 0 ] ;
176173 }
177174 }
178175}
@@ -187,45 +184,40 @@ public sealed class EntityQuery<T, T2> : ISceneQuery
187184 where T : IComponent
188185 where T2 : IComponent
189186{
190- private ( T , T2 ) [ ] contents = [ ] ;
191- private ( T , T2 ) content ;
192- private ( Entity , T , T2 ) [ ] contentEntities = [ ] ;
193- private ( Entity , T , T2 ) contentEntity ;
194-
195187 private readonly EntityQueryMode queryMode ;
196188 private readonly Entity target ;
197189 private readonly bool getEntities ;
198190
199- public int Length => contents . Length ;
191+ public int Length => Contents . Length ;
200192
201193 /// <summary>
202194 /// Contained content. Only valid if we have a single element.
203195 /// </summary>
204- public ( T , T2 ) Content => content ;
196+ public ( T , T2 ) Content { get ; private set ; }
205197
206198 /// <summary>
207199 /// Contained content. Only valid if we have a single element.
208200 /// </summary>
209- public ( T , T2 ) [ ] Contents => contents ;
201+ public ( T , T2 ) [ ] Contents { get ; private set ; } = [ ] ;
210202
211203 /// <summary>
212204 /// The content with its entity, if available.
213205 /// </summary>
214- public ( Entity , T , T2 ) ContentEntity => contentEntity ;
206+ public ( Entity , T , T2 ) ContentEntity { get ; private set ; }
215207
216208 /// <summary>
217209 /// The content with its entity, if available.
218210 /// </summary>
219- public ( Entity , T , T2 ) [ ] ContentEntities => contentEntities ;
211+ public ( Entity , T , T2 ) [ ] ContentEntities { get ; private set ; } = [ ] ;
220212
221- public ( T , T2 ) this [ int index ] => contents [ index ] ;
213+ public ( T , T2 ) this [ int index ] => Contents [ index ] ;
222214
223215 /// <summary>
224216 /// Gets an entity and component at a specific index
225217 /// </summary>
226218 /// <param name="index">The index to get at</param>
227219 /// <returns>The entity and component as a tuple, if valid</returns>
228- public ( Entity , T , T2 ) ContentEntityAt ( int index ) => index >= 0 && index < contentEntities . Length ? contentEntities [ index ] : default ;
220+ public ( Entity , T , T2 ) ContentEntityAt ( int index ) => index >= 0 && index < ContentEntities . Length ? ContentEntities [ index ] : default ;
229221
230222 /// <summary>
231223 /// Creates an entity query for a specific entity.
@@ -249,20 +241,20 @@ public void Unregister()
249241 {
250242 World . RemoveSceneQuery ( this ) ;
251243
252- content = default ;
253- contentEntity = default ;
244+ Content = default ;
245+ ContentEntity = default ;
254246
255- contents = [ ] ;
256- contentEntities = [ ] ;
247+ Contents = [ ] ;
248+ ContentEntities = [ ] ;
257249 }
258250
259251 public void WorldChanged ( )
260252 {
261- content = default ;
262- contentEntity = default ;
253+ Content = default ;
254+ ContentEntity = default ;
263255
264- contents = [ ] ;
265- contentEntities = [ ] ;
256+ Contents = [ ] ;
257+ ContentEntities = [ ] ;
266258
267259 if ( ! target . IsValid )
268260 {
@@ -413,28 +405,30 @@ void Recursive(Transform transform)
413405 break ;
414406 }
415407
416- contents = items . ToArray ( ) ;
408+ Contents = items . ToArray ( ) ;
417409
418- if ( contents . Length == 1 )
410+ if ( Contents . Length == 1 )
419411 {
420- content = contents [ 0 ] ;
412+ Content = Contents [ 0 ] ;
421413 }
422414
423- if ( getEntities )
415+ if ( ! getEntities )
424416 {
425- contentEntities = new ( Entity , T , T2 ) [ items . Count ] ;
417+ return ;
418+ }
426419
427- for ( var i = 0 ; i < items . Count ; i ++ )
428- {
429- var item = items [ i ] ;
420+ ContentEntities = new ( Entity , T , T2 ) [ items . Count ] ;
430421
431- contentEntities [ i ] = ( World . Current . GetComponentEntity ( item . Item1 ) , item . Item1 , item . Item2 ) ;
432- }
422+ for ( var i = 0 ; i < items . Count ; i ++ )
423+ {
424+ var item = items [ i ] ;
433425
434- if ( items . Count == 1 )
435- {
436- contentEntity = contentEntities [ 0 ] ;
437- }
426+ ContentEntities [ i ] = ( World . Current . GetComponentEntity ( item . Item1 ) , item . Item1 , item . Item2 ) ;
427+ }
428+
429+ if ( items . Count == 1 )
430+ {
431+ ContentEntity = ContentEntities [ 0 ] ;
438432 }
439433 }
440434}
0 commit comments