Skip to content

Instantly share code, notes, and snippets.

@jaburns
Created November 1, 2015 19:13
Show Gist options
  • Save jaburns/854bfa170dc573b1f54b to your computer and use it in GitHub Desktop.
Save jaburns/854bfa170dc573b1f54b to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
static public class PolygonHolePunchMenuItem
{
[MenuItem("Tools/PolygonCollider2D Punch Hole")]
static public void PolygonHolePunchMenuItem_Click()
{
if (!Selection.activeGameObject) return;
var collider = Selection.activeGameObject.GetComponent<PolygonCollider2D>();
if (!collider) return;
var originalPoints = collider.points;
var newPoints = originalPoints.Clone() as Vector2[];
for (int i = 0; i < newPoints.Length; ++i) {
newPoints[i].x *= 0.5f;
newPoints[i].y *= 0.5f;
}
collider.pathCount = 2;
collider.SetPath(0, originalPoints);
collider.SetPath(1, newPoints);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment