/// <summary> /// Constructor which creates all three arrays and fills the /// <see cref="added"/> and <see cref="updated"/> arrays with repeated copies of /// <paramref name="defaultValue"/>. /// </summary> /// <param name="addedCount">The number of added trackables.</param> /// <param name="updatedCount">The number of updated trackables.</param> /// <param name="removedCount">The number of removed trackables.</param> /// <param name="allocator">The allocator to use for each of <see cref="added"/>, <see cref="updated"/>, and <see cref="removed"/> arrays.</param> /// <param name="defaultValue">The value with which to fill the <see cref="added"/> and <see cref="updated"/> arrays.</param> public TrackableChanges( int addedCount, int updatedCount, int removedCount, Allocator allocator, T defaultValue) { m_Added = NativeCopyUtility.CreateArrayFilledWithValue(defaultValue, addedCount, allocator); m_Updated = NativeCopyUtility.CreateArrayFilledWithValue(defaultValue, updatedCount, allocator); m_Removed = new NativeArray <TrackableId>(removedCount, allocator); isCreated = true; }
/// <summary> /// Constructs a <see cref="TrackableChanges{T}"/> from native memory. /// </summary> /// <remarks> /// Because native code might be using an older version of <typeparamref name="T"/>, /// this constructor first fills the <see cref="added"/> and <see cref="updated"/> /// arrays with copies of <paramref name="defaultT"/> before copying the data from /// the <paramref name="addedPtr"/> and <paramref name="updatedPtr"/> pointers. /// This ensures that the addition of new fields to <typeparamref name="T"/> will have /// appropriate default values. /// </remarks> /// <param name="addedPtr">A pointer to a block of memory continaing <paramref name="addedCount"/> elements each of size <paramref name="stride"/>.</param> /// <param name="addedCount">The number of added elements.</param> /// <param name="updatedPtr">A pointer to a block of memory continaing <paramref name="updatedCount"/> elements each of size <paramref name="stride"/>.</param> /// <param name="updatedCount">The number of updated elements.</param> /// <param name="removedPtr">A pointer to a block of memory containing <paramref name="removedCount"/> <see cref="TrackableId"/>s.</param> /// <param name="removedCount">The number of removed elements.</param> /// <param name="defaultT">A default <typeparamref name="T"/> which should be used to fill the <see cref="added"/> and <see cref="updated"/> /// arrays before copying data from <paramref name="addedPtr"/> and <paramref name="updatedPtr"/>, respectively.</param> /// <param name="stride">The number of bytes for each element in the <paramref name="addedPtr"/> and <paramref name="updatedPtr"/> arrays.</param> /// <param name="allocator">An allocator to use when creating the <see cref="added"/>, <see cref="updated"/>, and <see cref="removed"/> arrays.</param> public unsafe TrackableChanges( void *addedPtr, int addedCount, void *updatedPtr, int updatedCount, void *removedPtr, int removedCount, T defaultT, int stride, Allocator allocator) { m_Added = NativeCopyUtility.PtrToNativeArrayWithDefault <T>(defaultT, addedPtr, stride, addedCount, allocator); m_Updated = NativeCopyUtility.PtrToNativeArrayWithDefault <T>(defaultT, updatedPtr, stride, updatedCount, allocator); m_Removed = new NativeArray <TrackableId>(removedCount, allocator); if (removedCount > 0) { UnsafeUtility.MemCpy(m_Removed.GetUnsafePtr(), removedPtr, removedCount * sizeof(TrackableId)); } isCreated = true; }
/// <summary> /// Constructs a <see cref="TrackableChanges{T}"/> from native memory. /// </summary> /// <remarks> /// Because native code may be using an older version of <typeparamref name="T"/>, /// this constructor first fills the <see cref="added"/> and <see cref="updated"/> /// arrays with copies of <paramref name="defaultT"/> before copying the data from /// the <paramref name="addedPtr"/> and <paramref name="updatedPtr"/> pointers. /// This ensures that the addition of new fields to <typeparamref name="T"/> will have /// appropriate default values. /// </remarks> /// <param name="addedPtr">A pointer to a block of memory continaing <paramref name="addedCount"/> elements each of size <paramref name="stride"/>.</param> /// <param name="addedCount">The number of added elements.</param> /// <param name="updatedPtr">A pointer to a block of memory continaing <paramref name="updatedCount"/> elements each of size <paramref name="stride"/>.</param> /// <param name="updatedCount">The number of updated elements.</param> /// <param name="removedPtr">A pointer to a block of memory containing <paramref name="removedCount"/> <see cref="TrackableId"/>s.</param> /// <param name="removedCount">The number of removed elements.</param> /// <param name="defaultT">A default <typeparamref name="T"/> which should be used to fill the <see cref="added"/> and <see cref="updated"/> /// arrays before copying data from <paramref name="addedPtr"/> and <paramref name="updatedPtr"/>, respectively.</param> /// <param name="stride">The number of bytes for each element in the <paramref name="addedPtr"/> and <paramref name="updatedPtr"/> arrays.</param> /// <param name="allocator">An allocator to use when creating the <see cref="added"/>, <see cref="updated"/>, and <see cref="removed"/> arrays.</param> public unsafe TrackableChanges( void *addedPtr, int addedCount, void *updatedPtr, int updatedCount, void *removedPtr, int removedCount, T defaultT, int stride, Allocator allocator) { m_Added = NativeCopyUtility.PtrToNativeArrayWithDefault <T>(defaultT, addedPtr, stride, addedCount, allocator); m_Updated = NativeCopyUtility.PtrToNativeArrayWithDefault <T>(defaultT, updatedPtr, stride, updatedCount, allocator); m_Removed = new NativeArray <TrackableId>(removedCount, allocator); if (removedCount > 0) { m_Removed.CopyFrom(NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <TrackableId>( removedPtr, removedCount, Allocator.None)); } isCreated = true; }