示例#1
0
        bool TryPairing(InputDevice device)
        {
            // Check if it's a MIDI device.
            var midiDevice = device as Minis.MidiDevice;

            if (midiDevice == null)
            {
                return(false);
            }

            // Channel matching
            if (_channel >= 0 && midiDevice.channel != _channel)
            {
                return(false);
            }

            // Product name matching
            if (!string.IsNullOrEmpty(_productName) &&
                !device.description.product.Contains(_productName))
            {
                return(false);
            }

            // Pairing
            InputUser.PerformPairingWithDevice(device, GetComponent <PlayerInput>().user);

            return(true);
        }
示例#2
0
    public void Users_CanQueryUnassignedDevices()
    {
        var gamepad  = InputSystem.AddDevice <Gamepad>();
        var keyboard = InputSystem.AddDevice <Keyboard>();
        var mouse    = InputSystem.AddDevice <Mouse>();
        var touch    = InputSystem.AddDevice <Touchscreen>();
        var gyro     = InputSystem.AddDevice <Gyroscope>();

        var user1 = new TestUser();
        var user2 = new TestUser();
        var user3 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);
        InputUser.Add(user3);

        user1.AssignInputDevice(gamepad);
        user3.AssignInputDevices(new InputDevice[] { keyboard, mouse });

        using (var unusedDevices = InputUser.GetUnassignedInputDevices())
        {
            Assert.That(unusedDevices, Has.Count.EqualTo(2));
            Assert.That(unusedDevices, Has.Exactly(1).SameAs(touch));
            Assert.That(unusedDevices, Has.Exactly(1).SameAs(gyro));
        }
    }
示例#3
0
    public void Users_CanUnpairDevices_WhenUserHasLostDevices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();
        var gamepad3 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad2);

        InputSystem.RemoveDevice(gamepad1);
        InputSystem.RemoveDevice(gamepad2);

        Assert.That(user1.pairedDevices, Is.Empty);
        Assert.That(user1.lostDevices, Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(user2.pairedDevices, Is.Empty);
        Assert.That(user2.lostDevices, Is.EquivalentTo(new[] { gamepad2 }));

        user1.UnpairDevices();

        Assert.That(user1.pairedDevices, Is.Empty);
        Assert.That(user1.lostDevices, Is.Empty);
        Assert.That(user2.pairedDevices, Is.Empty);
        Assert.That(user2.lostDevices, Is.EquivalentTo(new[] { gamepad2 }));

        InputUser.PerformPairingWithDevice(gamepad3, user: user2, options: InputUserPairingOptions.UnpairCurrentDevicesFromUser);

        Assert.That(user1.pairedDevices, Is.Empty);
        Assert.That(user1.lostDevices, Is.Empty);
        Assert.That(user2.pairedDevices, Is.EquivalentTo(new[] { gamepad3 }));
        Assert.That(user2.lostDevices, Is.Empty);
    }
示例#4
0
        public override async Task RemoveAndClearDialog()
        {
            try {
                await ClearDialogHistory();

                if (dialog.peer.Constructor == Constructor.peerChat)
                {
                    InputPeer peer = InputPeer;
                    InputPeerChatConstructor peerChat = (InputPeerChatConstructor)peer;
                    InputUser user = TL.inputUserSelf();

                    messages_StatedMessage message =
                        await session.Api.messages_deleteChatUser(peerChat.chat_id, user);

                    switch (message.Constructor)
                    {
                    case Constructor.messages_statedMessage:
                        session.Updates.processUpdatePtsSeq(((Messages_statedMessageConstructor)message).pts, ((Messages_statedMessageConstructor)message).seq);
                        break;

                    case Constructor.messages_statedMessageLink:
                        session.Updates.processUpdatePtsSeq(((Messages_statedMessageLinkConstructor)message).pts, ((Messages_statedMessageLinkConstructor)message).seq);
                        break;
                    }
                }

                session.Dialogs.Model.Dialogs.Remove(this);
            }
            catch (Exception ex) {
                logger.error("exception: {0}", ex);
            }
        }
