SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top