You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.6 KiB
97 lines
3.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
namespace uc
|
|
{
|
|
[CustomEditor(typeof(HotKeyManager))]
|
|
public class HotKeyManagerEditor : Editor
|
|
{
|
|
SerializedProperty hotkeysProperty;
|
|
//private Editor _editor;
|
|
//HotKeyManager hotkeyMamager;
|
|
GUIContent m_IconToolbarMinus;
|
|
GUIContent m_AddButonContent;
|
|
//int index = 0;
|
|
|
|
protected void OnEnable()
|
|
{
|
|
if (target == null)
|
|
return;
|
|
|
|
//hotkeyMamager = target as HotKeyManager;
|
|
hotkeysProperty = serializedObject.FindProperty("hotkeys");
|
|
m_AddButonContent = new GUIContent("Add New Key");
|
|
|
|
m_IconToolbarMinus = new GUIContent(EditorGUIUtility.IconContent("Toolbar Minus"));
|
|
//m_IconToolbarMinus = new GUIContent("remove");
|
|
m_IconToolbarMinus.tooltip = "Remove this key.";
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
if (target == null)
|
|
return;
|
|
|
|
serializedObject.Update();
|
|
|
|
int toBeRemovedEntry = -1;
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
Vector2 removeButtonSize = GUIStyle.none.CalcSize(m_IconToolbarMinus);
|
|
|
|
for (int i = 0; i < hotkeysProperty.arraySize; ++i)
|
|
{
|
|
SerializedProperty delegateProperty = hotkeysProperty.GetArrayElementAtIndex(i);
|
|
SerializedProperty enableProperty = delegateProperty.FindPropertyRelative("enable");
|
|
SerializedProperty m_CallStateProperty = delegateProperty.FindPropertyRelative("m_CallState");
|
|
SerializedProperty _keyCodeProperty = delegateProperty.FindPropertyRelative("_keyCode");
|
|
SerializedProperty _keyDownEvent = delegateProperty.FindPropertyRelative("_keyDownEvent");
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
enableProperty.boolValue = EditorGUILayout.ToggleLeft(enableProperty.displayName, enableProperty.boolValue);
|
|
Rect callbackRect = GUILayoutUtility.GetRect(removeButtonSize.y, removeButtonSize.y, GUI.skin.button);
|
|
if (GUI.Button(callbackRect, m_IconToolbarMinus, GUI.skin.button))
|
|
{
|
|
toBeRemovedEntry = i;
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUI.BeginDisabledGroup(enableProperty.boolValue == false);
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
EditorGUILayout.PropertyField(m_CallStateProperty, new GUIContent(""));
|
|
EditorGUILayout.PropertyField(_keyCodeProperty, new GUIContent(""));
|
|
EditorGUILayout.EndHorizontal();
|
|
EditorGUILayout.PropertyField(_keyDownEvent);
|
|
}
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
EditorGUILayout.Space();
|
|
}
|
|
|
|
if (toBeRemovedEntry > -1)
|
|
{
|
|
RemoveEntry(toBeRemovedEntry);
|
|
}
|
|
|
|
Rect btPosition = GUILayoutUtility.GetRect(m_AddButonContent, GUI.skin.button);
|
|
const float addButonWidth = 200f;
|
|
btPosition.x = btPosition.x + (btPosition.width - addButonWidth) / 2;
|
|
btPosition.width = addButonWidth;
|
|
if (GUI.Button(btPosition, m_AddButonContent))
|
|
{
|
|
hotkeysProperty.arraySize += 1;
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
private void RemoveEntry(int toBeRemovedEntry)
|
|
{
|
|
hotkeysProperty.DeleteArrayElementAtIndex(toBeRemovedEntry);
|
|
}
|
|
}
|
|
} |