示例#5
0
 private void OnInputEvent(InputAction action, InputUser user)
 {
     if (InputBindingUsedEvent != null)
     {
         InputBindingUsedEvent(user.InputUsing, action);
     }
 }
示例#6
0
    public void Users_CanDisconnectAndReconnectDevice()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();

        var user = InputUser.PerformPairingWithDevice(gamepad);

        var changes = new List <InputUserChange>();

        InputUser.onChange +=
            (u, change, device) =>
        {
            Assert.That(u, Is.EqualTo(user));
            Assert.That(device, Is.SameAs(gamepad));
            changes.Add(change);
        };

        InputSystem.RemoveDevice(gamepad);

        Assert.That(changes, Is.EquivalentTo(new[] { InputUserChange.DeviceLost, InputUserChange.DeviceUnpaired }));
        Assert.That(user.lostDevices, Is.EquivalentTo(new[] { gamepad }));
        Assert.That(user.pairedDevices, Is.Empty);

        changes.Clear();

        InputSystem.AddDevice(gamepad);

        Assert.That(changes, Is.EquivalentTo(new[] { InputUserChange.DeviceRegained, InputUserChange.DevicePaired }));
        Assert.That(user.lostDevices, Is.Empty);
        Assert.That(user.pairedDevices, Is.EquivalentTo(new[] { gamepad }));
    }
示例#7
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Person = await _context.People.FirstOrDefaultAsync(m => m.Id == id);

            ApplicationUser applicationUser = await _userManager.FindByIdAsync(Person.ApplicationUserId);

            InputUser = new InputUser
            {
                Email       = applicationUser.Email,
                PhoneNumber = applicationUser.PhoneNumber
            };

            if (Person == null)
            {
                return(NotFound());
            }

            ViewData["IdDocumentTypeId"] = new SelectList(_context.DocumentTypes, "Id", "Name");
            return(Page());
        }
示例#8
0
        private void Start()
        {
            var playerInputs = _playerInstances.Select(player => player.GetComponent <PlayerInput>()).ToList();

            // device option already exist
            for (var playerIdx = 0; playerIdx < maxPlayer; playerIdx++)
            {
                var(device, scheme) = DeviceMap.PlayerDevices[playerIdx];
                var playerInput = playerInputs[playerIdx];

                playerInput.SwitchCurrentControlScheme(scheme);
                InputUser.PerformPairingWithDevice(device, playerInput.user,
                                                   InputUserPairingOptions.UnpairCurrentDevicesFromUser);
                devicesText[playerIdx].text = device.displayName;

                if (!scheme.StartsWith("Keyboard"))
                {
                    keyboardScheme[playerIdx].SetActive(false);
                }
            }

            // This subscribes us to events that will fire if any button is pressed.  We'll most certainly want to throw this away
            // when not in a selection screen (performance intensive)!
            _myAction            = new InputAction(binding: "/*/<button>");
            _myAction.performed += action =>
            {
                // playerInputManager.JoinPlayerFromActionIfNotAlreadyJoined(action);
                AddPlayer(action.control.device);
            };
            _myAction.Enable();
            CheckValidScheme();
        }
