Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections.Generic;
  4.  
  5. [CreateAssetMenu(fileName = "new-controller-icon-mapping", menuName = "Controller Icon Mapping")]
  6. public class ControllerIconMapDefinition : ScriptableObject
  7. {
  8. [SerializeField]
  9. private InputIconMapDefinition gamepadMap = null;
  10.  
  11. [SerializeField]
  12. private InputIconMapDefinition keyboardMap = null;
  13.  
  14. [SerializeField]
  15. private InputIconMapDefinition mouseMap = null;
  16.  
  17. private List<Rewired.ControllerTemplateElementTarget> _elementTargets = new List<Rewired.ControllerTemplateElementTarget>();
  18.  
  19. public bool GetIconsForAction(int actionId, Rewired.Player player, List<InputIcon> inputIcons)
  20. {
  21. Rewired.Controller lastController = player.controllers.GetLastActiveController();
  22. if (lastController.type == Rewired.ControllerType.Joystick)
  23. {
  24. FillInputIcons(inputIcons, gamepadMap, player, lastController, actionId);
  25. }
  26. else
  27. {
  28. FillInputIcons(inputIcons, keyboardMap, player, Rewired.ReInput.controllers.Keyboard, actionId);
  29. FillInputIcons(inputIcons, mouseMap, player, Rewired.ReInput.controllers.Mouse, actionId);
  30. }
  31.  
  32. return inputIcons.Count > 0;
  33. }
  34.  
  35. private void FillInputIcons(List<InputIcon> inputIcons, InputIconMapDefinition iconMap, Rewired.Player player, Rewired.Controller controller, int actionId)
  36. {
  37. foreach (var elementMap in player.controllers.maps.ElementMapsWithAction(controller, actionId, skipDisabledMaps: false))
  38. {
  39. int inputId = elementMap.elementIdentifierId;
  40. if (controller.templateCount > 0)
  41. {
  42. _elementTargets.Clear();
  43. controller.Templates[0].GetElementTargets(elementMap, _elementTargets);
  44. if (_elementTargets.Count > 0)
  45. inputId = _elementTargets[0].element.id;
  46. }
  47.  
  48. var inputIcon = iconMap.GetInputIcon(inputId);
  49. inputIcons.Add(inputIcon);
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement