unitytips: MenuItem "CONTEXT/component"

You can create a context menu for any component using the "CONTEXT/<component>/<menu name>" on a MenuItem attribute:

Code

using UnityEditor;
using UnityEngine;
public static class TransformContextMenu
{
[MenuItem("CONTEXT/Transform/Make a circle")]
public static void MakeCircle()
{
var length = Selection.gameObjects.Length;
var radius = 5;
for (int i = 0; i < length; i++)
{
var angle = i * Mathf.PI * 2 / length;
Selection.gameObjects[i].transform.position = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
}
}
}
Loading comments...
Tutorials

Articles

Labs