示例#9
0
        public async Task <IActionResult> PostUser(InputUser inputUser,
                                                   [FromServices] IOptions <ApiBehaviorOptions> apiBehaviorOptions)
        {
            inputUser.HashPassword(_passwordHash);
            var user = inputUser.ToModel();

            if (await CpfExists(user.Cpf))
            {
                ModelState.AddModelError(nameof(user.Cpf), "User Cpf already in use");
            }

            if (await EmailExists(user.Email))
            {
                ModelState.AddModelError(nameof(user.Email), "User Email already in use");
            }

            if (!ModelState.IsValid)
            {
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(Ok(_outputHandler.OutputFor(user)));
        }
示例#10
0
    void SetKeyboardInput(PlayerInput input)
    {
        InputUser.PerformPairingWithDevice(Keyboard.current, input.user);
        string name = input.gameObject.name;

        if (name.StartsWith("Mechanic"))
        {
            string mechanicId = name.Substring(name.Length - 1);
            switch (mechanicId)
            {
            case "A":
                input.user.ActivateControlScheme("Keyboard_TFGH");
                break;

            case "B":
                input.user.ActivateControlScheme("Keyboard_IJKL");
                break;

            case "C":
                input.user.ActivateControlScheme("Keyboard_WASD");
                break;
            }
        }
        else
        {
            input.user.ActivateControlScheme("Keyboard");
        }
    }
示例#11
0
        private void Init()
        {
            if (_init)
            {
                return;
            }

            lastPlayer = 0;
            _users     = new InputUser[4];
            _gamepads  = new Gamepad[4];

            Debug.Log("On input singleton enabled");

            InputUser.listenForUnpairedDeviceActivity = 4;

            InputUser.onChange             += OnControlsChanged;
            InputUser.onUnpairedDeviceUsed += InputUser_onUnpairedDeviceUsed;

            for (var i = 0; i < _users.Length; i++)
            {
                _users[i] = InputUser.CreateUserWithoutPairedDevices();
            }

            _init = true;
        }
示例#12
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Customer = await _context.Customers
                       .Include(c => c.Person)
                       .Include(c => c.CustomerCompany)
                       .AsNoTracking().FirstOrDefaultAsync(m => m.Id == id);

            if (Customer == null)
            {
                return(NotFound());
            }

            Person          = Customer.Person;
            CustomerCompany = Customer.CustomerCompany;

            ApplicationUser applicationUser = await _userManager.FindByIdAsync(Person.ApplicationUserId);

            InputUser = new InputUser
            {
                Email       = applicationUser.Email,
                PhoneNumber = applicationUser.PhoneNumber
            };

            ViewData["IdDocumentTypeId"] = new SelectList(_context.DocumentTypes.AsNoTracking(), "Id", "Name", Person?.IdDocument?.DocumentTypeId);

            return(Page());
        }
        public IActionResult CreateUser([FromBody] InputUser user)
        {
            _logger.Info("Create User endpoint...", new { user });

            if (user != null)
            {
                var tokenPayload = _accessTokenProvider.GetTokenPayload();

                if (tokenPayload != null)
                {
                    if (tokenPayload.IsAdmin)
                    {
                        int createdUserId = _userRepository.CreateUser(user);

                        if (createdUserId > 0)
                        {
                            _logger.Info("Create User endpoint successful!", new { createdUserId });
                            return(Ok(new { createdUserId }));
                        }

                        return(StatusCode(StatusCodes.Status500InternalServerError));
                    }

                    return(StatusCode(StatusCodes.Status403Forbidden));
                }

                return(Unauthorized());
            }

            return(BadRequest());
        }
示例#14
0
    public void Users_CanAssignControlScheme_AndAutomaticallyAssignMatchingUnusedDevices()
    {
        var keyboard = InputSystem.AddDevice <Keyboard>();

        InputSystem.AddDevice <Mouse>(); // Noise.
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();
        var gamepad3 = InputSystem.AddDevice <Gamepad>();

        var singleGamepadScheme = new InputControlScheme("SingleGamepad")
                                  .WithRequiredDevice("<Gamepad>");
        var dualGamepadScheme = new InputControlScheme("DualGamepad")
                                .WithRequiredDevice("<Gamepad>")
                                .WithRequiredDevice("<Gamepad>");

        var user1 = new TestUser();
        var user2 = new TestUser();
        var user3 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);
        InputUser.Add(user3);

        user1.AssignInputDevice(keyboard); // Should automatically be unassigned.
        user3.AssignInputDevice(keyboard); // Should not be affected by any of what we do here.

        user1.AssignControlScheme(singleGamepadScheme).AndAssignDevices();
        user2.AssignControlScheme(dualGamepadScheme).AndAssignDevices();

        Assert.That(user1.GetAssignedInputDevices(), Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(user2.GetAssignedInputDevices(), Is.EquivalentTo(new[] { gamepad2, gamepad3 }));
        Assert.That(user3.GetAssignedInputDevices(), Is.EquivalentTo(new[] { keyboard }));
    }
