| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using Unity.Burst; |
| | 6 | | using Unity.Collections; |
| | 7 | | using Unity.Jobs; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | namespace GDX.Jobs.ParallelFor |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Determines if the <see cref="Color32" />s in the provided <see cref="Unity.Collections.NativeArray{T}" />s m |
| | 14 | | /// each other in |
| | 15 | | /// parallel. |
| | 16 | | /// </summary> |
| | 17 | | [BurstCompile] |
| | 18 | | public struct Color32MatchJob : IJobParallelFor |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// The left-hand side <see cref="Unity.Collections.NativeArray{T}" /> typed as <see cref="byte" />. |
| | 22 | | /// </summary> |
| | 23 | | [ReadOnly] public NativeArray<Color32> A; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// The right-hand side <see cref="Unity.Collections.NativeArray{T}" /> typed as <see cref="byte" />. |
| | 27 | | /// </summary> |
| | 28 | | [ReadOnly] public NativeArray<Color32> B; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Does the color match? |
| | 32 | | /// </summary> |
| | 33 | | [WriteOnly] public NativeArray<bool> Match; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Executable work for the provided index. |
| | 37 | | /// </summary> |
| | 38 | | /// <param name="index">The index of the Parallel for loop at which to perform work.</param> |
| | 39 | | public void Execute(int index) |
| 0 | 40 | | { |
| 0 | 41 | | if (A[index].r == B[index].r && |
| | 42 | | A[index].g == B[index].g && |
| | 43 | | A[index].b == B[index].b && |
| | 44 | | A[index].a == B[index].a) |
| 0 | 45 | | { |
| 0 | 46 | | Match[index] = true; |
| 0 | 47 | | } |
| | 48 | | else |
| 0 | 49 | | { |
| 0 | 50 | | Match[index] = false; |
| 0 | 51 | | } |
| 0 | 52 | | } |
| | 53 | | } |
| | 54 | | } |