//This is used to get the sprite from a Rewired action instead of knowing the actual button
    public static string GetSpriteStringForAction(int actionId)
    {
#if (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
        Init();

        // Convert action ID to NcControlElementID;
        Rewired.Player.ControllerHelper playerControllers = ReInput.players.GetPlayer(0).controllers;
        var map = playerControllers.maps.GetFirstElementMapWithAction(playerControllers.GetLastActiveController(), actionId, true);

        List <ActionElementMap> multimap = new List <ActionElementMap>();
        playerControllers.maps.GetElementMapsWithAction(playerControllers.GetLastActiveController(), actionId, true, multimap);

        var element = NCGameControllerUnity.NCControlElementID.ButtonA;
        if (multimap != null && multimap.Count > 1)
        {
            var element1 = GetElementFromString(multimap[0].elementIdentifierName);
            var element2 = GetElementFromString(multimap[1].elementIdentifierName);

            Debug.Log("found multi element " + element1 + " " + element2);

            return(GetSpriteStringForControlElement(element1) + " " + GetSpriteStringForControlElement(element2));
        }
        else if (map != null)
        {
            element = GetElementFromString(map.elementIdentifierName);
            Debug.Log("found element " + element);
        }
        else
        {
            Debug.LogWarning("Couldn't find proper mapping for Rewired action " + actionId);
        }

        return(GetSpriteStringForControlElement(element));
#else
        return("");
#endif
    }
Ejemplo n.º 2
0
    public void ShowAction(InputMappingIcons.Actions actionTarget, bool showValue, Texture2D iconTexture = null, ActionIcon.SideIconTypes sideIcon = ActionIcon.SideIconTypes.None, string actionStringOverride = null, DelayedAction delayedAction = null, bool useFillSprite = false)
    {
        Rewired.Player player = ReInput.players.GetPlayer(0);
        if (ReInput.players == null || player == null)
        {
            return;
        }
        Rewired.Player.ControllerHelper controllers = player.controllers;
        string stringValue = actionStringOverride.NullOrEmpty() ? this.GetActionText(actionTarget) : actionStringOverride;

        foreach (ControllerMap controllerMap in controllers.maps.GetAllMaps(ControllerType.Joystick))
        {
            if (controllerMap.enabled)
            {
                Controller controller = ReInput.controllers.GetController(ControllerType.Joystick, controllerMap.controllerId);
                if (controller.name.Equals(this.ControllerName))
                {
                    foreach (ActionElementMap actionElementMap in controllerMap.AllMaps)
                    {
                        InputAction action = ReInput.mapping.GetAction(actionElementMap.actionId);
                        if (action != null)
                        {
                            if (VRControllerDisplayManager.ActionMatches(actionTarget, action))
                            {
                                string elementIdentifierName = actionElementMap.elementIdentifierName;
                                if (iconTexture == null && showValue)
                                {
                                    this.RevertIcon(elementIdentifierName);
                                }
                                this.SetActive(elementIdentifierName, showValue, iconTexture, stringValue.IfNull(string.Empty).ToUpper(), this.ShouldShowTextBacking(), sideIcon, delayedAction, useFillSprite);
                            }
                        }
                    }
                }
            }
        }
    }