示例#1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        KeyboardGlyphMap glyphMap = (KeyboardGlyphMap)target;

        foreach (Rewired.KeyboardKeyCode keyCode in Enum.GetValues(typeof(Rewired.KeyboardKeyCode)))
        {
            KeyboardGlyphMap.GlyphMapping currentMapping = glyphMap.GetGlyphForKeyCode(keyCode);
            KeyboardGlyphMap.GlyphMapping newMapping     = new KeyboardGlyphMap.GlyphMapping();

            Sprite glyph = null;
            if (currentMapping != null)
            {
                glyph = currentMapping.glyph;
            }

            newMapping.glyph = (Sprite)EditorGUILayout.ObjectField(new GUIContent(keyCode.ToString()), glyph, typeof(Sprite), false);

            if (newMapping.glyph != glyph)
            {
                int index = glyphMap.GetIndexForKeyCode(keyCode);
                if (index < 0)
                {
                    index = glyphMappingsProperty.arraySize;
                    glyphMappingsProperty.InsertArrayElementAtIndex(glyphMappingsProperty.arraySize);
                }

                SerializedProperty glyphMappingArrayProperty = glyphMappingsProperty.GetArrayElementAtIndex(index);
                glyphMappingArrayProperty.FindPropertyRelative("keyCode").intValue           = (int)keyCode;
                glyphMappingArrayProperty.FindPropertyRelative("glyph").objectReferenceValue = newMapping.glyph;
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
示例#2
0
    public Sprite GetGlyph(ActionElementMap actionElementMap)
    {
        Controller controller = actionElementMap.controllerMap.controller;

        if (controller.type == ControllerType.Joystick)
        {
            Joystick joystick = controller as Joystick;
            string   guid     = joystick.hardwareTypeGuid.ToString();
            GlyphMap glyphMap = glyphMaps.Find((x) => x.controllerGuid == guid);

            if (glyphMap == null)
            {
                return(defaultGlyph);
            }

            GlyphMap.GlyphMapping glyphMapping = glyphMap.GetGlyphForId(actionElementMap.elementIdentifierId);
            if (actionElementMap.axisRange == AxisRange.Full || actionElementMap.elementType == ControllerElementType.Button)
            {
                return(glyphMapping.mainGlyph ?? defaultGlyph);
            }
            else if (actionElementMap.axisRange == AxisRange.Negative)
            {
                return(glyphMapping.negativeGlyph ?? defaultGlyph);
            }
            else if (actionElementMap.axisRange == AxisRange.Positive)
            {
                return(glyphMapping.positiveGlyph ?? defaultGlyph);
            }

            return(defaultGlyph);
        }
        else if (controller.type == ControllerType.Keyboard)
        {
            var glyphMapping = keyboardGlyphMap.GetGlyphForKeyCode(actionElementMap.keyboardKeyCode);
            if (glyphMapping != null)
            {
                return(glyphMapping.glyph);
            }

            return(defaultGlyph);
        }
        else if (controller.type == ControllerType.Mouse)
        {
            MouseGlyphMap.GlyphMapping glyphMapping = mouseGlyphMap.GetGlyphForId(actionElementMap.elementIdentifierId);
            if (actionElementMap.axisRange == AxisRange.Full || actionElementMap.elementType == ControllerElementType.Button)
            {
                return(glyphMapping.mainGlyph ?? defaultGlyph);
            }
            else if (actionElementMap.axisRange == AxisRange.Negative)
            {
                return(glyphMapping.negativeGlyph ?? defaultGlyph);
            }
            else if (actionElementMap.axisRange == AxisRange.Positive)
            {
                return(glyphMapping.positiveGlyph ?? defaultGlyph);
            }

            return(defaultGlyph);
        }
        else
        {
            Debug.LogError("Unsupported controller type: " + controller.type, this);
            return(defaultGlyph);
        }
    }