示例#15
0
    public void Users_CanAssignControlScheme_AndMaskOutBindingsFromOtherControlSchemes()
    {
        var gamepad       = InputSystem.AddDevice <Gamepad>();
        var gamepadScheme = new InputControlScheme("Gamepad")
                            .WithRequiredDevice("<Gamepad>");

        var map    = new InputActionMap("map");
        var action = map.AddAction("action");

        action.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");
        action.AddBinding("<Mouse>/leftButton", groups: "KeyboardMouse");

        var user = new TestUser();

        InputUser.Add(user);

        // Trying to do it before we've assigned actions should throw.
        Assert.That(() => user.AssignControlScheme(gamepadScheme)
                    .AndMaskBindingsFromOtherControlSchemes(), Throws.InvalidOperationException);

        user.AssignInputActions(map);
        user.AssignInputDevice(gamepad);
        user.AssignControlScheme(gamepadScheme)
        .AndMaskBindingsFromOtherControlSchemes();

        Assert.That(action.controls, Is.EquivalentTo(new[] { gamepad.buttonSouth }));
        Assert.That(map.bindingMask, Is.EqualTo(new InputBinding {
            groups = "Gamepad"
        }));
    }
示例#16
0
 public void UnRegisterInputUser(InputUser user)
 {
     if (allInputUsers.Contains(user))
     {
         allInputUsers.Remove(user);
     }
 }
示例#17
0
        public async Task CreateChatRequest(InputUser user) {
            try {
                messages_DhConfig dhConfig = await session.Api.messages_getDhConfig(version, 256);
                byte[] randomSalt;
                if(dhConfig.Constructor == Constructor.messages_dhConfig) {
                    var conf = (Messages_dhConfigConstructor) dhConfig;
                    version = conf.version;
                    g = conf.g;
                    p = new BigInteger(1, conf.p);
                    randomSalt = conf.random;
                } else if(dhConfig.Constructor == Constructor.messages_dhConfigNotModified) {
                    var conf = (Messages_dhConfigNotModifiedConstructor) dhConfig;
                    randomSalt = conf.random;
                } else {
                    throw new InvalidDataException("invalid constructor");
                }

                byte[] a = GetSaltedRandomBytes(256, randomSalt, 0);
                BigInteger ga = BigInteger.ValueOf(g).ModPow(new BigInteger(1, a), p);

                logger.info("generated a: {0}, ga: {1}", BitConverter.ToString(a).Replace("-","").ToLower(), ga);

                int randomId = random.Next(); // also chat id
                EncryptedChat chat = await session.Api.messages_requestEncryption(user, randomId, ga.ToByteArrayUnsigned());
                UpdateChat(chat, a);
            } catch(Exception e) {
                logger.error("creating chat error: {0}", e);
            }
        }
示例#18
0
 private void OnInputDeviceChange(InputUser user, InputUserChange change, InputDevice device)
 {
     if (change == InputUserChange.ControlSchemeChanged)
     {
         _uiInstance.ToggleInputIcon(playerInputVar.currentControlScheme);
     }
 }
示例#19
0
 public void RegisterInputUser(InputUser user)
 {
     if (!allInputUsers.Contains(user))
     {
         allInputUsers.Add(user);
     }
 }
