Esempio n. 1
0
 // May generate garbage.
 public static void SetUsage(InputDevice device, InternedString usage)
 {
     s_Manager.SetUsage(device, usage);
 }
Esempio n. 2
0
        private UnityEngine.InputSystem.Controls.Vector2Control Initialize_ctrlMousescroll(InternedString kVector2Layout, InputControl parent)
        {
            var ctrlMousescroll = new UnityEngine.InputSystem.Controls.Vector2Control();

            ctrlMousescroll.Setup()
            .At(this, 2)
            .WithParent(parent)
            .WithChildren(17, 2)
            .WithName("scroll")
            .WithDisplayName("Scroll")
            .WithLayout(kVector2Layout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1447379762),
                byteOffset = 16,
                bitOffset  = 0,
                sizeInBits = 64
            })
            .Finish();
            return(ctrlMousescroll);
        }
Esempio n. 3
0
        private UnityEngine.InputSystem.Controls.AxisControl Initialize_ctrlMousescrollx(InternedString kAxisLayout, InputControl parent)
        {
            var ctrlMousescrollx = new UnityEngine.InputSystem.Controls.AxisControl();

            ctrlMousescrollx.Setup()
            .At(this, 17)
            .WithParent(parent)
            .WithName("x")
            .WithDisplayName("Scroll Left/Right")
            .WithShortDisplayName("Scroll Left/Right")
            .WithLayout(kAxisLayout)
            .WithUsages(2, 1)
            .WithAliases(0, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1179407392),
                byteOffset = 16,
                bitOffset  = 0,
                sizeInBits = 32
            })
            .Finish();
            return(ctrlMousescrollx);
        }
Esempio n. 4
0
        private UnityEngine.InputSystem.Controls.AxisControl Initialize_ctrlMouseradiusy(InternedString kAxisLayout, InputControl parent)
        {
            var ctrlMouseradiusy = new UnityEngine.InputSystem.Controls.AxisControl();

            ctrlMouseradiusy.Setup()
            .At(this, 20)
            .WithParent(parent)
            .WithName("y")
            .WithDisplayName("Radius Y")
            .WithShortDisplayName("Radius Y")
            .WithLayout(kAxisLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1179407392),
                byteOffset = 44,
                bitOffset  = 0,
                sizeInBits = 32
            })
            .Finish();
            return(ctrlMouseradiusy);
        }
Esempio n. 5
0
        private UnityEngine.InputSystem.Controls.Vector2Control Initialize_ctrlMouseradius(InternedString kVector2Layout, InputControl parent)
        {
            var ctrlMouseradius = new UnityEngine.InputSystem.Controls.Vector2Control();

            ctrlMouseradius.Setup()
            .At(this, 10)
            .WithParent(parent)
            .WithChildren(19, 2)
            .WithName("radius")
            .WithDisplayName("Radius")
            .WithLayout(kVector2Layout)
            .WithUsages(9, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1447379762),
                byteOffset = 40,
                bitOffset  = 0,
                sizeInBits = 64
            })
            .Finish();
            return(ctrlMouseradius);
        }
Esempio n. 6
0
        private UnityEngine.InputSystem.Controls.IntegerControl Initialize_ctrlMouseclickCount(InternedString kIntegerLayout, InputControl parent)
        {
            var ctrlMouseclickCount = new UnityEngine.InputSystem.Controls.IntegerControl();

            ctrlMouseclickCount.Setup()
            .At(this, 12)
            .WithParent(parent)
            .WithName("clickCount")
            .WithDisplayName("Click Count")
            .WithLayout(kIntegerLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1431521364),
                byteOffset = 28,
                bitOffset  = 0,
                sizeInBits = 16
            })
            .Finish();
            return(ctrlMouseclickCount);
        }
        internal void SetupWithDescription(InternedString layout, InputDeviceDescription deviceDescription, InternedString variants)
        {
            InstantiateLayout(layout, variants, new InternedString(), null, null);
            FinalizeControlHierarchy();

            if (!deviceDescription.empty)
            {
                m_Device.m_Description = deviceDescription;
            }

            m_Device.CallFinishSetupRecursive(this);
        }
