示例#1
0
        private void ActivateElements(Player player, int actionId)
        {
            float axis = player.GetAxis(actionId);

            if ((double)axis == 0.0)
            {
                return;
            }
            IList <InputActionSourceData> currentInputSources = player.GetCurrentInputSources(actionId);

            for (int index1 = 0; index1 < ((ICollection <InputActionSourceData>)currentInputSources).Count; ++index1)
            {
                InputActionSourceData actionSourceData = currentInputSources[index1];
                IGamepadTemplate      template         = (IGamepadTemplate)((InputActionSourceData) ref actionSourceData).get_controller().GetTemplate <IGamepadTemplate>();
                if (template != null)
                {
                    ((IControllerTemplate)template).GetElementTargets(ControllerElementTarget.op_Implicit(((InputActionSourceData) ref actionSourceData).get_actionElementMap()), this._tempTargetList);
                    for (int index2 = 0; index2 < ((ICollection <ControllerTemplateElementTarget>) this._tempTargetList).Count; ++index2)
                    {
                        ControllerTemplateElementTarget tempTarget = this._tempTargetList[index2];
                        int id = ((ControllerTemplateElementTarget) ref tempTarget).get_element().get_id();
                        ControllerUIElement uiElement = this._uiElements[id];
                        if (((ControllerTemplateElementTarget) ref tempTarget).get_elementType() == null)
                        {
                            uiElement.Activate(axis);
                        }
                        else if (((ControllerTemplateElementTarget) ref tempTarget).get_elementType() == 1 && (player.GetButton(actionId) || player.GetNegativeButton(actionId)))
                        {
                            uiElement.Activate(1f);
                        }
                        this.GetStick(id)?.SetAxisPosition(id, axis * 20f);
                    }
                }
示例#2
0
        private void ActivateElements(Player player, int actionId)
        {
            // Get the Axis value of the Action from the Player
            float axisValue = player.GetAxis(actionId);

            if (axisValue == 0f)
            {
                return;                  // not active
            }
            // Get all the sources contributing to the Action
            IList <InputActionSourceData> sources = player.GetCurrentInputSources(actionId);

            // Check each source and activate the elements they map to
            for (int i = 0; i < sources.Count; i++)
            {
                InputActionSourceData source = sources[i];

                // Try to get the GamepadTemplate from the Controller
                IGamepadTemplate gamepad = source.controller.GetTemplate <IGamepadTemplate>();
                if (gamepad == null)
                {
                    continue;                  // does not implement the Dual Analog Gamepad Template
                }
                // Get all element targets on the template by passing in the Action Element Map
                // This gives you the Template element targets that are mapped to the Controller element target.
                gamepad.GetElementTargets(source.actionElementMap, _tempTargetList);

                // Activate Template element targets
                for (int j = 0; j < _tempTargetList.Count; j++)
                {
                    ControllerTemplateElementTarget target = _tempTargetList[j];
                    int templateElementId         = target.element.id;
                    ControllerUIElement uiElement = _uiElements[templateElementId];

                    if (target.elementType == ControllerTemplateElementType.Axis)
                    {
                        uiElement.Activate(axisValue);
                    }
                    else if (target.elementType == ControllerTemplateElementType.Button)
                    {
                        // If the target element is a Button, make sure the Button value of the Action is true before activating
                        if (player.GetButton(actionId) || player.GetNegativeButton(actionId))
                        {
                            uiElement.Activate(1f);
                        }
                    }

                    // Move the stick for stick axes
                    Stick stick = GetStick(templateElementId);
                    if (stick != null)
                    {
                        stick.SetAxisPosition(templateElementId, axisValue * stickRadius);
                    }
                }
            }
        }
示例#3
0
        private void DrawLabels(Player player, InputAction action)
        {
            // Lists first Action bound to each Dual Analog Gamepad Template element

            // Get the first Controller that implements the Dual Analog Gamepad Template from the Player
            Controller controller = player.controllers.GetFirstControllerWithTemplate <IGamepadTemplate>();

            if (controller == null)
            {
                return;
            }

            // Get the first gamepad assigned to the Player
            IGamepadTemplate gamepad = controller.GetTemplate <IGamepadTemplate>();

            // Get the Controller Map in the Default category and layout for this Controller from the Player
            ControllerMap controllerMap = player.controllers.maps.GetMap(controller, "Default", "Default");

            if (controllerMap == null)
            {
                return;
            }

            // Go through each Controller Template element displayed in the UI
            for (int i = 0; i < _uiElementsArray.Length; i++)
            {
                ControllerUIElement uiElement = _uiElementsArray[i].element;
                int elementId = _uiElementsArray[i].id;

                // Get the Controller Template Element from the Controller Template
                IControllerTemplateElement element = gamepad.GetElement(elementId);

                // Draw the label
                DrawLabel(uiElement, action, controllerMap, gamepad, element);
            }
        }