void DrawControllerMapping(ElementIdentifierMap.ControllerMapping controllerMapping) { GlyphMap glyphMap = (GlyphMap)target; GUILayout.Label(new GUIContent(controllerMapping.controllerName), titleStyle); GUILayout.BeginHorizontal(); GUILayout.Label("GUID"); guidProperty.stringValue = GUILayout.TextField(glyphMap.controllerGuid); GUILayout.EndHorizontal(); foreach (KeyValuePair <int, ElementIdentifierMap.ElementIdentifier> pair in controllerMapping.elementIdToNameMap) { int elementId = pair.Key; var elementIdentifier = pair.Value; GlyphMap.GlyphMapping currentMapping = glyphMap.GetGlyphForId(elementId); GlyphMap.GlyphMapping newGlyphMapping = new GlyphMap.GlyphMapping(); Sprite mainGlyph = null; Sprite negativeGlyph = null; Sprite positiveGlyph = null; if (currentMapping != null) { mainGlyph = currentMapping.mainGlyph; negativeGlyph = currentMapping.negativeGlyph; positiveGlyph = currentMapping.positiveGlyph; } if (elementIdentifier.type == ElementIdentifierMap.ElementIdentifierType.Button || elementIdentifier.type == ElementIdentifierMap.ElementIdentifierType.Stick) { newGlyphMapping.mainGlyph = (Sprite)EditorGUILayout.ObjectField(new GUIContent(elementIdentifier.name), mainGlyph, typeof(Sprite), false); } else if (elementIdentifier.type == ElementIdentifierMap.ElementIdentifierType.Axis) { GUILayout.Label(new GUIContent(elementIdentifier.name), smallTitleStyle); newGlyphMapping.mainGlyph = (Sprite)EditorGUILayout.ObjectField(new GUIContent("Main"), mainGlyph, typeof(Sprite), false); newGlyphMapping.negativeGlyph = (Sprite)EditorGUILayout.ObjectField(new GUIContent("Negative"), negativeGlyph, typeof(Sprite), false); newGlyphMapping.positiveGlyph = (Sprite)EditorGUILayout.ObjectField(new GUIContent("Positive"), positiveGlyph, typeof(Sprite), false); EditorGUILayout.Space(); } if (newGlyphMapping.mainGlyph != mainGlyph || newGlyphMapping.negativeGlyph != negativeGlyph || newGlyphMapping.positiveGlyph != positiveGlyph) { int index = glyphMap.GetIndexForId(elementId); if (index < 0) { index = glyphMappingsProperty.arraySize; glyphMappingsProperty.InsertArrayElementAtIndex(glyphMappingsProperty.arraySize); glyphMappingsProperty.GetArrayElementAtIndex(index).FindPropertyRelative("elementId").intValue = elementId; } glyphMappingsProperty.GetArrayElementAtIndex(index).FindPropertyRelative("mainGlyph").objectReferenceValue = newGlyphMapping.mainGlyph; glyphMappingsProperty.GetArrayElementAtIndex(index).FindPropertyRelative("negativeGlyph").objectReferenceValue = newGlyphMapping.negativeGlyph; glyphMappingsProperty.GetArrayElementAtIndex(index).FindPropertyRelative("positiveGlyph").objectReferenceValue = newGlyphMapping.positiveGlyph; } } }
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); } }