示例#20
0
    public void Users_CanActivateControlScheme_AndManuallyPairMissingDevices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        InputSystem.AddDevice <Mouse>(); // Noise.

        var gamepadScheme = new InputControlScheme("Gamepad")
                            .WithRequiredDevice("<Gamepad>")
                            .WithRequiredDevice("<Gamepad>");

        var user = InputUser.PerformPairingWithDevice(gamepad1);

        var actions = new InputActionMap();

        user.AssociateActionsWithUser(actions);

        user.ActivateControlScheme(gamepadScheme);

        Assert.That(user.pairedDevices, Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(user.hasMissingDevices, Is.True);
        Assert.That(user.controlSchemeMatch.isSuccessfulMatch, Is.False);
        Assert.That(user.controlSchemeMatch[0].control, Is.SameAs(gamepad1));
        Assert.That(user.controlSchemeMatch[1].control, Is.Null);

        InputUser.PerformPairingWithDevice(gamepad2, user: user);

        Assert.That(user.pairedDevices, Is.EquivalentTo(new[] { gamepad1, gamepad2 }));
        Assert.That(actions.devices, Is.EquivalentTo(new[] { gamepad1, gamepad2 }));
        Assert.That(user.hasMissingDevices, Is.False);
        Assert.That(user.controlSchemeMatch.isSuccessfulMatch, Is.True);
        Assert.That(user.controlSchemeMatch[0].control, Is.SameAs(gamepad1));
        Assert.That(user.controlSchemeMatch[1].control, Is.SameAs(gamepad2));
    }
示例#21
0
    public void TODO_Users_CanApplySettings_WithInvertedMouseAxes()
    {
        var mouse = InputSystem.AddDevice <Mouse>();

        var actionMap      = new InputActionMap();
        var positionAction = actionMap.AddAction("position", binding: "<Mouse>/position");
        var deltaAction    = actionMap.AddAction("delta", binding: "<Mouse>/delta");

        Vector2?receivedPosition = null;
        Vector2?receivedDelta    = null;

        positionAction.performed += ctx => receivedPosition = ctx.ReadValue <Vector2>();
        deltaAction.performed    += ctx => receivedDelta = ctx.ReadValue <Vector2>();

        var user = InputUser.PerformPairingWithDevice(mouse);

        user.settings = new InputUserSettings
        {
            invertMouseX = true,
            invertMouseY = true,
        };

        actionMap.Enable();

        InputSystem.QueueStateEvent(mouse, new MouseState
        {
            position = new Vector2(0.123f, 0.234f),
            delta    = new Vector2(0.345f, 0.456f),
        });
        InputSystem.Update();

        //Assert.That(receivedPosition, Is.EqualTo(new Vector2());
        Assert.That(receivedDelta, Is.EqualTo(new Vector2(-0.345f, -0.456f)).Using(Vector2EqualityComparer.Instance));
    }
示例#22
0
    public void Users_CannotActivateControlSchemeWithoutActions()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();
        var user    = InputUser.PerformPairingWithDevice(gamepad);

        Assert.That(() => user.ActivateControlScheme("scheme"), Throws.InvalidOperationException);
    }
示例#23
0
    public void Users_CanActivateControlSchemeByName()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();
        var user    = InputUser.PerformPairingWithDevice(gamepad);

        var actions = new InputActionMap("TestActions");
        var asset   = ScriptableObject.CreateInstance <InputActionAsset>();

        asset.AddActionMap(actions);
        var scheme = asset.AddControlScheme("scheme").WithRequiredDevice <Gamepad>().Done();

        user.AssociateActionsWithUser(actions);

        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        user.ActivateControlScheme("scheme");

        Assert.That(user.controlScheme, Is.EqualTo(scheme));
        Assert.That(actions.bindingMask, Is.EqualTo(new InputBinding {
            groups = "scheme"
        }));
        Assert.That(actions.devices, Is.EqualTo(new[] { gamepad }));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.ControlSchemeChanged)
        }));

        Assert.That(() => user.ActivateControlScheme("doesNotExist"),
                    Throws.ArgumentException.With.Message.Contains("Cannot find").And.Message.Contains("doesNotExist").And
                    .Message.Contains("TestActions"));
    }
