Esempio n. 1
0
        public KeyCode StringToKey(string code)
        {
            switch (code)
            {
            case "\\":
                return(KeyCode.Backslash);

            case "\"":
                return(KeyCode.Quote);

            default:
                return(KeyCodeConverter.StringToKey(code));
            }
        }
        public KeyCode OnGUI(string label, KeyCode key)
        {
            GUI.SetNextControlName(m_controlName);
            bool hasFocus = (GUI.GetNameOfFocusedControl() == m_controlName);
            if(!m_isEditing && hasFocus)
                m_keyString = Key2String(key);

            m_isEditing = hasFocus;

            if(m_isEditing)
                m_keyString = EditorGUILayout.TextField(label, m_keyString);
            else
                EditorGUILayout.TextField(label, Key2String(key));

            if(m_isEditing && Event.current.type == EventType.KeyUp)
            {
                key = KeyCodeConverter.StringToKey(m_keyString);

                m_keyString = Key2String(key);
                m_isEditing = false;
            }

            return key;
        }
Esempio n. 3
0
        public KeyCode OnGUI(Rect position, string label, KeyCode key)
        {
            GUI.SetNextControlName(m_controlName);
            bool hasFocus = (GUI.GetNameOfFocusedControl() == m_controlName);

            if (!m_isEditing && hasFocus)
            {
                m_keyString = key == KeyCode.None ? "" : KeyCodeConverter.KeyToString(key);
            }

            m_isEditing = hasFocus;
            if (m_isEditing)
            {
                m_keyString = EditorGUI.TextField(position, label, m_keyString);
            }
            else
            {
                EditorGUI.TextField(position, label, key == KeyCode.None ? "" : KeyCodeConverter.KeyToString(key));
            }

            if (m_isEditing && Event.current.type == EventType.KeyUp)
            {
                key = KeyCodeConverter.StringToKey(m_keyString);
                if (key == KeyCode.None)
                {
                    m_keyString = "";
                }
                else
                {
                    m_keyString = KeyCodeConverter.KeyToString(key);
                }
                m_isEditing = false;
            }

            return(key);
        }
 private static KeyCode ConvertUnityKeyCode(object value) => value != null?KeyCodeConverter.StringToKey(value.ToString()) : KeyCode.None;