Skip to content

Instantly share code, notes, and snippets.

@sabresaurus
Created September 5, 2020 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabresaurus/3321755946a07236340c27e8f63f0809 to your computer and use it in GitHub Desktop.
Save sabresaurus/3321755946a07236340c27e8f63f0809 to your computer and use it in GitHub Desktop.
Getting Unity Sprite Outline
using UnityEditor;
using UnityEngine;
public class DisplaySpriteOutline : MonoBehaviour
{
[SerializeField] private Sprite sprite;
private void OnDrawGizmos()
{
TextureImporter textureImporter = (TextureImporter) AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(sprite.texture));
var spriteOutlineProperty = new SerializedObject(textureImporter).FindProperty("m_SpriteSheet.m_Outline").GetArrayElementAtIndex(0);
Vector2[] spriteOutline = new Vector2[spriteOutlineProperty.arraySize];
for (int i = 0; i < spriteOutlineProperty.arraySize; i++)
{
spriteOutline[i] = spriteOutlineProperty.GetArrayElementAtIndex(i).vector2Value;
}
for (var index = 0; index < spriteOutline.Length; index++)
{
Vector2 vertex1 = spriteOutline[index];
Vector2 vertex2 = spriteOutline[(index + 1) % spriteOutline.Length];
Gizmos.DrawLine(vertex1, vertex2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment