using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace VketCloudGUITools.Editor { /// /// Editor用:Hierarchy右クリックメニュー追加 /// VketCloudGUIToolsのUI作成 /// public class VCGUIHierarchyMenu { public static class Constants { private const string CREATE_MENU_ITEM_PREFIX = "GameObject/VketCloudGUI/"; public const string CREATE_LANDSCAPE_LAYER_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "LandscapeLayer"; public const string CREATE_PORTRAIT_LAYER_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "PortraitLayer"; public const string CREATE_CANVAS_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "Canvas"; public const string CREATE_TEXT_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "Text"; public const string CREATE_IMAGE_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "Image"; public const string CREATE_BUTTON_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "Button"; public const string CREATE_SLIDER_MENU_ITEM_KEY = CREATE_MENU_ITEM_PREFIX + "Slider"; } private static void TrySetParent(GameObject gameObject, GameObject parent) { if (gameObject != null && parent != null) { gameObject.transform.SetParent(parent.transform, false); gameObject.transform.hasChanged = true; } } [MenuItem(Constants.CREATE_LANDSCAPE_LAYER_MENU_ITEM_KEY, false, 10)] private static void LandscapeLayer() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateLayer("VCGUILayer", Runtime.CanvasType.LandScape); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_PORTRAIT_LAYER_MENU_ITEM_KEY, false, 11)] private static void PortraitLayer() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateLayer("VCGUILayer", Runtime.CanvasType.Portrait); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_CANVAS_MENU_ITEM_KEY, false, 12)] private static void Canvas() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateCanvas("VCGUICanvas"); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_TEXT_MENU_ITEM_KEY, false, 13)] private static void Text() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateText("VCGUIText"); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_IMAGE_MENU_ITEM_KEY, false, 14)] private static void Image() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateImage("VCGUIImage"); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_BUTTON_MENU_ITEM_KEY, false, 15)] private static void Button() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateButton("VCGUIButton"); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } [MenuItem(Constants.CREATE_SLIDER_MENU_ITEM_KEY, false, 16)] private static void Slider() { var selectedGameObject = Selection.activeGameObject; var createdGameObject = VCGUIEditorFactory.CreateSlider("VCGUISlider"); TrySetParent(createdGameObject, selectedGameObject); Selection.activeGameObject = createdGameObject; EditorUtility.SetDirty(createdGameObject); } } }