public NativeArray <T> GetFixedArray <T>(Entity entity) where T : struct { var typeIndex = TypeManager.GetTypeIndex <T>(); #if ENABLE_UNITY_COLLECTIONS_CHECKS m_Entities->AssertEntityHasComponent(entity, typeIndex); if (TypeManager.GetComponentType <T>().Category != TypeManager.TypeCategory.OtherValueType) { throw new ArgumentException($"GetComponentFixedArray<{typeof(T)}> may not be IComponentData or ISharedComponentData"); } #endif ComponentJobSafetyManager.CompleteWriteDependency(typeIndex); byte *ptr; int length; m_Entities->GetComponentDataWithTypeAndFixedArrayLength(entity, typeIndex, out ptr, out length); var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(ptr, length, Allocator.Invalid); #if ENABLE_UNITY_COLLECTIONS_CHECKS NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, ComponentJobSafetyManager.GetSafetyHandle(typeIndex, false)); #endif return(array); }
public T GetComponentData <T>(Entity entity) where T : struct, IComponentData { var typeIndex = TypeManager.GetTypeIndex <T>(); m_Entities->AssertEntityHasComponent(entity, typeIndex); ComponentJobSafetyManager.CompleteWriteDependency(typeIndex); var ptr = m_Entities->GetComponentDataWithType(entity, typeIndex); T value; UnsafeUtility.CopyPtrToStructure(ptr, out value); return(value); }
public T GetComponentData <T>(Entity entity) where T : struct, IComponentData { var typeIndex = TypeManager.GetTypeIndex <T>(); Entities->AssertEntityHasComponent(entity, typeIndex); #if ENABLE_UNITY_COLLECTIONS_CHECKS if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized) { throw new System.ArgumentException($"GetComponentData<{typeof(T)}> can not be called with a zero sized component."); } #endif ComponentJobSafetyManager.CompleteWriteDependency(typeIndex); var ptr = Entities->GetComponentDataWithTypeRO(entity, typeIndex); T value; UnsafeUtility.CopyPtrToStructure(ptr, out value); return(value); }
public T GetComponentData <T>(Entity entity) where T : struct, IComponentData { var typeIndex = TypeManager.GetTypeIndex <T>(); Entities->AssertEntityHasComponent(entity, typeIndex); // If the user attempts to get a zero-sized type, we return a default-initialized value instead. // This is to prevent requiring users from checking for zero-size before calling this API. var componentType = ComponentType.FromTypeIndex(typeIndex); if (componentType.IsZeroSized) { return(default(T)); } ComponentJobSafetyManager.CompleteWriteDependency(typeIndex); var ptr = Entities->GetComponentDataWithTypeRO(entity, typeIndex); T value; UnsafeUtility.CopyPtrToStructure(ptr, out value); return(value); }