using TFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace TFramework
{
    [CustomEditor(typeof(InputManager))]
    public class InputManagerInspector : TEditor
    {
        SerializedProperty m_isEnableInputDevice;
        SerializedProperty m_inputDevice;
        SerializedProperty _doubleClickInterval;
        SerializedProperty m_checkError;

        List<string> inputDeviceNames = new List<string>();
        GenericMenu menu = new GenericMenu();

        private void OnEnable()
        {
            m_isEnableInputDevice = serializedObject.FindProperty("m_isEnableInputDevice");
            m_inputDevice = serializedObject.FindProperty("m_inputDevice");
            m_checkError = serializedObject.FindProperty("m_checkError");
            _doubleClickInterval = serializedObject.FindProperty("_doubleClickInterval");
            inputDeviceNames.Add("None");
            foreach (var item in GlobalTool.GetTypesInRunTimeAssemblies(type =>
            (type.IsSubclassOf(typeof(InputDeviceBase)) || (type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(InputDeviceBase)))
            && type.IsClass && !type.IsAbstract && type.Name != typeof(InputDeviceBase).Name))
            {
                inputDeviceNames.Add(item.FullName);
            }
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(m_isEnableInputDevice, new GUIContent("启用输入设备"));
            int selectIndex = inputDeviceNames.IndexOf(m_inputDevice.stringValue);
            EditorGUI.BeginChangeCheck();
            int newIndex = EditorGUILayout.Popup(new GUIContent("输入设备"), selectIndex, inputDeviceNames.ToArray());
            if (newIndex != selectIndex)
            {
                m_inputDevice.stringValue = inputDeviceNames[newIndex];
                selectIndex = newIndex;
            }
            EditorGUILayout.PropertyField(_doubleClickInterval, new GUIContent("双击间隔"));
            EditorGUILayout.PropertyField(m_checkError, new GUIContent("检测误差"));
            serializedObject.ApplyModifiedProperties();
        }
    }
}
