Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- [CreateAssetMenu(fileName = "new-controller-icon-mapping", menuName = "Controller Icon Mapping")]
- public class ControllerIconMapDefinition : ScriptableObject
- {
- [SerializeField]
- private InputIconMapDefinition gamepadMap = null;
- [SerializeField]
- private InputIconMapDefinition keyboardMap = null;
- [SerializeField]
- private InputIconMapDefinition mouseMap = null;
- private List<Rewired.ControllerTemplateElementTarget> _elementTargets = new List<Rewired.ControllerTemplateElementTarget>();
- public bool GetIconsForAction(int actionId, Rewired.Player player, List<InputIcon> inputIcons)
- {
- Rewired.Controller lastController = player.controllers.GetLastActiveController();
- if (lastController.type == Rewired.ControllerType.Joystick)
- {
- FillInputIcons(inputIcons, gamepadMap, player, lastController, actionId);
- }
- else
- {
- FillInputIcons(inputIcons, keyboardMap, player, Rewired.ReInput.controllers.Keyboard, actionId);
- FillInputIcons(inputIcons, mouseMap, player, Rewired.ReInput.controllers.Mouse, actionId);
- }
- return inputIcons.Count > 0;
- }
- private void FillInputIcons(List<InputIcon> inputIcons, InputIconMapDefinition iconMap, Rewired.Player player, Rewired.Controller controller, int actionId)
- {
- foreach (var elementMap in player.controllers.maps.ElementMapsWithAction(controller, actionId, skipDisabledMaps: false))
- {
- int inputId = elementMap.elementIdentifierId;
- if (controller.templateCount > 0)
- {
- _elementTargets.Clear();
- controller.Templates[0].GetElementTargets(elementMap, _elementTargets);
- if (_elementTargets.Count > 0)
- inputId = _elementTargets[0].element.id;
- }
- var inputIcon = iconMap.GetInputIcon(inputId);
- inputIcons.Add(inputIcon);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement