Search Unity

How do i use IJobParallelForFilter?

Discussion in 'Entity Component System' started by faldor20, Aug 11, 2018.

  1. faldor20

    faldor20

    Joined:
    Feb 9, 2017
    Posts:
    6
    I want to sort a large array using this compare function with the job system
    Code (CSharp):
    1.  
    2. public static int IsClockwise(Vector2 first, Vector2 second, Vector2 origin) {
    3.             if (first == second)
    4.                 return 0;
    5.  
    6.             Vector2 firstOffset = first - origin;
    7.             Vector2 secondOffset = second - origin;
    8.  
    9.             float angle1 = Mathf.Atan2(firstOffset.x, firstOffset.y);
    10.             float angle2 = Mathf.Atan2(secondOffset.x, secondOffset.y);
    11.  
    12.             if (angle1 < angle2)
    13.                 return -1;
    14.  
    15.             if (angle1 > angle2)
    16.                 return 1;
    17.  
    18.             // Check to see which point is closest
    19.             return (firstOffset.sqrMagnitude < secondOffset.sqrMagnitude) ? -1 : 1;
    20.         }
    I think the way to do that using an IJobParallelForFilter but i'm not totally sure.