11
2+ using System ;
23using Bloodstone . API ;
34using Il2CppInterop . Runtime ;
45using Unity . Entities ;
56
67
78/// <remarks>
89/// Copying these around is an anti-pattern - they should live in Bloodstone. I've put them here for now to uncouple things.
10+ /// CS8500
911/// </remarks>
12+ #pragma warning disable CS8500
1013internal static class ECSExtensions
1114{
1215 internal static void With < T > ( this Entity entity , VExtensions . ActionRef < T > action ) where T : struct
@@ -16,24 +19,33 @@ internal static void With<T>(this Entity entity, VExtensions.ActionRef<T> action
1619 VWorld . Game . EntityManager . SetComponentData ( entity , item ) ;
1720 }
1821
19- internal static bool Has < T > ( this Entity entity )
22+ internal static bool Has < T > ( this Entity entity ) where T : struct
2023 {
2124 int typeIndex = TypeManager . GetTypeIndex ( Il2CppType . Of < T > ( ) ) ;
2225
2326 return VWorld . Game . EntityManager . HasComponentRaw ( entity , typeIndex ) ;
2427 }
2528
26- internal unsafe static T RW < T > ( this Entity entity )
29+ internal unsafe static T RW < T > ( this Entity entity ) where T : struct
2730 {
2831 int typeIndex = TypeManager . GetTypeIndex ( Il2CppType . Of < T > ( ) ) ;
2932 T * componentDataRawRW = ( T * ) VWorld . Game . EntityManager . GetComponentDataRawRW ( entity , typeIndex ) ;
33+ if ( componentDataRawRW == null )
34+ {
35+ throw new InvalidOperationException ( $ "Failure to access ReadWrite <{ typeof ( T ) . Name } > typeIndex({ typeIndex } ) on entity({ entity } ).") ;
36+ }
3037 return * componentDataRawRW ;
3138 }
3239
33- internal unsafe static T Read < T > ( this Entity entity )
40+ internal unsafe static T Read < T > ( this Entity entity ) where T : struct
3441 {
3542 int typeIndex = TypeManager . GetTypeIndex ( Il2CppType . Of < T > ( ) ) ;
3643 T * componentDataRawRO = ( T * ) VWorld . Game . EntityManager . GetComponentDataRawRO ( entity , typeIndex ) ;
44+ if ( componentDataRawRO == null )
45+ {
46+ throw new InvalidOperationException ( $ "Failure to access ReadOnly <{ typeof ( T ) . Name } > typeIndex({ typeIndex } ) on entity({ entity } ).") ;
47+ }
3748 return * componentDataRawRO ;
3849 }
3950}
51+ #pragma warning restore CS8500
0 commit comments