Beispiel #1
0
 bool InputObjectFactory.VendorExists <T> (string vendor)
 {
     if (typeof(T) == typeof(Keyboard) || typeof(T) == typeof(Mouse) || vendor.ToLower() == InputSystemName.ToLower())
     {
         return(true);
     }
     else
     {
         if (typeof(T) == typeof(Joystick))
         {
             foreach (DeviceInfo dev in _unusedDevices)
             {
                 if (dev.GetType() == typeof(JoystickInfo))
                 {
                     JoystickInfo joy = (JoystickInfo)dev;
                     if (joy.Vendor.ToLower() == vendor.ToLower())
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Beispiel #2
0
        public void UpdateJoystickInfo(JoystickInfo oldState, JoystickInfo newState)
        {
            if (oldState.IsButtonDown(Components.Button.B3, newState))
            {
                this.rocketFactory.Fire();
            }

            if (oldState.IsButtonDown(Components.Button.B1, newState))
            {
                this.planetFactory.AddNewPlanet();
            }
        }
    public void InputHandler(JoystickInfo joystickInfo)
    {
        horizontal = ((Mathf.Abs(joystickInfo.position.x) > 0.1f)? Mathf.Clamp(2 * joystickInfo.position.x, -1, 1) : 0);
        jumpForce  = Mathf.Clamp(joystickInfo.deltaPosition.magnitude, -1f, 1f);
        vertical   = joystickInfo.position.y;

        Movement();

        Fliping();

        ApplyAnimator();
    }
        private void _enumerateDevices()
        {
            var keyboardInfo = new KeyboardInfo();

            keyboardInfo.Vendor = InputSystemName;
            keyboardInfo.Id     = 0;
            this._unusedDevices.Add(keyboardInfo);

            var mouseInfo = new MouseInfo();

            mouseInfo.Vendor = InputSystemName;
            mouseInfo.Id     = 0;
            this._unusedDevices.Add(mouseInfo);

            foreach (MDI.DeviceInstance device in this.directInput.GetDevices(MDI.DeviceClass.GameControl, MDI.DeviceEnumerationFlags.AttachedOnly))
            {
                //if ( device.Type == MDI.DeviceType.Joystick || device.Type == MDI.DeviceType.Gamepad ||
                //     device.Type == MDI.DeviceType.FirstPerson || device.Type == MDI.DeviceType.Driving ||
                //     device.Type == MDI.DeviceType.Flight )
                //{
                var joystickInfo = new JoystickInfo();
                joystickInfo.IsXInput    = false;
                joystickInfo.ProductGuid = device.ProductGuid;
                joystickInfo.DeviceId    = device.InstanceGuid;
                joystickInfo.Vendor      = device.ProductName;
                joystickInfo.Id          = this._joystickCount++;

                this._unusedDevices.Add(joystickInfo);
                //}
            }

            try
            {
                var controllers = new[] { new SXI.Controller(SXI.UserIndex.One), new SXI.Controller(SXI.UserIndex.Two), new SXI.Controller(SXI.UserIndex.Three), new SXI.Controller(SXI.UserIndex.Four) };
                foreach (var controller in controllers)
                {
                    if (controller.IsConnected)
                    {
                        DirectXJoystick.CheckXInputDevices(_unusedDevices);
                    }
                }
            }
            catch (DllNotFoundException)
            {
            }
        }
Beispiel #5
0
        public DirectXJoystick(InputManager creator, MDI.DirectInput device, bool buffered, MDI.CooperativeLevel coopSettings)
        {
            Creator            = creator;
            this._directInput  = device;
            IsBuffered         = buffered;
            this._coopSettings = coopSettings;
            Type          = InputType.Joystick;
            EventListener = null;

            this._joyInfo = (JoystickInfo)((DirectXInputManager)Creator).CaptureDevice <Joystick>();

            if (this._joyInfo == null)
            {
                throw new Exception("No devices match requested type.");
            }

            this._deviceGuid = this._joyInfo.DeviceId;
            Vendor           = this._joyInfo.Vendor;
            DeviceID         = this._joyInfo.Id.ToString();
        }
        void ShowJoystickInfos()
        {
            _joystickInfosProperty = serializedObject.FindProperty("_joystickInfos");

            if (AddFoldOut(_joystickInfosProperty, "Joysticks".ToGUIContent()))
            {
                JoystickInfo[] joystickInfos = _inputSystem.GetJoystickInfos();
                JoystickInfo joystickInfo = joystickInfos.Last();

                joystickInfo.SetUniqueName("default", "", joystickInfos);

                serializedObject.Update();
            }

            if (_joystickInfosProperty.isExpanded)
            {
                EditorGUI.indentLevel += 1;

                for (int i = 0; i < _joystickInfosProperty.arraySize; i++)
                {
                    _currentJoystickInfo = _inputSystem.GetJoystickInfos()[i];
                    _currentJoystickInfoProperty = _joystickInfosProperty.GetArrayElementAtIndex(i);

                    BeginBox();

                    string joystickName = _currentJoystickInfoProperty.FindPropertyRelative("_joystick").GetValue<Joysticks>().ToString();

                    if (DeleteFoldOut(_joystickInfosProperty, i, string.Format("{0} ({1})", _currentJoystickInfo.Name, joystickName).ToGUIContent(), CustomEditorStyles.BoldFoldout))
                    {
                        break;
                    }

                    ShowJoystickInfo();

                    EndBox();
                }

                Separator();
                EditorGUI.indentLevel -= 1;
            }
        }
Beispiel #7
0
        void xna_init_input()
        {
            int tot, i, j, k;
            string buf = "";

            for (i = 0; i < 4; i++)
            {
                joy[i] = new GamepadInfo();
            }
            tot = 0;

            /* first of all, map mouse buttons */
            //for (j = 0; j < 3; j++)
            //{
            //    buf = sprintf("MOUSE B%d", j + 1);
            //    joynames[tot] = buf;
            //    joylist[tot] = new JoystickInfo();
            //    joylist[tot].name = joynames[tot];
            //    joylist[tot].code = MOUSE_BUTTON(j + 1);
            //    tot++;
            //}

            for (i = 0; i < num_joysticks; i++)
            {
                for (j = 0; j < joy[i].num_sticks; j++)
                {
                    for (k = 0; k < joy[i].stick[j].num_axis; k++)
                    {
                        joylist[tot] = new JoystickInfo();
                        joynames[tot] = sprintf(buf, "J%d %s %s -", i + 1, joy[i].stick[j].name, joy[i].stick[j].axis[k].name);
                        joylist[tot].name = joynames[tot];
                        joylist[tot].code = (uint)JOYCODE(i + 1, j + 1, k + 1, 1);
                        tot++;

                        joylist[tot] = new JoystickInfo();

                        joynames[tot] = sprintf("J%d %s %s +", i + 1, joy[i].stick[j].name, joy[i].stick[j].axis[k].name);
                        joylist[tot].name = joynames[tot];
                        joylist[tot].code = (uint)JOYCODE(i + 1, j + 1, k + 1, 2);
                        tot++;
                    }
                }
                for (j = 0; j < joy[i].num_buttons; j++)
                {
                    joynames[tot] = sprintf(buf, "J%d %s", i + 1, joy[i].button[j].name);
                    joylist[tot] = new JoystickInfo();
                    joylist[tot].name = joynames[tot];
                    joylist[tot].code = (uint)JOYCODE(i + 1, 0, j + 1, 0);
                    tot++;
                }
            }
            joylist[tot] = new JoystickInfo();
            /* terminate array */
            joylist[tot].name = null;
            joylist[tot].code = 0;
            joylist[tot].standardcode = 0;

            /* fill in equivalences */
            for (i = 0; i < tot; i++)
            {
                joylist[i].standardcode = (uint)InputCodes.CODE_OTHER;

                j = 0;
                while (joyequiv[j][0] != 0)
                {
                    if (joyequiv[j][0] == joylist[i].code)
                    {
                        joylist[i].standardcode = (uint)joyequiv[j][1];
                        break;
                    }
                    j++;
                }
            }
        }
    public void InputHandler(JoystickInfo joystickInfo)
    {
        deltaAngle = Vector3.Angle(transform.up, joystickInfo.position) * Mathf.Sign(Vector3.Cross(transform.up, joystickInfo.position).z);

        rb2D.angularVelocity = deltaAngle * rotationSpeed;
    }
Beispiel #9
0
 private void Start()
 {
     get = this;
 }