Unity 框架

InputManagerInspector.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using TFramework;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. namespace TFramework
  7. {
  8. [CustomEditor(typeof(InputManager))]
  9. public class InputManagerInspector : TEditor
  10. {
  11. SerializedProperty m_isEnableInputDevice;
  12. SerializedProperty m_inputDevice;
  13. SerializedProperty _doubleClickInterval;
  14. SerializedProperty m_checkError;
  15. List<string> inputDeviceNames = new List<string>();
  16. GenericMenu menu = new GenericMenu();
  17. private void OnEnable()
  18. {
  19. m_isEnableInputDevice = serializedObject.FindProperty("m_isEnableInputDevice");
  20. m_inputDevice = serializedObject.FindProperty("m_inputDevice");
  21. m_checkError = serializedObject.FindProperty("m_checkError");
  22. _doubleClickInterval = serializedObject.FindProperty("_doubleClickInterval");
  23. inputDeviceNames.Add("None");
  24. foreach (var item in GlobalTool.GetTypesInRunTimeAssemblies(type =>
  25. (type.IsSubclassOf(typeof(InputDeviceBase)) || (type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(InputDeviceBase)))
  26. && type.IsClass && !type.IsAbstract && type.Name != typeof(InputDeviceBase).Name))
  27. {
  28. inputDeviceNames.Add(item.FullName);
  29. }
  30. }
  31. public override void OnInspectorGUI()
  32. {
  33. serializedObject.Update();
  34. EditorGUILayout.PropertyField(m_isEnableInputDevice, new GUIContent("启用输入设备"));
  35. int selectIndex = inputDeviceNames.IndexOf(m_inputDevice.stringValue);
  36. EditorGUI.BeginChangeCheck();
  37. int newIndex = EditorGUILayout.Popup(new GUIContent("输入设备"), selectIndex, inputDeviceNames.ToArray());
  38. if (newIndex != selectIndex)
  39. {
  40. m_inputDevice.stringValue = inputDeviceNames[newIndex];
  41. selectIndex = newIndex;
  42. }
  43. EditorGUILayout.PropertyField(_doubleClickInterval, new GUIContent("双击间隔"));
  44. EditorGUILayout.PropertyField(m_checkError, new GUIContent("检测误差"));
  45. serializedObject.ApplyModifiedProperties();
  46. }
  47. }
  48. }