/// <summary> /// Unity version of Shape from Sprite... this only works in editor but is faster than runtime implementation /// </summary> public static ComplexShape ShapeFromSprite(Sprite p_sprite, float p_detail = 1, float p_alphaTolerance = 0f, bool p_holeDetection = true) { if (p_sprite != null) { var v_method = typeof(UnityEditor.Sprites.SpriteUtility).GetMethod("GenerateOutlineFromSprite", BindingFlags.Static | BindingFlags.NonPublic); Vector2[][] v_paths = null; var v_args = new object[] { p_sprite, p_detail, (byte)(p_alphaTolerance * 255), p_holeDetection, v_paths }; v_method.Invoke(null, v_args); v_paths = v_args[4] as Vector2[][]; var v_shape = new ComplexShape(v_paths); v_shape.TransformPosition(Rect.MinMaxRect(p_sprite.bounds.min.x, p_sprite.bounds.min.y, p_sprite.bounds.max.x, p_sprite.bounds.max.y), new Rect(0, 0, 1, 1)); return(v_shape); } return(null); }