示例#24
0
    public void Users_CanUnpairDevicesAndRemoveUser()
    {
        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user = InputUser.PerformPairingWithDevice(gamepad1);

        InputUser.PerformPairingWithDevice(gamepad2, user: user);

        user.UnpairDevicesAndRemoveUser();

        Assert.That(user.valid, Is.False);
        Assert.That(InputUser.all, Is.Empty);
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.Added),
            new UserChange(user, InputUserChange.DevicePaired, gamepad1),
            new UserChange(user, InputUserChange.DevicePaired, gamepad2),
            new UserChange(user, InputUserChange.DeviceUnpaired, gamepad1),
            new UserChange(user, InputUserChange.DeviceUnpaired, gamepad2),
            new UserChange(user, InputUserChange.Removed),
        }));
    }
示例#25
0
    public void Users_CanPairDevice_WithGivenUser()
    {
        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (user, change, device) => { receivedChanges.Add(new UserChange(user, change, device)); };

        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad2, user: user1);

        Assert.That(user1.valid, Is.True);
        Assert.That(user2.valid, Is.True);
        Assert.That(user1, Is.EqualTo(user2));
        Assert.That(InputUser.all, Is.EquivalentTo(new[] { user1 }));
        Assert.That(user1.pairedDevices, Is.EquivalentTo(new[] { gamepad1, gamepad2 }));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user1, InputUserChange.Added),
            new UserChange(user1, InputUserChange.DevicePaired, gamepad1),
            new UserChange(user1, InputUserChange.DevicePaired, gamepad2),
        }));

        receivedChanges.Clear();

        // Pairing with already paired device should do nothing.
        InputUser.PerformPairingWithDevice(gamepad1, user: user1);

        Assert.That(receivedChanges, Is.Empty);
        Assert.That(user1.pairedDevices, Is.EquivalentTo(new[] { gamepad1, gamepad2 }));
    }
示例#26
0
 public RemoteInput(ref InputUser user)
 {
     RemoteMouse       = user.pairedDevices.FirstOrDefault(device => device is Mouse) as Mouse;
     RemoteKeyboard    = user.pairedDevices.FirstOrDefault(device => device is Keyboard) as Keyboard;
     RemoteTouchscreen = user.pairedDevices.FirstOrDefault(device => device is Touchscreen) as Touchscreen;
     RemoteGamepad     = user.pairedDevices.FirstOrDefault(device => device is Gamepad) as Gamepad;
 }
示例#27
0
    public void Users_CanUnpairDevices()
    {
        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);

        InputUser.PerformPairingWithDevice(gamepad2, user: user1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad1);

        user1.UnpairDevice(gamepad1);

        Assert.That(user1.valid, Is.True);
        Assert.That(user2.valid, Is.True);
        Assert.That(user1.pairedDevices, Is.EquivalentTo(new[] { gamepad2 }));
        Assert.That(user2.pairedDevices, Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user1, InputUserChange.Added),
            new UserChange(user1, InputUserChange.DevicePaired, gamepad1),
            new UserChange(user1, InputUserChange.DevicePaired, gamepad2),
            new UserChange(user2, InputUserChange.Added),
            new UserChange(user2, InputUserChange.DevicePaired, gamepad1),
            new UserChange(user1, InputUserChange.DeviceUnpaired, gamepad1),
        }));
    }
示例#28
0
    void OnUnpairedDeviceUsed(InputControl control, InputEventPtr eventPtr)
    {
        // Debug.Log("Unpaired device detected " + control.device.displayName +  " ||| " + control.path);
        // Ignore anything but button presses.
        bool isGamepad = false;
        if (control.device.displayName.Length > 18)
            isGamepad = control.device.displayName.Substring(0, 19) == "Wireless Controller";
        if (!(control is ButtonControl && (control.device.displayName == "Keyboard" || isGamepad)))
            return;
        Debug.Log("Unpaired device added " + control.device.displayName + " " + control.device.deviceId);

        // get a new InputUser, now paired with the device
        InputUser user = InputUser.PerformPairingWithDevice(control.device);

        canvas.transform.GetChild(user.index).GetComponent<Image>().color = playerColors[user.index];
        canvas.transform.GetChild(user.index).GetChild(0).gameObject.SetActive(true);

        audioManager.Play("Menu Tick");

        InputUser.listenForUnpairedDeviceActivity--;

        if (InputUser.listenForUnpairedDeviceActivity < 3) {
            button.interactable = true;
        } else {
            button.interactable = false;
        }
    }
