using System; using UnityEditor; using UnityEngine; using VketCloudGUITools.Runtime; namespace VketCloudGUITools.Editor { [CustomEditor(typeof(GUIAction), isFallback = true)] public class GUIActionInspector : SubInspector { public override void OnSubInspectorGUI(Rect position) { var mainRect = position; mainRect.height -= EditorGUIUtility.singleLineHeight; var warningRect = position; warningRect.yMin = mainRect.yMax; // default inspector base.OnSubInspectorGUI(mainRect); // warning Color defaultContentColor = GUI.contentColor; GUI.contentColor = Color.yellow; EditorGUI.DrawRect(warningRect, new Color(1f, 1f, 0f, 1f / 32f)); GUI.Label(warningRect, "-Warning- Custom Editor Not Found"); GUI.contentColor = defaultContentColor; } public override float GetSubInspectorHeight() { return base.GetSubInspectorHeight() + EditorGUIUtility.singleLineHeight; } /// /// 選択肢から選ぶことも、自由入力も可能なTextField /// /// 文字列表示欄 /// 選択肢表示欄 /// 文字列代入先 /// 選択肢の一覧 protected string DrawActionNameTypeField(Rect checkRect, Rect typeRect, string actionName, string[] actionNameSelectableOptions) { // MEMO:見た目だけButtonにして、挙動はPopupにする int selectedIndex = -1; EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.Repaint) { EditorGUI.Popup(checkRect, 0, new string[] { "Select" }); } else { selectedIndex = EditorGUI.Popup(checkRect, Array.IndexOf(actionNameSelectableOptions, actionName), actionNameSelectableOptions); } if (EditorGUI.EndChangeCheck() && selectedIndex >= 0) { actionName = actionNameSelectableOptions[selectedIndex]; } actionName = EditorGUI.TextField(typeRect, "Action", actionName); if (string.IsNullOrEmpty(actionName)) { var contentColorBackup = GUI.contentColor; GUI.contentColor = Color.Lerp(GUI.contentColor, Color.grey, 0.5f); var textRect = new Rect(typeRect); textRect.x += EditorGUIUtility.labelWidth; GUI.Label(textRect, " (Input Action Name)"); GUI.contentColor = contentColorBackup; } return actionName; } /// /// 選択肢を選べるような見た目だが、実際には選べない入力欄 /// 他の入力欄と見た目を合わせる都合 /// /// 文字列入力欄 /// 選択肢表示欄 /// protected void DrawActionNameTypeFieldDummy(Rect checkRect, Rect typeRect, string actionName) { EditorGUI.BeginDisabledGroup(true); DrawActionNameTypeField(checkRect, typeRect, actionName, new string[] { actionName }); EditorGUI.EndDisabledGroup(); } } }