Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active October 26, 2019 19:53
Show Gist options
  • Save unitycoder/80f76a58ebe535658fd0 to your computer and use it in GitHub Desktop.
Save unitycoder/80f76a58ebe535658fd0 to your computer and use it in GitHub Desktop.
Sort System.Array of custom Struct with CompareTo
Array.Sort(tiles, new Comparison<YourThing>((a, b) => b.x.CompareTo(a.x)));
// declare
PointData[] pointArray;
// init
pointArray = new PointData[masterPointCount];
// fill
pointArray[rowCount].vertex = new Vector3(x,y,z);
pointArray[rowCount].uv = new Vector2(x,y);
// sort
System.Array.Sort<PointData>(pointArray, (a,b) => (corner-a.vertex).sqrMagnitude.CompareTo((corner-b.vertex).sqrMagnitude));
// struct
using UnityEngine;
public struct PointData
{
public Vector3 vertex;
public Vector2 uv;
public int indice;
public Color color;
public Vector3 normal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment