Creating Menu Items | Editor Scripting | C# | Unity Game Engine


MenuItems_Editor.cs
using UnityEngine;
using UnityEditor;

public class MenuItems_Editor
{
    [MenuItem("Control Menu/Play")]
    public static void Play()
    {
        EditorApplication.EnterPlaymode();
    }

    [MenuItem("Control Menu/Stop")]
    public static void Stop()
    {
        EditorApplication.ExitPlaymode();
    }

    [MenuItem("Assets/Custom/Clear PlayerPrefs")]
    public static void DeleteAllPlayerPrefs()
    {
        PlayerPrefs.DeleteAll();
        EditorUtility.DisplayDialog("Cleared", "PlayerPrefs Cleared", "OK");
    }

    [MenuItem("Assets/Create/Cube at Center")]
    public static void CreateCenterCube()
    {
        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube.transform.position = Vector3.zero;
    }
}