using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public static class ContextMenu { [MenuItem("GameObject/UI/Custom/Button", false, 12)] public static void PlaceButton(MenuCommand menuCommand) => PlaceCustomUI("Button", menuCommand); [MenuItem("GameObject/UI/Custom/Input", false, 12)] public static void PlaceInput(MenuCommand menuCommand) => PlaceCustomUI("Input", menuCommand); [MenuItem("GameObject/UI/Custom/Scrollable", false, 12)] public static void PlaceScrollable(MenuCommand menuCommand) => PlaceCustomUI("Scrollable", menuCommand); [MenuItem("GameObject/UI/Custom/Container", false, 12)] public static void PlaceContainer(MenuCommand menuCommand) => PlaceCustomUI("Container", menuCommand); public static void PlaceCustomUI(string part, MenuCommand mc) { var go = GameObject.Instantiate(Resources.Load("CustomUI/" + part), Vector3.zero, Quaternion.identity) as GameObject; go.name = part; GameObjectUtility.SetParentAndAlign(go, mc.context as GameObject); Undo.RegisterCreatedObjectUndo(go, "Create Custom " + part); Selection.activeObject = go; } }