Esempio n. 1
0
        private void DrawLabel(ControllerUIElement uiElement, InputAction action, ControllerMap controllerMap,
                               IControllerTemplate template, IControllerTemplateElement element)
        {
            if (element.source == null)
            {
                return;                         // this element cannot map to a source
            }
            ActionElementMap aem;

            // A Controller Template Element Source contains Targets that each point to
            // a Controller.Element or part of a Controller.Element (such as one pole of an Axis).

            // Handle Axis-type Template Element
            if (element.source.type == ControllerTemplateElementSourceType.Axis)
            {
                // Cast the source to an Axis source so we can access the 3 possible Targets
                IControllerTemplateAxisSource source = (element.source as IControllerTemplateAxisSource);

                // A Template axis source can be either a full-axis binding or a split-axis binding

                // Handle split-axis source
                if (source.splitAxis)
                {
                    // A split-axis source has a Positive Target and a Negative Target, one for each side of the axis.

                    // Positive Target
                    aem = controllerMap.GetFirstElementMapWithElementTarget(source.positiveTarget, action.id, true);
                    if (aem != null)
                    {
                        uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Positive);
                    }

                    // Negative Target
                    aem = controllerMap.GetFirstElementMapWithElementTarget(source.negativeTarget, action.id, true);
                    if (aem != null)
                    {
                        uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Negative);
                    }

                    // Handle full-axis source
                }
                else
                {
                    // A full-axis sources has just a single full target.

                    // Full Target
                    aem = controllerMap.GetFirstElementMapWithElementTarget(source.fullTarget, action.id, true);
                    if (aem != null)
                    {
                        // a full target was mapped

                        uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Full);
                    }
                    else
                    {
                        // no full mapping was found, look for separate positive/negative mappings

                        // Positive side
                        aem = controllerMap.GetFirstElementMapWithElementTarget(
                            new ControllerElementTarget(source.fullTarget)
                        {
                            axisRange = AxisRange.Positive
                        },
                            action.id,
                            true
                            );
                        if (aem != null)
                        {
                            uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Positive);
                        }

                        // Negative side
                        aem = controllerMap.GetFirstElementMapWithElementTarget(
                            new ControllerElementTarget(source.fullTarget)
                        {
                            axisRange = AxisRange.Negative
                        },
                            action.id,
                            true
                            );
                        if (aem != null)
                        {
                            uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Negative);
                        }
                    }
                }

                // Handle Button-type Template Element
            }
            else if (element.source.type == ControllerTemplateElementSourceType.Button)
            {
                // Cast the source to an button source
                IControllerTemplateButtonSource source = (element.source as IControllerTemplateButtonSource);

                // Target
                aem = controllerMap.GetFirstElementMapWithElementTarget(source.target, action.id, true);
                if (aem != null)
                {
                    uiElement.SetLabel(aem.actionDescriptiveName, AxisRange.Full);
                }
            }
        }