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


MenuItems_Editor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
    }
}