Esempio n. 8
0
        private UnityEngine.InputSystem.Controls.ButtonControl Initialize_ctrlMousebackButton(InternedString kButtonLayout, InputControl parent)
        {
            var ctrlMousebackButton = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlMousebackButton.Setup()
            .At(this, 8)
            .WithParent(parent)
            .WithName("backButton")
            .WithDisplayName("Back")
            .WithLayout(kButtonLayout)
            .WithUsages(7, 1)
            .IsButton(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 24,
                bitOffset  = 4,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();
            return(ctrlMousebackButton);
        }
        private void AddChildControls(InputControlLayout layout, InternedString variants, InputControl parent, ReadOnlyArray <InputControl>?existingChildren, ref bool haveChildrenUsingStateFromOtherControls)
        {
            var controlLayouts = layout.m_Controls;

            if (controlLayouts == null)
            {
                return;
            }

            // Find out how many direct children we will add.
            var childCount = 0;
            var haveControlLayoutWithPath = false;

            for (var i = 0; i < controlLayouts.Length; ++i)
            {
                ////REVIEW: I'm not sure this is good enough. ATM if you have a control layout with
                ////        name "foo" and one with name "foo/bar", then the latter is taken as an override
                ////        but the former isn't. However, whether it has a slash in the path or not shouldn't
                ////        matter. If a control layout of the same name already exists, it should be
                ////        considered an override, if not, it shouldn't.
                // Not a new child if it's a layout reaching in to the hierarchy to modify
                // an existing child.
                if (controlLayouts[i].isModifyingChildControlByPath)
                {
                    if (controlLayouts[i].isArray)
                    {
                        throw new NotSupportedException(string.Format(
                                                            "Control '{0}' in layout '{1}' is modifying the child of another control but is marked as an array",
                                                            controlLayouts[i].name, layout.name));
                    }

                    haveControlLayoutWithPath = true;
                    InsertChildControlOverrides(parent, ref controlLayouts[i]);
                    continue;
                }

                // Skip if variants don't match.
                if (!controlLayouts[i].variants.IsEmpty() &&
                    !StringHelpers.CharacterSeparatedListsHaveAtLeastOneCommonElement(controlLayouts[i].variants,
                                                                                      variants, InputControlLayout.kListSeparator))
                {
                    continue;
                }

                if (controlLayouts[i].isArray)
                {
                    childCount += controlLayouts[i].arraySize;
                }
                else
                {
                    ++childCount;
                }
            }

            // Add room for us in the device's child array.
            var firstChildIndex = ArrayHelpers.GrowBy(ref m_Device.m_ChildrenForEachControl, childCount);

            // Add controls from all control layouts except the ones that have
            // paths in them.
            var childIndex = firstChildIndex;

            for (var i = 0; i < controlLayouts.Length; ++i)
            {
                var controlLayout = controlLayouts[i];

                // Skip control layouts that don't add controls but rather modify child
                // controls of other controls added by the layout. We do a second pass
                // to apply their settings.
                if (controlLayout.isModifyingChildControlByPath)
                {
                    continue;
                }

                // If the control is part of a variant, skip it if it isn't in the variants we're
                // looking for.
                if (!controlLayout.variants.IsEmpty() &&
                    !StringHelpers.CharacterSeparatedListsHaveAtLeastOneCommonElement(controlLayout.variants, variants,
                                                                                      InputControlLayout.kListSeparator))
                {
                    continue;
                }

                // If it's an array, add a control for each array element.
                if (controlLayout.isArray)
                {
                    for (var n = 0; n < controlLayout.arraySize; ++n)
                    {
                        var name    = controlLayout.name + n;
                        var control = AddChildControl(layout, variants, parent, existingChildren, ref haveChildrenUsingStateFromOtherControls,
                                                      ref controlLayout, ref childIndex, nameOverride: name);

                        // Adjust offset, if the control uses explicit offsets.
                        if (control.m_StateBlock.byteOffset != InputStateBlock.kInvalidOffset)
                        {
                            control.m_StateBlock.byteOffset = (uint)n * control.m_StateBlock.alignedSizeInBytes;
                        }
                    }
                }
                else
                {
                    AddChildControl(layout, variants, parent, existingChildren, ref haveChildrenUsingStateFromOtherControls,
                                    ref controlLayout, ref childIndex);
                }
            }

            // Install child array on parent. We will later patch up the array
            // reference again as we finalize the hierarchy. However, the reference
            // will point to a valid child array all the same even while we are
            // constructing the hierarchy.
            //
            // NOTE: It's important to do this *after* the loop above where we call InstantiateLayout for each child
            //       as each child may end up moving the m_ChildrenForEachControl array around.
            parent.m_ChildrenReadOnly = new ReadOnlyArray <InputControl>(m_Device.m_ChildrenForEachControl, firstChildIndex, childCount);

            ////TODO: replace the entire post-creation modification logic here with using m_ChildControlOverrides
            ////      (note that we have to *merge* into the table; if there's already overrides, only replace properties that haven't been set)
            ////      (however, this will also require moving the child insertion logic somewhere else)

            // Apply control modifications from control layouts with paths.
            if (haveControlLayoutWithPath)
            {
                for (var i = 0; i < controlLayouts.Length; ++i)
                {
                    var controlLayout = controlLayouts[i];
                    if (!controlLayout.isModifyingChildControlByPath)
                    {
                        continue;
                    }

                    // If the control is part of a variants, skip it if it isn't the variants we're
                    // looking for.
                    if (!controlLayout.variants.IsEmpty() && controlLayout.variants != variants)
                    {
                        continue;
                    }

                    ModifyChildControl(layout, variants, parent, ref haveChildrenUsingStateFromOtherControls,
                                       ref controlLayout);
                }
            }
        }
        private InputControl AddChildControl(InputControlLayout layout, InternedString variants, InputControl parent,
                                             ReadOnlyArray <InputControl>?existingChildren, ref bool haveChildrenUsingStateFromOtherControls,
                                             ref InputControlLayout.ControlItem controlItem, ref int childIndex, string nameOverride = null)
        {
            var    name          = nameOverride ?? controlItem.name;
            var    nameLowerCase = name.ToLower();
            var    nameInterned  = new InternedString(name);
            string path          = null;

            ////REVIEW: can we check this in InputControlLayout instead?
            if (string.IsNullOrEmpty(controlItem.layout))
            {
                throw new Exception(string.Format("Layout has not been set on control '{0}' in '{1}'",
                                                  controlItem.name, layout.name));
            }

            // See if there is an override for the control.
            InputControlLayout.ControlItem?controlOverride = null;
            if (m_ChildControlOverrides != null)
            {
                path = string.Format("{0}/{1}", parent.path, name);
                var pathLowerCase = path.ToLower();

                InputControlLayout.ControlItem match;
                if (m_ChildControlOverrides.TryGetValue(pathLowerCase, out match))
                {
                    controlOverride = match;
                }
            }

            // Get name of layout to use for control.
            var layoutName = controlItem.layout;

            if (controlOverride != null && !controlOverride.Value.layout.IsEmpty())
            {
                layoutName = controlOverride.Value.layout;
            }

            // See if we have an existing control that we might be able to re-use.
            InputControl existingControl = null;

            if (existingChildren != null)
            {
                var existingChildCount = existingChildren.Value.Count;
                for (var n = 0; n < existingChildCount; ++n)
                {
                    var existingChild = existingChildren.Value[n];
                    if (existingChild.layout == layoutName &&
                        existingChild.name.ToLower() == nameLowerCase)
                    {
                        existingControl = existingChild;
                        break;
                    }
                }
            }

            // Create control.
            InputControl control;

            try
            {
                control = InstantiateLayout(layoutName, variants, nameInterned, parent, existingControl);
            }
            catch (InputControlLayout.LayoutNotFoundException exception)
            {
                // Throw better exception that gives more info.
                throw new Exception(
                          string.Format("Cannot find layout '{0}' used in control '{1}' of layout '{2}'",
                                        exception.layout, name, layout.name),
                          exception);
            }

            // Add to array.
            m_Device.m_ChildrenForEachControl[childIndex] = control;
            ++childIndex;

            // Set display name.
            control.m_DisplayNameFromLayout = controlItem.displayName;

            // Set flags.
            control.m_IsNoisy = controlItem.isNoisy;

            // Pass state block config on to control.
            var usesStateFromOtherControl = !string.IsNullOrEmpty(controlItem.useStateFrom);

            if (!usesStateFromOtherControl)
            {
                control.m_StateBlock.byteOffset = controlItem.offset;
                if (controlItem.bit != InputStateBlock.kInvalidOffset)
                {
                    control.m_StateBlock.bitOffset = controlItem.bit;
                }
                if (controlItem.sizeInBits != 0)
                {
                    control.m_StateBlock.sizeInBits = controlItem.sizeInBits;
                }
                if (controlItem.format != 0)
                {
                    SetFormat(control, controlItem);
                }
            }
            else
            {
                // Mark controls that don't have state blocks of their own but rather get their
                // blocks from other controls by setting their state size to kInvalidOffset.
                control.m_StateBlock.sizeInBits         = kSizeForControlUsingStateFromOtherControl;
                haveChildrenUsingStateFromOtherControls = true;
            }

            ////REVIEW: the constant appending to m_UsagesForEachControl and m_AliasesForEachControl may lead to a lot
            ////        of successive re-allocations

            // Add usages.
            var usages = controlOverride != null ? controlOverride.Value.usages : controlItem.usages;

            if (usages.Count > 0)
            {
                var usageCount = usages.Count;
                var usageIndex =
                    ArrayHelpers.AppendToImmutable(ref m_Device.m_UsagesForEachControl, usages.m_Array);
                control.m_UsagesReadOnly =
                    new ReadOnlyArray <InternedString>(m_Device.m_UsagesForEachControl, usageIndex, usageCount);

                ArrayHelpers.GrowBy(ref m_Device.m_UsageToControl, usageCount);
                for (var n = 0; n < usageCount; ++n)
                {
                    m_Device.m_UsageToControl[usageIndex + n] = control;
                }
            }

            // Add aliases.
            if (controlItem.aliases.Count > 0)
            {
                var aliasCount = controlItem.aliases.Count;
                var aliasIndex =
                    ArrayHelpers.AppendToImmutable(ref m_Device.m_AliasesForEachControl, controlItem.aliases.m_Array);
                control.m_AliasesReadOnly =
                    new ReadOnlyArray <InternedString>(m_Device.m_AliasesForEachControl, aliasIndex, aliasCount);
            }

            // Set parameters.
            if (controlItem.parameters.Count > 0)
            {
                SetParameters(control, controlItem.parameters);
            }

            // Add processors.
            if (controlItem.processors.Count > 0)
            {
                AddProcessors(control, ref controlItem, layout.name);
            }

            return(control);
        }
        private InputControl InstantiateLayout(InputControlLayout layout, InternedString variants, InternedString name, InputControl parent, InputControl existingControl)
        {
            InputControl control;

            // If we have an existing control, see whether it's usable.
            if (existingControl != null && existingControl.layout == layout.name && existingControl.GetType() == layout.type)
            {
                control = existingControl;

                ////FIXME: the re-use path probably has some data that could stick around when it shouldn't
                control.m_UsagesReadOnly = new ReadOnlyArray <InternedString>();
                control.ClearProcessors();
            }
            else
            {
                Debug.Assert(layout.type != null);

                // No, so create a new control.
                var controlObject = Activator.CreateInstance(layout.type);
                control = controlObject as InputControl;
                if (control == null)
                {
                    throw new Exception(string.Format("Type '{0}' referenced by layout '{1}' is not an InputControl",
                                                      layout.type.Name, layout.name));
                }
            }

            // If it's a device, perform some extra work specific to the control
            // hierarchy root.
            var controlAsDevice = control as InputDevice;

            if (controlAsDevice != null)
            {
                if (parent != null)
                {
                    throw new Exception(string.Format(
                                            "Cannot instantiate device layout '{0}' as child of '{1}'; devices must be added at root",
                                            layout.name, parent.path));
                }

                m_Device = controlAsDevice;
                m_Device.m_StateBlock.byteOffset = 0;
                m_Device.m_StateBlock.format     = layout.stateFormat;

                // If we have an existing device, we'll start the various control arrays
                // from scratch. Note that all the controls still refer to the existing
                // arrays and so we can iterate children, for example, just fine while
                // we are rebuilding the control hierarchy.
                m_Device.m_AliasesForEachControl  = null;
                m_Device.m_ChildrenForEachControl = null;
                m_Device.m_UsagesForEachControl   = null;
                m_Device.m_UsageToControl         = null;

                // But we preserve IDs and descriptions of existing devices.
                if (existingControl != null)
                {
                    var existingDevice = (InputDevice)existingControl;
                    m_Device.m_Id          = existingDevice.m_Id;
                    m_Device.m_Description = existingDevice.m_Description;
                }

                if (layout.m_UpdateBeforeRender == true)
                {
                    m_Device.m_Flags |= InputDevice.Flags.UpdateBeforeRender;
                }
            }
            else if (parent == null)
            {
                // Someone did "new InputDeviceBuilder(...)" with a control layout.
                // We don't support creating control hierarchies without a device at the root.
                throw new InvalidOperationException(
                          string.Format(
                              "Toplevel layout used with InputDeviceBuilder must be a device layout; '{0}' is a control layout",
                              layout.name));
            }

            // Name defaults to name of layout.
            if (name.IsEmpty())
            {
                name = layout.name;

                // If there's a namespace in the layout name, snip it out.
                var indexOfLastColon = name.ToString().LastIndexOf(':');
                if (indexOfLastColon != -1)
                {
                    name = new InternedString(name.ToString().Substring(indexOfLastColon + 1));
                }
            }

            // Variant defaults to variants of layout.
            if (variants.IsEmpty())
            {
                variants = layout.variants;

                if (variants.IsEmpty())
                {
                    variants = InputControlLayout.DefaultVariant;
                }
            }

            control.m_Name = name;
            control.m_DisplayNameFromLayout = layout.m_DisplayName;
            control.m_Layout   = layout.name;
            control.m_Variants = variants;
            control.m_Parent   = parent;
            control.m_Device   = m_Device;

            // Create children and configure their settings from our
            // layout values.
            var haveChildrenUsingStateFromOtherControl = false;

            try
            {
                // Pass list of existing control on to function as we may have decided to not
                // actually reuse the existing control (and thus control.m_ChildrenReadOnly will
                // now be blank) but still want crawling down the hierarchy to preserve existing
                // controls where possible.
                AddChildControls(layout, variants, control,
                                 existingControl != null ? existingControl.m_ChildrenReadOnly : (ReadOnlyArray <InputControl>?)null,
                                 ref haveChildrenUsingStateFromOtherControl);
            }
            catch
            {
                ////TODO: remove control from collection and rethrow
                throw;
            }

            // Come up with a layout for our state.
            ComputeStateLayout(control);

            // Finally, if we have child controls that take their state blocks from other
            // controls, assign them their blocks now.
            if (haveChildrenUsingStateFromOtherControl)
            {
                foreach (var controlLayout in layout.controls)
                {
                    if (string.IsNullOrEmpty(controlLayout.useStateFrom))
                    {
                        continue;
                    }

                    var child = TryGetControl(control, controlLayout.name);
                    Debug.Assert(child != null);

                    // Find the referenced control.
                    var referencedControl = TryGetControl(control, controlLayout.useStateFrom);
                    if (referencedControl == null)
                    {
                        throw new Exception(
                                  string.Format(
                                      "Cannot find control '{0}' referenced in 'useStateFrom' of control '{1}' in layout '{2}'",
                                      controlLayout.useStateFrom, controlLayout.name, layout.name));
                    }

                    // Copy its state settings.
                    child.m_StateBlock = referencedControl.m_StateBlock;

                    // At this point, all byteOffsets are relative to parents so we need to
                    // walk up the referenced control's parent chain and add offsets until
                    // we are at the same level that we are at.
                    for (var parentInChain = referencedControl.parent; parentInChain != control; parentInChain = parentInChain.parent)
                    {
                        child.m_StateBlock.byteOffset += parentInChain.m_StateBlock.byteOffset;
                    }
                }
            }

            return(control);
        }
        private InputControl InstantiateLayout(InternedString layout, InternedString variants, InternedString name, InputControl parent, InputControl existingControl)
        {
            // Look up layout by name.
            var layoutInstance = FindOrLoadLayout(layout);

            // Create control hierarchy.
            return(InstantiateLayout(layoutInstance, variants, name, parent, existingControl));
        }
Esempio n. 13
0
 public static void RemoveUsage(InputDevice device, InternedString usage)
 {
     throw new NotImplementedException();
 }
Esempio n. 14
0
        private UnityEngine.InputSystem.Controls.ButtonControl Initialize_ctrlMousepress(InternedString kButtonLayout, InputControl parent)
        {
            var ctrlMousepress = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlMousepress.Setup()
            .At(this, 3)
            .WithParent(parent)
            .WithName("press")
            .WithDisplayName("Press")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .IsButton(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 24,
                bitOffset  = 0,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();
            return(ctrlMousepress);
        }
        private void ModifyChildControl(InputControlLayout layout, InternedString variants, InputControl parent,
                                        ref bool haveChildrenUsingStateFromOtherControls,
                                        ref InputControlLayout.ControlItem controlItem)
        {
            ////TODO: support arrays (we may modify an entire array in bulk)

            // Controls layout themselves as we come back up the hierarchy. However, when we
            // apply layout modifications reaching *into* the hierarchy, we need to retrigger
            // layouting on their parents.
            var haveChangedLayoutOfParent = false;

            // Find the child control.
            var child = TryGetControl(parent, controlItem.name);

            if (child == null)
            {
                // We're adding a child somewhere in the existing hierarchy. This is a tricky
                // case as we have to potentially shift indices around in the hierarchy to make
                // room for the new control.

                ////TODO: this path does not support recovering existing controls? does it matter?

                child = InsertChildControl(layout, variants, parent,
                                           ref haveChildrenUsingStateFromOtherControls, ref controlItem);
                haveChangedLayoutOfParent = true;
            }
            else
            {
                // Apply modifications.
                if (controlItem.sizeInBits != 0 &&
                    child.m_StateBlock.sizeInBits != controlItem.sizeInBits)
                {
                    child.m_StateBlock.sizeInBits = controlItem.sizeInBits;
                }
                if (controlItem.format != 0 && child.m_StateBlock.format != controlItem.format)
                {
                    SetFormat(child, controlItem);
                    haveChangedLayoutOfParent = true;
                }
                ////REVIEW: ATM, when you move a child with a fixed offset, we only move the child
                ////        and don't move the parent or siblings. What this means is that if you move
                ////        leftStick/x, for example, leftStick stays put. ATM you have to move *all*
                ////        controls that are part of a chain manually. Not sure what the best behavior
                ////        is. If we opt to move parents along with children, we have to make sure we
                ////        are not colliding with any other relocations of children (e.g. if you move
                ////        both leftStick/x and leftStick/y, leftStick itself should move only once and
                ////        not at all if there indeed is a leftStick control layout with an offset;
                ////        so, it'd get quite complicated)
                if (controlItem.offset != InputStateBlock.kInvalidOffset)
                {
                    child.m_StateBlock.byteOffset = controlItem.offset;
                }
                if (controlItem.bit != InputStateBlock.kInvalidOffset)
                {
                    child.m_StateBlock.bitOffset = controlItem.bit;
                }
                if (controlItem.processors.Count > 0)
                {
                    AddProcessors(child, ref controlItem, layout.name);
                }
                ////REVIEW: ATM parameters applied using this path add on top instead of just overriding existing parameters
                if (controlItem.parameters.Count > 0)
                {
                    SetParameters(child, controlItem.parameters);
                }
                if (!string.IsNullOrEmpty(controlItem.displayName))
                {
                    child.m_DisplayNameFromLayout = controlItem.displayName;
                }

                ////TODO: other modifications
            }

            // Apply layout change.
            ////REVIEW: not sure what's better here; trigger this immediately means we may trigger
            ////        it a number of times on the same parent but doing it as a final pass would
            ////        require either collecting the necessary parents or doing another pass through
            ////        the list of control layouts
            if (haveChangedLayoutOfParent && !ReferenceEquals(child.parent, parent))
            {
                ComputeStateLayout(child.parent);
            }
        }
Esempio n. 16
0
        public FastMouse()
        {
            var builder = this.Setup(21, 10, 2)
                          .WithName("Mouse")
                          .WithDisplayName("Mouse")
                          .WithChildren(0, 13)
                          .WithLayout(new InternedString("Mouse"))
                          .WithStateBlock(new InputStateBlock {
                format = new FourCC(1297044819), sizeInBits = 392
            });

            var kVector2Layout = new InternedString("Vector2");
            var kButtonLayout  = new InternedString("Button");
            var kAxisLayout    = new InternedString("Axis");
            var kDigitalLayout = new InternedString("Digital");
            var kIntegerLayout = new InternedString("Integer");

            // /Mouse/position
            var ctrlMouseposition = Initialize_ctrlMouseposition(kVector2Layout, this);

            // /Mouse/delta
            var ctrlMousedelta = Initialize_ctrlMousedelta(kVector2Layout, this);

            // /Mouse/scroll
            var ctrlMousescroll = Initialize_ctrlMousescroll(kVector2Layout, this);

            // /Mouse/press
            var ctrlMousepress = Initialize_ctrlMousepress(kButtonLayout, this);

            // /Mouse/leftButton
            var ctrlMouseleftButton = Initialize_ctrlMouseleftButton(kButtonLayout, this);

            // /Mouse/rightButton
            var ctrlMouserightButton = Initialize_ctrlMouserightButton(kButtonLayout, this);

            // /Mouse/middleButton
            var ctrlMousemiddleButton = Initialize_ctrlMousemiddleButton(kButtonLayout, this);

            // /Mouse/forwardButton
            var ctrlMouseforwardButton = Initialize_ctrlMouseforwardButton(kButtonLayout, this);

            // /Mouse/backButton
            var ctrlMousebackButton = Initialize_ctrlMousebackButton(kButtonLayout, this);

            // /Mouse/pressure
            var ctrlMousepressure = Initialize_ctrlMousepressure(kAxisLayout, this);

            // /Mouse/radius
            var ctrlMouseradius = Initialize_ctrlMouseradius(kVector2Layout, this);

            // /Mouse/pointerId
            var ctrlMousepointerId = Initialize_ctrlMousepointerId(kDigitalLayout, this);

            // /Mouse/clickCount
            var ctrlMouseclickCount = Initialize_ctrlMouseclickCount(kIntegerLayout, this);

            // /Mouse/position/x
            var ctrlMousepositionx = Initialize_ctrlMousepositionx(kAxisLayout, ctrlMouseposition);

            // /Mouse/position/y
            var ctrlMousepositiony = Initialize_ctrlMousepositiony(kAxisLayout, ctrlMouseposition);

            // /Mouse/delta/x
            var ctrlMousedeltax = Initialize_ctrlMousedeltax(kAxisLayout, ctrlMousedelta);

            // /Mouse/delta/y
            var ctrlMousedeltay = Initialize_ctrlMousedeltay(kAxisLayout, ctrlMousedelta);

            // /Mouse/scroll/x
            var ctrlMousescrollx = Initialize_ctrlMousescrollx(kAxisLayout, ctrlMousescroll);

            // /Mouse/scroll/y
            var ctrlMousescrolly = Initialize_ctrlMousescrolly(kAxisLayout, ctrlMousescroll);

            // /Mouse/radius/x
            var ctrlMouseradiusx = Initialize_ctrlMouseradiusx(kAxisLayout, ctrlMouseradius);

            // /Mouse/radius/y
            var ctrlMouseradiusy = Initialize_ctrlMouseradiusy(kAxisLayout, ctrlMouseradius);

            // Usages.
            builder.WithControlUsage(0, new InternedString("Point"), ctrlMouseposition);
            builder.WithControlUsage(1, new InternedString("Secondary2DMotion"), ctrlMousedelta);
            builder.WithControlUsage(2, new InternedString("ScrollHorizontal"), ctrlMousescrollx);
            builder.WithControlUsage(3, new InternedString("ScrollVertical"), ctrlMousescrolly);
            builder.WithControlUsage(4, new InternedString("PrimaryAction"), ctrlMouseleftButton);
            builder.WithControlUsage(5, new InternedString("SecondaryAction"), ctrlMouserightButton);
            builder.WithControlUsage(6, new InternedString("Forward"), ctrlMouseforwardButton);
            builder.WithControlUsage(7, new InternedString("Back"), ctrlMousebackButton);
            builder.WithControlUsage(8, new InternedString("Pressure"), ctrlMousepressure);
            builder.WithControlUsage(9, new InternedString("Radius"), ctrlMouseradius);

            // Aliases.
            builder.WithControlAlias(0, new InternedString("horizontal"));
            builder.WithControlAlias(1, new InternedString("vertical"));

            // Control getters/arrays.
            this.scroll         = ctrlMousescroll;
            this.leftButton     = ctrlMouseleftButton;
            this.middleButton   = ctrlMousemiddleButton;
            this.rightButton    = ctrlMouserightButton;
            this.backButton     = ctrlMousebackButton;
            this.forwardButton  = ctrlMouseforwardButton;
            this.clickCount     = ctrlMouseclickCount;
            this.position       = ctrlMouseposition;
            this.delta          = ctrlMousedelta;
            this.radius         = ctrlMouseradius;
            this.pressure       = ctrlMousepressure;
            this.press          = ctrlMousepress;
            ctrlMouseposition.x = ctrlMousepositionx;
            ctrlMouseposition.y = ctrlMousepositiony;
            ctrlMousedelta.x    = ctrlMousedeltax;
            ctrlMousedelta.y    = ctrlMousedeltay;
            ctrlMousescroll.x   = ctrlMousescrollx;
            ctrlMousescroll.y   = ctrlMousescrolly;
            ctrlMouseradius.x   = ctrlMouseradiusx;
            ctrlMouseradius.y   = ctrlMouseradiusy;

            // State offset to control index map.
            builder.WithStateOffsetToControlIndexMap(new uint[]
            {
                32781u, 16809998u, 33587215u, 50364432u, 67141649u, 83918866u, 100664323u, 100664324u, 101188613u, 101712902u
                , 102237191u, 102761480u, 117456908u, 134250505u, 167804947u, 184582164u, 201327627u
            });

            builder.Finish();
        }
Esempio n. 17
0
        private void SetupInputControl()
        {
            Debug.Assert(m_Control == null);
            Debug.Assert(m_NextControlOnDevice == null);
            Debug.Assert(!m_InputEventPtr.valid);

            // Nothing to do if we don't have a control path.
            if (string.IsNullOrEmpty(m_ControlPath))
            {
                return;
            }

            // Determine what type of device to work with.
            var layoutName = InputControlPath.TryGetDeviceLayout(m_ControlPath);

            if (layoutName == null)
            {
                Debug.LogError(
                    string.Format(
                        "Cannot determine device layout to use based on control path '{0}' used in {1} component",
                        m_ControlPath, GetType().Name), this);
                return;
            }

            // Try to find existing on-screen device that matches.
            var internedLayoutName = new InternedString(layoutName);
            var deviceInfoIndex    = -1;

            for (var i = 0; i < s_OnScreenDevices.length; ++i)
            {
                if (s_OnScreenDevices[i].device.m_Layout == internedLayoutName)
                {
                    deviceInfoIndex = i;
                    break;
                }
            }

            // If we don't have a matching one, create a new one.
            InputDevice device;

            if (deviceInfoIndex == -1)
            {
                // Try to create device.
                try
                {
                    device = InputSystem.AddDevice(layoutName);
                }
                catch (Exception exception)
                {
                    Debug.LogError(string.Format("Could not create device with layout '{0}' used in '{1}' component", layoutName,
                                                 GetType().Name));
                    Debug.LogException(exception);
                    return;
                }

                // Create event buffer.
                InputEventPtr eventPtr;
                var           buffer = StateEvent.From(device, out eventPtr, Allocator.Persistent);

                // Add to list.
                deviceInfoIndex = s_OnScreenDevices.Append(new OnScreenDeviceInfo
                {
                    eventPtr = eventPtr,
                    buffer   = buffer,
                    device   = device,
                });
            }
            else
            {
                device = s_OnScreenDevices[deviceInfoIndex].device;
            }

            // Try to find control on device.
            m_Control = InputControlPath.TryFindControl(device, m_ControlPath);
            if (m_Control == null)
            {
                Debug.LogError(
                    string.Format(
                        "Cannot find control with path '{0}' on device of type '{1}' referenced by component '{2}'",
                        m_ControlPath, layoutName, GetType().Name), this);

                // Remove the device, if we just created one.
                if (s_OnScreenDevices[deviceInfoIndex].firstControl == null)
                {
                    s_OnScreenDevices[deviceInfoIndex].Destroy();
                    s_OnScreenDevices.RemoveAt(deviceInfoIndex);
                }

                return;
            }
            m_InputEventPtr = s_OnScreenDevices[deviceInfoIndex].eventPtr;

            // We have all we need. Permanently add us.
            s_OnScreenDevices[deviceInfoIndex] =
                s_OnScreenDevices[deviceInfoIndex].AddControl(this);
        }
Esempio n. 18
0
        private UnityEngine.InputSystem.Controls.AxisControl Initialize_ctrlMousepressure(InternedString kAxisLayout, InputControl parent)
        {
            var ctrlMousepressure = new UnityEngine.InputSystem.Controls.AxisControl();

            ctrlMousepressure.Setup()
            .At(this, 9)
            .WithParent(parent)
            .WithName("pressure")
            .WithDisplayName("Pressure")
            .WithLayout(kAxisLayout)
            .WithUsages(8, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1179407392),
                byteOffset = 32,
                bitOffset  = 0,
                sizeInBits = 32
            })
            .WithDefaultState(1)
            .Finish();
            return(ctrlMousepressure);
        }
        public FastDualShock4GamepadHID()
        {
            var builder = this.Setup(37, 11, 8)
                          .WithName("DualShock4GamepadHID")
                          .WithDisplayName("PS4 Controller")
                          .WithChildren(0, 19)
                          .WithLayout(new InternedString("DualShock4GamepadHID"))
                          .WithStateBlock(new InputStateBlock {
                format = new FourCC(1212761120), sizeInBits = 80
            });

            var kStickLayout          = new InternedString("Stick");
            var kDpadLayout           = new InternedString("Dpad");
            var kButtonLayout         = new InternedString("Button");
            var kAxisLayout           = new InternedString("Axis");
            var kDpadAxisLayout       = new InternedString("DpadAxis");
            var kDiscreteButtonLayout = new InternedString("DiscreteButton");

            // /DualShock4GamepadHID/leftStick
            var ctrlDualShock4GamepadHIDleftStick = new UnityEngine.InputSystem.Controls.StickControl();

            ctrlDualShock4GamepadHIDleftStick.Setup()
            .At(this, 0)
            .WithParent(this)
            .WithChildren(19, 6)
            .WithName("leftStick")
            .WithDisplayName("Left Stick")
            .WithShortDisplayName("LS")
            .WithLayout(kStickLayout)
            .WithUsages(0, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1447244354),
                byteOffset = 1,
                bitOffset  = 0,
                sizeInBits = 16
            })
            .WithProcessor <InputProcessor <UnityEngine.Vector2>, UnityEngine.Vector2>(new UnityEngine.InputSystem.Processors.StickDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick
            var ctrlDualShock4GamepadHIDrightStick = new UnityEngine.InputSystem.Controls.StickControl();

            ctrlDualShock4GamepadHIDrightStick.Setup()
            .At(this, 1)
            .WithParent(this)
            .WithChildren(25, 6)
            .WithName("rightStick")
            .WithDisplayName("Right Stick")
            .WithShortDisplayName("RS")
            .WithLayout(kStickLayout)
            .WithUsages(1, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1447244354),
                byteOffset = 3,
                bitOffset  = 0,
                sizeInBits = 16
            })
            .WithProcessor <InputProcessor <UnityEngine.Vector2>, UnityEngine.Vector2>(new UnityEngine.InputSystem.Processors.StickDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/dpad
            var ctrlDualShock4GamepadHIDdpad = new UnityEngine.InputSystem.Controls.DpadControl();

            ctrlDualShock4GamepadHIDdpad.Setup()
            .At(this, 2)
            .WithParent(this)
            .WithChildren(31, 6)
            .WithName("dpad")
            .WithDisplayName("D-Pad")
            .WithLayout(kDpadLayout)
            .WithUsages(2, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .WithDefaultState(8)
            .Finish();

            // /DualShock4GamepadHID/buttonWest
            var ctrlDualShock4GamepadHIDbuttonWest = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDbuttonWest.Setup()
            .At(this, 3)
            .WithParent(this)
            .WithName("buttonWest")
            .WithDisplayName("Square")
            .WithShortDisplayName("Square")
            .WithLayout(kButtonLayout)
            .WithUsages(3, 1)
            .WithAliases(0, 2)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 4,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/buttonSouth
            var ctrlDualShock4GamepadHIDbuttonSouth = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDbuttonSouth.Setup()
            .At(this, 4)
            .WithParent(this)
            .WithName("buttonSouth")
            .WithDisplayName("Cross")
            .WithShortDisplayName("Cross")
            .WithLayout(kButtonLayout)
            .WithUsages(4, 2)
            .WithAliases(2, 2)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 5,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/buttonEast
            var ctrlDualShock4GamepadHIDbuttonEast = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDbuttonEast.Setup()
            .At(this, 5)
            .WithParent(this)
            .WithName("buttonEast")
            .WithDisplayName("Circle")
            .WithShortDisplayName("Circle")
            .WithLayout(kButtonLayout)
            .WithUsages(6, 2)
            .WithAliases(4, 2)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 6,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/buttonNorth
            var ctrlDualShock4GamepadHIDbuttonNorth = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDbuttonNorth.Setup()
            .At(this, 6)
            .WithParent(this)
            .WithName("buttonNorth")
            .WithDisplayName("Triangle")
            .WithShortDisplayName("Triangle")
            .WithLayout(kButtonLayout)
            .WithAliases(6, 2)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 7,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/leftShoulder
            var ctrlDualShock4GamepadHIDleftShoulder = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDleftShoulder.Setup()
            .At(this, 7)
            .WithParent(this)
            .WithName("leftShoulder")
            .WithDisplayName("L1")
            .WithShortDisplayName("L1")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 0,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/rightShoulder
            var ctrlDualShock4GamepadHIDrightShoulder = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDrightShoulder.Setup()
            .At(this, 8)
            .WithParent(this)
            .WithName("rightShoulder")
            .WithDisplayName("R1")
            .WithShortDisplayName("R1")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 1,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/leftTriggerButton
            var ctrlDualShock4GamepadHIDleftTriggerButton = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDleftTriggerButton.Setup()
            .At(this, 9)
            .WithParent(this)
            .WithName("leftTriggerButton")
            .WithDisplayName("leftTriggerButton")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 2,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/rightTriggerButton
            var ctrlDualShock4GamepadHIDrightTriggerButton = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDrightTriggerButton.Setup()
            .At(this, 10)
            .WithParent(this)
            .WithName("rightTriggerButton")
            .WithDisplayName("rightTriggerButton")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 3,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/select
            var ctrlDualShock4GamepadHIDselect = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDselect.Setup()
            .At(this, 11)
            .WithParent(this)
            .WithName("select")
            .WithDisplayName("Share")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 4,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/start
            var ctrlDualShock4GamepadHIDstart = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDstart.Setup()
            .At(this, 12)
            .WithParent(this)
            .WithName("start")
            .WithDisplayName("Options")
            .WithLayout(kButtonLayout)
            .WithUsages(8, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 5,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/leftStickPress
            var ctrlDualShock4GamepadHIDleftStickPress = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDleftStickPress.Setup()
            .At(this, 13)
            .WithParent(this)
            .WithName("leftStickPress")
            .WithDisplayName("L3")
            .WithShortDisplayName("L3")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 6,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/rightStickPress
            var ctrlDualShock4GamepadHIDrightStickPress = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDrightStickPress.Setup()
            .At(this, 14)
            .WithParent(this)
            .WithName("rightStickPress")
            .WithDisplayName("R3")
            .WithShortDisplayName("R3")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 6,
                bitOffset  = 7,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/systemButton
            var ctrlDualShock4GamepadHIDsystemButton = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDsystemButton.Setup()
            .At(this, 15)
            .WithParent(this)
            .WithName("systemButton")
            .WithDisplayName("System")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 7,
                bitOffset  = 0,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/touchpadButton
            var ctrlDualShock4GamepadHIDtouchpadButton = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDtouchpadButton.Setup()
            .At(this, 16)
            .WithParent(this)
            .WithName("touchpadButton")
            .WithDisplayName("Touchpad Press")
            .WithLayout(kButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 7,
                bitOffset  = 1,
                sizeInBits = 1
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/leftTrigger
            var ctrlDualShock4GamepadHIDleftTrigger = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDleftTrigger.Setup()
            .At(this, 17)
            .WithParent(this)
            .WithName("leftTrigger")
            .WithDisplayName("L2")
            .WithShortDisplayName("L2")
            .WithLayout(kButtonLayout)
            .WithUsages(9, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 8,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/rightTrigger
            var ctrlDualShock4GamepadHIDrightTrigger = new UnityEngine.InputSystem.Controls.ButtonControl();

            ctrlDualShock4GamepadHIDrightTrigger.Setup()
            .At(this, 18)
            .WithParent(this)
            .WithName("rightTrigger")
            .WithDisplayName("R2")
            .WithShortDisplayName("R2")
            .WithLayout(kButtonLayout)
            .WithUsages(10, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 9,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/leftStick/up
            var ctrlDualShock4GamepadHIDleftStickup = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMax = 0.5f, invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftStickup.Setup()
            .At(this, 19)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("up")
            .WithDisplayName("Left Stick Up")
            .WithShortDisplayName("LS Up")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 2,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/leftStick/x
            var ctrlDualShock4GamepadHIDleftStickx = new UnityEngine.InputSystem.Controls.AxisControl {
                normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftStickx.Setup()
            .At(this, 20)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("x")
            .WithDisplayName("Left Stick X")
            .WithShortDisplayName("LS X")
            .WithLayout(kAxisLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 1,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(-1, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/leftStick/y
            var ctrlDualShock4GamepadHIDleftSticky = new UnityEngine.InputSystem.Controls.AxisControl {
                invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftSticky.Setup()
            .At(this, 21)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("y")
            .WithDisplayName("Left Stick Y")
            .WithShortDisplayName("LS Y")
            .WithLayout(kAxisLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 2,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(-1, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/leftStick/down
            var ctrlDualShock4GamepadHIDleftStickdown = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMin = 0.5f, clampMax = 1f, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftStickdown.Setup()
            .At(this, 22)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("down")
            .WithDisplayName("Left Stick Down")
            .WithShortDisplayName("LS Down")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 2,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/leftStick/left
            var ctrlDualShock4GamepadHIDleftStickleft = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMax = 0.5f, invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftStickleft.Setup()
            .At(this, 23)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("left")
            .WithDisplayName("Left Stick Left")
            .WithShortDisplayName("LS Left")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 1,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/leftStick/right
            var ctrlDualShock4GamepadHIDleftStickright = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMin = 0.5f, clampMax = 1f, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDleftStickright.Setup()
            .At(this, 24)
            .WithParent(ctrlDualShock4GamepadHIDleftStick)
            .WithName("right")
            .WithDisplayName("Left Stick Right")
            .WithShortDisplayName("LS Right")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 1,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/up
            var ctrlDualShock4GamepadHIDrightStickup = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMax = 0.5f, invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightStickup.Setup()
            .At(this, 25)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("up")
            .WithDisplayName("Right Stick Up")
            .WithShortDisplayName("RS Up")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 4,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/x
            var ctrlDualShock4GamepadHIDrightStickx = new UnityEngine.InputSystem.Controls.AxisControl {
                normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightStickx.Setup()
            .At(this, 26)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("x")
            .WithDisplayName("Right Stick X")
            .WithShortDisplayName("RS X")
            .WithLayout(kAxisLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 3,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(-1, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/y
            var ctrlDualShock4GamepadHIDrightSticky = new UnityEngine.InputSystem.Controls.AxisControl {
                invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightSticky.Setup()
            .At(this, 27)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("y")
            .WithDisplayName("Right Stick Y")
            .WithShortDisplayName("RS Y")
            .WithLayout(kAxisLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 4,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(-1, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/down
            var ctrlDualShock4GamepadHIDrightStickdown = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMin = 0.5f, clampMax = 1f, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightStickdown.Setup()
            .At(this, 28)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("down")
            .WithDisplayName("Right Stick Down")
            .WithShortDisplayName("RS Down")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 4,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/left
            var ctrlDualShock4GamepadHIDrightStickleft = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMax = 0.5f, invert = true, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightStickleft.Setup()
            .At(this, 29)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("left")
            .WithDisplayName("Right Stick Left")
            .WithShortDisplayName("RS Left")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 3,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/rightStick/right
            var ctrlDualShock4GamepadHIDrightStickright = new UnityEngine.InputSystem.Controls.ButtonControl {
                clamp = UnityEngine.InputSystem.Controls.AxisControl.Clamp.BeforeNormalize, clampMin = 0.5f, clampMax = 1f, normalize = true, normalizeMax = 1f, normalizeZero = 0.5f
            };

            ctrlDualShock4GamepadHIDrightStickright.Setup()
            .At(this, 30)
            .WithParent(ctrlDualShock4GamepadHIDrightStick)
            .WithName("right")
            .WithDisplayName("Right Stick Right")
            .WithShortDisplayName("RS Right")
            .WithLayout(kButtonLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1113150533),
                byteOffset = 3,
                bitOffset  = 0,
                sizeInBits = 8
            })
            .WithDefaultState(127)
            .WithMinAndMax(0, 1)
            .WithProcessor <InputProcessor <System.Single>, System.Single>(new UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor())
            .Finish();

            // /DualShock4GamepadHID/dpad/x
            var ctrlDualShock4GamepadHIDdpadx = new UnityEngine.InputSystem.Controls.DpadControl.DpadAxisControl();

            ctrlDualShock4GamepadHIDdpadx.Setup()
            .At(this, 31)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("x")
            .WithDisplayName("D-Pad X")
            .WithShortDisplayName("D-Pad X")
            .WithLayout(kDpadAxisLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .Finish();
            ctrlDualShock4GamepadHIDdpadx.component = 0;

            // /DualShock4GamepadHID/dpad/y
            var ctrlDualShock4GamepadHIDdpady = new UnityEngine.InputSystem.Controls.DpadControl.DpadAxisControl();

            ctrlDualShock4GamepadHIDdpady.Setup()
            .At(this, 32)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("y")
            .WithDisplayName("D-Pad Y")
            .WithShortDisplayName("D-Pad Y")
            .WithLayout(kDpadAxisLayout)
            .IsSynthetic(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .Finish();
            ctrlDualShock4GamepadHIDdpady.component = 1;

            // /DualShock4GamepadHID/dpad/up
            var ctrlDualShock4GamepadHIDdpadup = new UnityEngine.InputSystem.Controls.DiscreteButtonControl {
                minValue = 7, maxValue = 1, wrapAtValue = 7, nullValue = 8
            };

            ctrlDualShock4GamepadHIDdpadup.Setup()
            .At(this, 33)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("up")
            .WithDisplayName("D-Pad Up")
            .WithShortDisplayName("D-Pad Up")
            .WithLayout(kDiscreteButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/dpad/down
            var ctrlDualShock4GamepadHIDdpaddown = new UnityEngine.InputSystem.Controls.DiscreteButtonControl {
                minValue = 3, maxValue = 5
            };

            ctrlDualShock4GamepadHIDdpaddown.Setup()
            .At(this, 34)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("down")
            .WithDisplayName("D-Pad Down")
            .WithShortDisplayName("D-Pad Down")
            .WithLayout(kDiscreteButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/dpad/left
            var ctrlDualShock4GamepadHIDdpadleft = new UnityEngine.InputSystem.Controls.DiscreteButtonControl {
                minValue = 5, maxValue = 7
            };

            ctrlDualShock4GamepadHIDdpadleft.Setup()
            .At(this, 35)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("left")
            .WithDisplayName("D-Pad Left")
            .WithShortDisplayName("D-Pad Left")
            .WithLayout(kDiscreteButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // /DualShock4GamepadHID/dpad/right
            var ctrlDualShock4GamepadHIDdpadright = new UnityEngine.InputSystem.Controls.DiscreteButtonControl {
                minValue = 1, maxValue = 3
            };

            ctrlDualShock4GamepadHIDdpadright.Setup()
            .At(this, 36)
            .WithParent(ctrlDualShock4GamepadHIDdpad)
            .WithName("right")
            .WithDisplayName("D-Pad Right")
            .WithShortDisplayName("D-Pad Right")
            .WithLayout(kDiscreteButtonLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 5,
                bitOffset  = 0,
                sizeInBits = 4
            })
            .WithMinAndMax(0, 1)
            .Finish();

            // Usages.
            builder.WithControlUsage(0, new InternedString("Primary2DMotion"), ctrlDualShock4GamepadHIDleftStick);
            builder.WithControlUsage(1, new InternedString("Secondary2DMotion"), ctrlDualShock4GamepadHIDrightStick);
            builder.WithControlUsage(2, new InternedString("Hatswitch"), ctrlDualShock4GamepadHIDdpad);
            builder.WithControlUsage(3, new InternedString("SecondaryAction"), ctrlDualShock4GamepadHIDbuttonWest);
            builder.WithControlUsage(4, new InternedString("PrimaryAction"), ctrlDualShock4GamepadHIDbuttonSouth);
            builder.WithControlUsage(5, new InternedString("Submit"), ctrlDualShock4GamepadHIDbuttonSouth);
            builder.WithControlUsage(6, new InternedString("Back"), ctrlDualShock4GamepadHIDbuttonEast);
            builder.WithControlUsage(7, new InternedString("Cancel"), ctrlDualShock4GamepadHIDbuttonEast);
            builder.WithControlUsage(8, new InternedString("Menu"), ctrlDualShock4GamepadHIDstart);
            builder.WithControlUsage(9, new InternedString("SecondaryTrigger"), ctrlDualShock4GamepadHIDleftTrigger);
            builder.WithControlUsage(10, new InternedString("SecondaryTrigger"), ctrlDualShock4GamepadHIDrightTrigger);

            // Aliases.
            builder.WithControlAlias(0, new InternedString("x"));
            builder.WithControlAlias(1, new InternedString("square"));
            builder.WithControlAlias(2, new InternedString("a"));
            builder.WithControlAlias(3, new InternedString("cross"));
            builder.WithControlAlias(4, new InternedString("b"));
            builder.WithControlAlias(5, new InternedString("circle"));
            builder.WithControlAlias(6, new InternedString("y"));
            builder.WithControlAlias(7, new InternedString("triangle"));

            // Control getters/arrays.
            this.leftTriggerButton  = ctrlDualShock4GamepadHIDleftTriggerButton;
            this.rightTriggerButton = ctrlDualShock4GamepadHIDrightTriggerButton;
            this.playStationButton  = ctrlDualShock4GamepadHIDsystemButton;
            this.touchpadButton     = ctrlDualShock4GamepadHIDtouchpadButton;
            this.optionsButton      = ctrlDualShock4GamepadHIDstart;
            this.shareButton        = ctrlDualShock4GamepadHIDselect;
            this.L1               = ctrlDualShock4GamepadHIDleftShoulder;
            this.R1               = ctrlDualShock4GamepadHIDrightShoulder;
            this.L2               = ctrlDualShock4GamepadHIDleftTrigger;
            this.R2               = ctrlDualShock4GamepadHIDrightTrigger;
            this.L3               = ctrlDualShock4GamepadHIDleftStickPress;
            this.R3               = ctrlDualShock4GamepadHIDrightStickPress;
            this.buttonWest       = ctrlDualShock4GamepadHIDbuttonWest;
            this.buttonNorth      = ctrlDualShock4GamepadHIDbuttonNorth;
            this.buttonSouth      = ctrlDualShock4GamepadHIDbuttonSouth;
            this.buttonEast       = ctrlDualShock4GamepadHIDbuttonEast;
            this.leftStickButton  = ctrlDualShock4GamepadHIDleftStickPress;
            this.rightStickButton = ctrlDualShock4GamepadHIDrightStickPress;
            this.startButton      = ctrlDualShock4GamepadHIDstart;
            this.selectButton     = ctrlDualShock4GamepadHIDselect;
            this.dpad             = ctrlDualShock4GamepadHIDdpad;
            this.leftShoulder     = ctrlDualShock4GamepadHIDleftShoulder;
            this.rightShoulder    = ctrlDualShock4GamepadHIDrightShoulder;
            this.leftStick        = ctrlDualShock4GamepadHIDleftStick;
            this.rightStick       = ctrlDualShock4GamepadHIDrightStick;
            this.leftTrigger      = ctrlDualShock4GamepadHIDleftTrigger;
            this.rightTrigger     = ctrlDualShock4GamepadHIDrightTrigger;
            ctrlDualShock4GamepadHIDleftStick.up     = ctrlDualShock4GamepadHIDleftStickup;
            ctrlDualShock4GamepadHIDleftStick.down   = ctrlDualShock4GamepadHIDleftStickdown;
            ctrlDualShock4GamepadHIDleftStick.left   = ctrlDualShock4GamepadHIDleftStickleft;
            ctrlDualShock4GamepadHIDleftStick.right  = ctrlDualShock4GamepadHIDleftStickright;
            ctrlDualShock4GamepadHIDleftStick.x      = ctrlDualShock4GamepadHIDleftStickx;
            ctrlDualShock4GamepadHIDleftStick.y      = ctrlDualShock4GamepadHIDleftSticky;
            ctrlDualShock4GamepadHIDrightStick.up    = ctrlDualShock4GamepadHIDrightStickup;
            ctrlDualShock4GamepadHIDrightStick.down  = ctrlDualShock4GamepadHIDrightStickdown;
            ctrlDualShock4GamepadHIDrightStick.left  = ctrlDualShock4GamepadHIDrightStickleft;
            ctrlDualShock4GamepadHIDrightStick.right = ctrlDualShock4GamepadHIDrightStickright;
            ctrlDualShock4GamepadHIDrightStick.x     = ctrlDualShock4GamepadHIDrightStickx;
            ctrlDualShock4GamepadHIDrightStick.y     = ctrlDualShock4GamepadHIDrightSticky;
            ctrlDualShock4GamepadHIDdpad.up          = ctrlDualShock4GamepadHIDdpadup;
            ctrlDualShock4GamepadHIDdpad.down        = ctrlDualShock4GamepadHIDdpaddown;
            ctrlDualShock4GamepadHIDdpad.left        = ctrlDualShock4GamepadHIDdpadleft;
            ctrlDualShock4GamepadHIDdpad.right       = ctrlDualShock4GamepadHIDdpadright;
            ctrlDualShock4GamepadHIDdpad.x           = ctrlDualShock4GamepadHIDdpadx;
            ctrlDualShock4GamepadHIDdpad.y           = ctrlDualShock4GamepadHIDdpady;
            builder.Finish();
        }
Esempio n. 20
0
        private UnityEngine.InputSystem.Controls.IntegerControl Initialize_ctrlMousepointerId(InternedString kDigitalLayout, InputControl parent)
        {
            var ctrlMousepointerId = new UnityEngine.InputSystem.Controls.IntegerControl();

            ctrlMousepointerId.Setup()
            .At(this, 11)
            .WithParent(parent)
            .WithName("pointerId")
            .WithDisplayName("pointerId")
            .WithLayout(kDigitalLayout)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1112101920),
                byteOffset = 48,
                bitOffset  = 0,
                sizeInBits = 1
            })
            .Finish();
            return(ctrlMousepointerId);
        }
 public RebindingOperation WithExpectedControlLayout(string layoutName)
 {
     m_ExpectedLayout = new InternedString(layoutName);
     return(this);
 }
Esempio n. 22
0
        private UnityEngine.InputSystem.Controls.AxisControl Initialize_ctrlMousepositionx(InternedString kAxisLayout, InputControl parent)
        {
            var ctrlMousepositionx = new UnityEngine.InputSystem.Controls.AxisControl();

            ctrlMousepositionx.Setup()
            .At(this, 13)
            .WithParent(parent)
            .WithName("x")
            .WithDisplayName("Position X")
            .WithShortDisplayName("Position X")
            .WithLayout(kAxisLayout)
            .DontReset(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1179407392),
                byteOffset = 0,
                bitOffset  = 0,
                sizeInBits = 32
            })
            .Finish();
            return(ctrlMousepositionx);
        }
        // If our layout data is outdated, rescan all the layouts in the system.
        internal static void Refresh()
        {
            var manager = InputSystem.s_Manager;

            if (manager.m_LayoutRegistrationVersion == s_LayoutRegistrationVersion)
            {
                return;
            }

            Clear();

            var layoutNames = new List <string>();

            manager.ListControlLayouts(layoutNames);

            s_Cache.layouts = manager.m_Layouts;

            // Load and store all layouts.
            for (var i = 0; i < layoutNames.Count; ++i)
            {
                var layout = s_Cache.FindOrLoadLayout(layoutNames[i]);
                ScanLayout(layout);

                if (layout.isControlLayout)
                {
                    s_ControlLayouts.Add(layout.name);
                }
                else if (!layout.deviceMatcher.empty)
                {
                    s_ProductLayouts.Add(layout.name);
                }
                else
                {
                    s_DeviceLayouts.Add(layout.name);
                }
            }

            // Move all device layouts without a device description but derived from
            // a layout that has one over to the product list.
            foreach (var name in s_DeviceLayouts)
            {
                var layout = s_Cache.FindOrLoadLayout(name);

                for (var baseLayoutName = layout.extendsLayout; baseLayoutName != null;)
                {
                    var internedBaseLayoutName = new InternedString(baseLayoutName);
                    if (s_ProductLayouts.Contains(internedBaseLayoutName))
                    {
                        // Defer removing from s_DeviceLayouts to keep iteration stable.
                        s_ProductLayouts.Add(name);
                        break;
                    }

                    var baseLayout = s_Cache.FindOrLoadLayout(baseLayoutName);
                    baseLayoutName = baseLayout.extendsLayout;
                }
            }

            // Remove every product device layout now.
            s_DeviceLayouts.ExceptWith(s_ProductLayouts);

            s_LayoutRegistrationVersion = manager.m_LayoutRegistrationVersion;

            if (s_RefreshListeners != null)
            {
                foreach (var listener in s_RefreshListeners)
                {
                    listener();
                }
            }
        }
Esempio n. 24
0
        private UnityEngine.InputSystem.Controls.AxisControl Initialize_ctrlMousescrolly(InternedString kAxisLayout, InputControl parent)
        {
            var ctrlMousescrolly = new UnityEngine.InputSystem.Controls.AxisControl();

            ctrlMousescrolly.Setup()
            .At(this, 18)
            .WithParent(parent)
            .WithName("y")
            .WithDisplayName("Scroll Up/Down")
            .WithShortDisplayName("Scroll Wheel")
            .WithLayout(kAxisLayout)
            .WithUsages(3, 1)
            .WithAliases(1, 1)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1179407392),
                byteOffset = 20,
                bitOffset  = 0,
                sizeInBits = 32
            })
            .Finish();
            return(ctrlMousescrolly);
        }
Esempio n. 25
0
        private UnityEngine.InputSystem.Controls.Vector2Control Initialize_ctrlMouseposition(InternedString kVector2Layout, InputControl parent)
        {
            var ctrlMouseposition = new UnityEngine.InputSystem.Controls.Vector2Control();

            ctrlMouseposition.Setup()
            .At(this, 0)
            .WithParent(parent)
            .WithChildren(13, 2)
            .WithName("position")
            .WithDisplayName("Position")
            .WithLayout(kVector2Layout)
            .WithUsages(0, 1)
            .DontReset(true)
            .WithStateBlock(new InputStateBlock
            {
                format     = new FourCC(1447379762),
                byteOffset = 0,
                bitOffset  = 0,
                sizeInBits = 64
            })
                #if UNITY_EDITOR
            .WithProcessor <InputProcessor <UnityEngine.Vector2>, UnityEngine.Vector2>(new UnityEngine.InputSystem.Processors.EditorWindowSpaceProcessor())
                #endif
            .Finish();
            return(ctrlMouseposition);
        }
Esempio n. 26
0
        /// <summary>
        /// Generate C# code that for the given device layout called <paramref name="layoutName"/> instantly creates
        /// an <see cref="InputDevice"/> equivalent to what the input system would create by manually interpreting
        /// the given <see cref="InputControlLayout"/>.
        /// </summary>
        /// <param name="layoutName">Name of the device layout to generate code for.</param>
        /// <param name="defines">Null/empty or a valid expression for an #if conditional compilation statement.</param>
        /// <param name="namePrefix">Prefix to prepend to the type name of <paramref name="layoutName"/>.</param>
        /// <param name="visibility">C# access modifier to use with the generated class.</param>
        /// <param name="namespace">Namespace to put the generated class in. If <c>null</c>, namespace of type behind <paramref name="layoutName"/> will be used.</param>
        /// <returns>C# source code for a precompiled version of the device layout.</returns>
        /// <remarks>
        /// The code generated by this method will be many times faster than the reflection-based <see cref="InputDevice"/>
        /// creation normally performed by the input system. It will also create less GC heap garbage.
        ///
        /// The downside to the generated code is that the makeup of the device is hardcoded and can no longer
        /// be changed by altering the <see cref="InputControlLayout"/> setup of the system.
        ///
        /// Note that it is possible to use this method with layouts generated on-the-fly by layout builders such as
        /// the one employed for <see cref="HID"/>. However, this must be done at compile/build time and can thus not
        /// be done for devices dynamically discovered at runtime. When this is acceptable, it is a way to dramatically
        /// speed up the creation of these devices.
        /// </remarks>
        /// <seealso cref="InputSystem.RegisterPrecompiledLayout{T}"/>
        public static string GenerateCodeForDeviceLayout(string layoutName, string defines = null, string namePrefix = "Fast", string visibility = "public", string @namespace = null)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                throw new ArgumentNullException(nameof(layoutName));
            }

            // Produce a device from the layout.
            var device = InputDevice.Build <InputDevice>(layoutName, noPrecompiledLayouts: true);

            // Get info about base type.
            var baseType          = device.GetType();
            var baseTypeName      = baseType.Name;
            var baseTypeNamespace = baseType.Namespace;

            // Begin generating code.
            var writer = new InputActionCodeGenerator.Writer
            {
                buffer = new StringBuilder()
            };

            writer.WriteLine(CSharpCodeHelpers.MakeAutoGeneratedCodeHeader("com.unity.inputsystem:InputLayoutCodeGenerator",
                                                                           InputSystem.version.ToString(),
                                                                           $"\"{layoutName}\" layout"));

            // Defines.
            if (defines != null)
            {
                writer.WriteLine($"#if {defines}");
                writer.WriteLine();
            }

            if (@namespace == null)
            {
                @namespace = baseTypeNamespace;
            }

            writer.WriteLine("using UnityEngine.InputSystem;");
            writer.WriteLine("using UnityEngine.InputSystem.LowLevel;");
            writer.WriteLine("using UnityEngine.InputSystem.Utilities;");
            writer.WriteLine("");
            writer.WriteLine("// Suppress warnings from local variables for control references");
            writer.WriteLine("// that we don't end up using.");
            writer.WriteLine("#pragma warning disable CS0219");
            writer.WriteLine("");
            if (@namespace != "")
            {
                writer.WriteLine("namespace " + @namespace);
            }
            writer.BeginBlock();

            writer.WriteLine($"{visibility} partial class {namePrefix}{baseTypeName} : {baseTypeNamespace}.{baseTypeName}");
            writer.BeginBlock();

            // "Metadata". ATM this is simply a flat, semicolon-separated list of names for layouts and processors that
            // we depend on. If any of them are touched, the precompiled layout should be considered invalidated.
            var internedLayoutName = new InternedString(layoutName);
            var allControls        = device.allControls;
            var usedControlLayouts = allControls.Select(x => x.m_Layout).Distinct().ToList();
            var layoutDependencies = string.Join(";",
                                                 usedControlLayouts.SelectMany(l => InputControlLayout.s_Layouts.GetBaseLayouts(l))
                                                 .Union(InputControlLayout.s_Layouts.GetBaseLayouts(internedLayoutName)));
            var processorDependencies = string.Join(";",
                                                    allControls.SelectMany(c => c.GetProcessors()).Select(p => InputProcessor.s_Processors.FindNameForType(p.GetType()))
                                                    .Where(n => !n.IsEmpty()).Distinct());
            var metadata = string.Join(";", processorDependencies, layoutDependencies);

            writer.WriteLine($"public const string metadata = \"{metadata}\";");

            // Constructor.
            writer.WriteLine($"public {namePrefix}{baseTypeName}()");
            writer.BeginBlock();

            var usagesForEachControl  = device.m_UsagesForEachControl;
            var usageToControl        = device.m_UsageToControl;
            var aliasesForEachControl = device.m_AliasesForEachControl;
            var controlCount          = allControls.Count;
            var usageCount            = usagesForEachControl?.Length ?? 0;
            var aliasCount            = aliasesForEachControl?.Length ?? 0;

            // Set up device control info.
            writer.WriteLine($"var builder = this.Setup({controlCount}, {usageCount}, {aliasCount})");
            writer.WriteLine($"    .WithName(\"{device.name}\")");
            writer.WriteLine($"    .WithDisplayName(\"{device.displayName}\")");
            writer.WriteLine($"    .WithChildren({device.m_ChildStartIndex}, {device.m_ChildCount})");
            writer.WriteLine($"    .WithLayout(new InternedString(\"{device.layout}\"))");
            if (device.noisy)
            {
                writer.WriteLine("    .IsNoisy(true)");
            }
            writer.WriteLine($"    .WithStateBlock(new InputStateBlock {{ format = new FourCC({(int)device.stateBlock.format}), sizeInBits = {device.stateBlock.sizeInBits} }});");

            // Add controls to device.
            writer.WriteLine();
            foreach (var layout in usedControlLayouts)
            {
                writer.WriteLine($"var k{layout}Layout = new InternedString(\"{layout}\");");
            }

            for (var i = 0; i < controlCount; ++i)
            {
                var control             = allControls[i];
                var controlVariableName = MakeControlVariableName(control);

                writer.WriteLine("");
                writer.WriteLine($"// {control.path}");
                var parentName = "this";
                if (control.parent != device)
                {
                    parentName = MakeControlVariableName(control.parent);
                }
                writer.WriteLine($"var {controlVariableName} = {NameOfControlMethod(controlVariableName)}(k{control.layout}Layout, {parentName});");
            }

            // Initialize usages array.
            if (usageCount > 0)
            {
                writer.WriteLine();
                writer.WriteLine("// Usages.");
                for (var i = 0; i < usageCount; ++i)
                {
                    writer.WriteLine(
                        $"builder.WithControlUsage({i}, new InternedString(\"{usagesForEachControl[i]}\"), {MakeControlVariableName(usageToControl[i])});");
                }
            }

            // Initialize aliases array.
            if (aliasCount > 0)
            {
                writer.WriteLine();
                writer.WriteLine("// Aliases.");
                for (var i = 0; i < aliasCount; ++i)
                {
                    writer.WriteLine($"builder.WithControlAlias({i},  new InternedString(\"{aliasesForEachControl[i]}\"));");
                }
            }

            // Emit initializers for control getters and control arrays. This is usually what's getting set up
            // in FinishSetup(). We hardcode the look results here.
            var controlGetterProperties = new Dictionary <Type, List <PropertyInfo> >();
            var controlArrayProperties  = new Dictionary <Type, List <PropertyInfo> >();

            writer.WriteLine();
            writer.WriteLine("// Control getters/arrays.");
            writer.EmitControlArrayInitializers(device, "this", controlArrayProperties);
            writer.EmitControlGetterInitializers(device, "this", controlGetterProperties);

            for (var i = 0; i < controlCount; ++i)
            {
                var control             = allControls[i];
                var controlVariableName = MakeControlVariableName(control);

                writer.EmitControlArrayInitializers(control, controlVariableName, controlArrayProperties);
                writer.EmitControlGetterInitializers(control, controlVariableName, controlGetterProperties);
            }

            // State offset to control index map.
            if (device.m_StateOffsetToControlMap != null)
            {
                writer.WriteLine();
                writer.WriteLine("// State offset to control index map.");
                writer.WriteLine("builder.WithStateOffsetToControlIndexMap(new uint[]");
                writer.WriteLine("{");
                ++writer.indentLevel;
                var map        = device.m_StateOffsetToControlMap;
                var entryCount = map.Length;
                for (var index = 0; index < entryCount;)
                {
                    if (index != 0)
                    {
                        writer.WriteLine();
                    }
                    // 10 entries a line.
                    writer.WriteIndent();
                    for (var i = 0; i < 10 && index < entryCount; ++index, ++i)
                    {
                        writer.Write((index != 0 ? ", " : "") + map[index] + "u");
                    }
                }
                writer.WriteLine();
                --writer.indentLevel;
                writer.WriteLine("});");
            }

            writer.WriteLine();
            writer.WriteLine("builder.Finish();");
            writer.EndBlock();

            for (var i = 0; i < controlCount; ++i)
            {
                var control             = allControls[i];
                var controlType         = control.GetType();
                var controlVariableName = MakeControlVariableName(control);
                var controlFieldInits   = control.GetInitializersForPublicPrimitiveTypeFields();
                writer.WriteLine();
                EmitControlMethod(writer, controlVariableName, controlType, controlFieldInits, i, control);
            }

            writer.EndBlock();
            writer.EndBlock();

            if (defines != null)
            {
                writer.WriteLine($"#endif // {defines}");
            }

            return(writer.buffer.ToString());
        }
        private InputControl InstantiateLayout(InputControlLayout layout, InternedString variants, InternedString name,
                                               InputControl parent)
        {
            Debug.Assert(layout.type != null, "Layout has no type set on it");

            // No, so create a new control.
            var controlObject = Activator.CreateInstance(layout.type);

            if (!(controlObject is InputControl control))
            {
                throw new InvalidOperationException(
                          $"Type '{layout.type.Name}' referenced by layout '{layout.name}' is not an InputControl");
            }

            // If it's a device, perform some extra work specific to the control
            // hierarchy root.
            if (control is InputDevice controlAsDevice)
            {
                if (parent != null)
                {
                    throw new InvalidOperationException(
                              $"Cannot instantiate device layout '{layout.name}' as child of '{parent.path}'; devices must be added at root");
                }

                m_Device = controlAsDevice;
                m_Device.m_StateBlock.byteOffset = 0;
                m_Device.m_StateBlock.bitOffset  = 0;
                m_Device.m_StateBlock.format     = layout.stateFormat;

                // If we have an existing device, we'll start the various control arrays
                // from scratch. Note that all the controls still refer to the existing
                // arrays and so we can iterate children, for example, just fine while
                // we are rebuilding the control hierarchy.
                m_Device.m_AliasesForEachControl  = null;
                m_Device.m_ChildrenForEachControl = null;
                m_Device.m_UsagesForEachControl   = null;
                m_Device.m_UsageToControl         = null;

                if (layout.m_UpdateBeforeRender == true)
                {
                    m_Device.m_DeviceFlags |= InputDevice.DeviceFlags.UpdateBeforeRender;
                }
            }
            else if (parent == null)
            {
                // Someone did "new InputDeviceBuilder(...)" with a control layout.
                // We don't support creating control hierarchies without a device at the root.
                throw new InvalidOperationException(
                          $"Toplevel layout used with InputDeviceBuilder must be a device layout; '{layout.name}' is a control layout");
            }

            // Name defaults to name of layout.
            if (name.IsEmpty())
            {
                name = layout.name;

                // If there's a namespace in the layout name, snip it out.
                var indexOfLastColon = name.ToString().LastIndexOf(':');
                if (indexOfLastColon != -1)
                {
                    name = new InternedString(name.ToString().Substring(indexOfLastColon + 1));
                }
            }

            // Variant defaults to variants of layout.
            if (variants.IsEmpty())
            {
                variants = layout.variants;

                if (variants.IsEmpty())
                {
                    variants = InputControlLayout.DefaultVariant;
                }
            }

            control.m_Name = name;
            control.m_DisplayNameFromLayout = layout.m_DisplayName; // No short display names at layout roots.
            control.m_Layout   = layout.name;
            control.m_Variants = variants;
            control.m_Parent   = parent;
            control.m_Device   = m_Device;

            // Create children and configure their settings from our
            // layout values.
            var haveChildrenUsingStateFromOtherControl = false;

            try
            {
                // Pass list of existing control on to function as we may have decided to not
                // actually reuse the existing control (and thus control.m_ChildrenReadOnly will
                // now be blank) but still want crawling down the hierarchy to preserve existing
                // controls where possible.
                AddChildControls(layout, variants, control,
                                 ref haveChildrenUsingStateFromOtherControl);
            }
            catch
            {
                ////TODO: remove control from collection and rethrow
                throw;
            }

            // Come up with a layout for our state.
            ComputeStateLayout(control);

            // Finally, if we have child controls that take their state blocks from other
            // controls, assign them their blocks now.
            if (haveChildrenUsingStateFromOtherControl)
            {
                var controls = layout.m_Controls;
                for (var i = 0; i < controls.Length; ++i)
                {
                    ref var item = ref controls[i];
                    if (string.IsNullOrEmpty(item.useStateFrom))
                    {
                        continue;
                    }
                    ApplyUseStateFrom(control, ref item, layout);
                }
            }