示例#29
0
    ////TODO: this is also where we should look for whether we have custom bindings for the user that we should activate
    public bool OnJoin(InputUser user)
    {
        Debug.Assert(user.valid);
        Debug.Assert(user.pairedDevices.Count == 1, "Players should join on exactly one input device");

        // Associate our InputUser with the actions we're using.
        user.AssociateActionsWithUser(controls);

        // Find out what control scheme to use and whether we have all the devices needed for it.
        var controlScheme = SelectControlSchemeBasedOnDevice(user.pairedDevices[0]);

        Debug.Assert(controlScheme.HasValue, "Must not join player on devices that we have no control scheme for");

        // Try to activate control scheme. The scheme may require additional devices which we
        // also need to pair to the user. This process may fail and we may end up a player missing
        // devices to start playing.
        user.ActivateControlScheme(controlScheme.Value).AndPairRemainingDevices();
        if (user.hasMissingRequiredDevices)
        {
            return(false);
        }

        // Put the player in joined state.
        m_User = user;
        ChangeState(State.Joined);

        return(true);
    }
    public void InstantiatePlayersControls(List <float> ids)
    {
        foreach (Player player in playersInfos)
        {
            PlayerInput p = players[player.Id].AddComponent <PlayerInput>();
            p.actions          = Instantiate(actions);
            p.defaultActionMap = "Deceived";
            PlayerControls pc = players[player.Id].AddComponent <PlayerControls>();
            pc.infos = new Player(player.Id, playersInfos[player.Id].Skin);
            p.user.UnpairDevices();
            InputUser.PerformPairingWithDevice(playersInfos[player.Id].device, p.user);
            p.actions.Enable();
        }

/*         for(int i = 0; i < players.Count;i++){
 *          PlayerInput p = players[i].AddComponent<PlayerInput>();
 *          p.actions = Instantiate(actions);
 *          p.defaultActionMap = "Deceived";
 *          PlayerControls pc = players[i].AddComponent<PlayerControls>();
 *          pc.infos = new Player(i,playersInfos[i].Skin);
 *          p.user.UnpairDevices();
 *          InputUser.PerformPairingWithDevice(playersInfos[i].device,p.user);
 *          p.actions.Enable();
 *      } */
    }
            private void AddUser(TreeViewItem parent, InputUser user, ref int id)
            {
                ////REVIEW: can we get better identification? allow associating GameObject with user?
                var userItem = AddChild(parent, "User #" + user.index, ref id);

                // Control scheme.
                var controlScheme = user.controlScheme;

                if (controlScheme != null)
                {
                    AddChild(userItem, "Control Scheme: " + controlScheme, ref id);
                }

                // Paired and lost devices.
                AddDeviceListToUser("Paired Devices", user.pairedDevices, ref id, userItem);
                AddDeviceListToUser("Lost Devices", user.lostDevices, ref id, userItem);

                // Actions.
                var actions = user.actions;

                if (actions != null)
                {
                    var actionsItem = AddChild(userItem, "Actions", ref id);
                    foreach (var action in actions)
                    {
                        AddActionItem(actionsItem, action, ref id);
                    }

                    parent.children?.Sort((a, b) => string.Compare(a.displayName, b.displayName, StringComparison.CurrentCultureIgnoreCase));
                }
            }
示例#32
0
        private async Task DoBlockUser(InputUser iUser) {
            bool result = await TelegramSession.Instance.Api.contacts_block(iUser);
            
            if (!result) {
                Toaster.ShowNetworkError();
                return;
            }

            NavigationService.GoBack();
        }