Ejemplo n.º 1
0
        private static InputDevice CreateOnScreenDevice(string layout, OnScreenControl onScreenControl)
        {
            var           device = InputSystem.AddDevice(layout);
            InputEventPtr eventPtr;
            var           buffer = StateEvent.From(device, out eventPtr, Allocator.Persistent);

            OnScreenDeviceEventInfo deviceEventInfo;

            deviceEventInfo.eventPtr     = eventPtr;
            deviceEventInfo.buffer       = buffer;
            deviceEventInfo.device       = device;
            deviceEventInfo.firstControl = onScreenControl;

            s_DeviceEventInfoArray.Append(deviceEventInfo);

            return(device);
        }
            public OnScreenDeviceInfo RemoveControl(OnScreenControl control)
            {
                if (firstControl == control)
                {
                    firstControl = control.m_NextControlOnDevice;
                }
                else
                {
                    for (OnScreenControl current = firstControl.m_NextControlOnDevice, previous = firstControl;
                         current != null; previous = current, current = current.m_NextControlOnDevice)
                    {
                        if (current != control)
                        {
                            continue;
                        }

                        previous.m_NextControlOnDevice = current.m_NextControlOnDevice;
                        break;
                    }
                }

                control.m_NextControlOnDevice = null;
                return(this);
            }
Ejemplo n.º 3
0
        private InputControl RegisterInputControl(string controlPath)
        {
            var layout = InputControlPath.TryGetDeviceLayout(controlPath);

            if (layout == null)
            {
                throw new Exception(string.Format("Could not parse a device layout for the {0} control path",
                                                  controlPath));
            }

            m_Layout = layout;

            // Check if we already have a a device created for this type of OnScreenControl
            int deviceIndex = GetDeviceEventIndex(layout);

            // If we do not have a device created yet, create a new one
            if (deviceIndex < 0)
            {
                var device = CreateOnScreenDevice(layout, this);
                if (device == null)
                {
                    throw new Exception(string.Format("Could not create a device for the {0} control path",
                                                      controlPath));
                }

                return(InputControlPath.TryFindControl(device, controlPath));
            }
            else
            {
                m_NextControlOnDevice = s_DeviceEventInfoArray[deviceIndex].firstControl.m_NextControlOnDevice;
                var temp = s_DeviceEventInfoArray[deviceIndex].firstControl;
                temp.m_NextControlOnDevice = this;

                return(InputControlPath.TryFindControl(s_DeviceEventInfoArray[deviceIndex].device, controlPath));
            }
        }
 public OnScreenDeviceInfo AddControl(OnScreenControl control)
 {
     control.m_NextControlOnDevice = firstControl;
     firstControl = control;
     return(this);
 }