Search Unity

Implement IJobParallelFor with generic type?

Discussion in 'Entity Component System' started by OFFICIAL_bryanw, Jul 16, 2018.

  1. OFFICIAL_bryanw

    OFFICIAL_bryanw

    Joined:
    Jul 6, 2018
    Posts:
    36
    I'm trying to implement an IJobParallelFor to generically copy data of any type like this:

    Code (CSharp):
    1.     [BurstCompile]
    2.     struct Copy_Live<T> where T: struct, IJobParallelFor
    3.     {
    4.         public NativeArray<T> Data;
    5.  
    6.         [ReadOnly]
    7.         public NativeArray<T> Old_Data;
    8.  
    9.         public void Execute(int index)
    10.         {
    11.             T d= Old_Data[index];
    12.  
    13.             Data[index] = d;
    14.         }
    15.     }
    Is this even possible? I know right now the syntax is wrong... I want to specify that T is non-nullable but also specify that this job is implementing IJobParallelFor

    Anyone know the trick???
     
  2. OFFICIAL_bryanw

    OFFICIAL_bryanw

    Joined:
    Jul 6, 2018
    Posts:
    36
    Oh wow I figured it out:
    Code (CSharp):
    1.    [BurstCompile]
    2.     struct Copy_Live<T> IJobParallelFor where T: struct
    3.     {
    4.         public NativeArray<T> Data;
    5.         [ReadOnly]
    6.         public NativeArray<T> Old_Data;
    7.         public void Execute(int index)
    8.         {
    9.             T d= Old_Data[index];
    10.             Data[index] = d;
    11.         }
    12.     }