public void Performance_FindControlScheme(string device1, string device2 = null, bool success = true)
    {
        var actions = new DefaultInputActions();

        var device1Instance = InputSystem.AddDevice(device1);
        var device2Instance = device2 != null?InputSystem.AddDevice(device2) : null;

        InputDevice[] devices;
        if (device1Instance != null && device2Instance != null)
        {
            devices = new[] { device1Instance, device2Instance }
        }
        ;
        else
        {
            devices = new[] { device1Instance }
        };

        Measure.Method(() =>
        {
            var result = InputControlScheme.FindControlSchemeForDevices(devices, actions.controlSchemes, out _, out var match);
            match.Dispose();
            Assert.That(result, Is.EqualTo(success));
        })
        .MeasurementCount(100)
        .WarmupCount(5)
        .Run();
    }
 // Start is called before the first frame update
 void Awake()
 {
     playerInput = new DefaultInputActions();
     playerInput.Enable();
     playerInput.Player.SetCallbacks(this);
     this.mAnimator       = GetComponent <Animator>();
     this.controller      = GetComponent <CharacterController>();
     this.cameraTransform = Camera.main.transform;
 }
    public void API_DefaultInputActionsClassIsUpToDate()
    {
        const string assetFile = "Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/DefaultInputActions.inputactions";

        Assert.That(File.Exists(assetFile), Is.True);

        var actions         = new DefaultInputActions();
        var jsonFromActions = actions.asset.ToJson();
        var jsonFromFile    = File.ReadAllText(assetFile);

        Assert.That(jsonFromActions.WithAllWhitespaceStripped(), Is.EqualTo(jsonFromFile.WithAllWhitespaceStripped()));
    }
Beispiel #4
0
 /// <summary>
 /// Метод пробуждения игрового объекта (компонента).
 /// Вызывается перед методом Start() даже если скрипт выключен.
 /// </summary>
 private void Awake()
 {
     this.inputActions = new DefaultInputActions();
     this.inputActions.Player.Jump.performed += context => Jump();
     this.inputActions.Player.Move.performed += OnMove;
     this.inputActions.Player.ChangeDirectionalLightIntensity.performed += context => ChangeDirectionalLightIntensity();
     this.inputActions.Player.ChangeColorLerp.performed   += context => ChangeColorLerp();
     this.inputActions.Player.ChangeColor.performed       += context => ChangeColor();
     this.inputActions.Player.ChangeLightSource.performed += context => ChangeLightSource();
     this.inputActions.Player.DestroyOtherBall.performed  += context => DestroyOtherBall();
     this.inputActions.Player.Fire.performed += context => Fire();
 }
Beispiel #5
0
    public void Samples_RebindingUI_SuppressingEventsDoesNotInterfereWithUIInput()
    {
        var keyboard = InputSystem.AddDevice <Keyboard>();

        var asset     = ScriptableObject.CreateInstance <InputActionAsset>();
        var actionMap = asset.AddActionMap("map");
        var action    = actionMap.AddAction("action", binding: "<Keyboard>/a");

        var canvasGO = new GameObject();

        canvasGO.SetActive(false);
        canvasGO.AddComponent <Canvas>();

        // Set up UI input module.
        var eventSystemGO = new GameObject();

        eventSystemGO.SetActive(false);
        var eventSystem   = eventSystemGO.AddComponent <TestEventSystem>();
        var uiInputModule = eventSystemGO.AddComponent <InputSystemUIInputModule>();
        var inputActions  = new DefaultInputActions().asset;

        uiInputModule.actionsAsset = inputActions;
        uiInputModule.submit       = InputActionReference.Create(inputActions["submit"]);

        var bindingButtonGO = new GameObject();

        bindingButtonGO.transform.parent = canvasGO.transform;
        var bindingButton = bindingButtonGO.AddComponent <Button>();

        var bindingLabelGO = new GameObject();

        bindingLabelGO.transform.parent = bindingButtonGO.transform;
        var bindingLabel = bindingLabelGO.AddComponent <Text>();

        var rebind = bindingButtonGO.AddComponent <RebindActionUI>();

        rebind.bindingId       = action.bindings[0].id.ToString();
        rebind.actionReference = InputActionReference.Create(action);
        rebind.bindingText     = bindingLabel;
        bindingButton.onClick.AddListener(rebind.StartInteractiveRebind);

        canvasGO.SetActive(true);
        eventSystemGO.SetActive(true);

        eventSystem.SetSelectedGameObject(bindingButtonGO);
        eventSystem.InvokeUpdate(); // Initial update switches the input module.

        Assert.That(rebind.ongoingRebind, Is.Null);
        Assert.That(bindingLabel.text, Is.EqualTo("A"));

        // As soon as the submit hits, the rebind starts -- which in turn enables suppression
        // of events. This means that the enter key release event will not reach the UI. The
        // UI should be fine with that.
        PressAndRelease(keyboard.enterKey);
        eventSystem.InvokeUpdate();

        Assert.That(rebind.ongoingRebind, Is.Not.Null);
        Assert.That(rebind.ongoingRebind.started, Is.True);
        Assert.That(rebind.ongoingRebind.candidates, Is.Empty);
        Assert.That(bindingLabel.text, Is.EqualTo("<Waiting...>"));
        Assert.That(inputActions["submit"].inProgress, Is.False);

        Press(keyboard.bKey);
        eventSystem.InvokeUpdate();

        Assert.That(rebind.ongoingRebind, Is.Not.Null);
        Assert.That(rebind.ongoingRebind.started, Is.True);
        Assert.That(rebind.ongoingRebind.candidates, Is.EquivalentTo(new[] { keyboard.bKey }));
        Assert.That(bindingLabel.text, Is.EqualTo("<Waiting...>"));
        Assert.That(inputActions["submit"].inProgress, Is.False);

        // Expire rebind wait time.
        currentTime += 1;
        InputSystem.Update();

        Assert.That(rebind.ongoingRebind, Is.Null);
        Assert.That(bindingLabel.text, Is.EqualTo("B"));
        Assert.That(inputActions["submit"].inProgress, Is.False);

        // Start another rebind via "Submit".
        PressAndRelease(keyboard.enterKey);
        eventSystem.InvokeUpdate();

        Assert.That(rebind.ongoingRebind, Is.Not.Null);
        Assert.That(rebind.ongoingRebind.started, Is.True);
        Assert.That(rebind.ongoingRebind.candidates, Is.Empty);
        Assert.That(bindingLabel.text, Is.EqualTo("<Waiting...>"));
    }
Beispiel #6
0
    public IEnumerator Devices_CanHaveOnScreenJoystickControls()
    {
        foreach (var c in Camera.allCameras)
        {
            Object.Destroy(c.gameObject);
        }

        yield return(null);

        InputSystem.AddDevice <Touchscreen>();

        // Set up a full UI scene with an on-screen stick and button.

        var eventSystemGO = new GameObject("EventSystem");
        var eventSystem   = eventSystemGO.AddComponent <TestEventSystem>();
        var uiModule      = eventSystemGO.AddComponent <InputSystemUIInputModule>();

        eventSystem.OnApplicationFocus(true);

        var uiActions = new DefaultInputActions();

        uiModule.actionsAsset = uiActions.asset;
        uiModule.leftClick    = InputActionReference.Create(uiActions.UI.Click);
        uiModule.point        = InputActionReference.Create(uiActions.UI.Point);

        var canvasGO        = new GameObject("Canvas");
        var canvasTransform = canvasGO.AddComponent <RectTransform>();
        var canvas          = canvasGO.AddComponent <Canvas>();

        canvasGO.AddComponent <GraphicRaycaster>();
        canvas.renderMode = RenderMode.ScreenSpaceOverlay;

        var stickGO = new GameObject("Stick");

        stickGO.SetActive(false);
        var stickTransform = stickGO.AddComponent <RectTransform>();
        var stick          = stickGO.AddComponent <OnScreenStick>();

        stickGO.AddComponent <Image>();
        stickTransform.SetParent(canvasTransform);
        stickTransform.anchorMin        = new Vector2(0, 0);
        stickTransform.anchorMax        = new Vector2(0, 0);
        stickTransform.anchoredPosition = new Vector2(100, 100);
        stickTransform.sizeDelta        = new Vector2(100, 100);
        stick.controlPath = "<Gamepad>/leftStick";
        stickGO.SetActive(true);

        var buttonGO = new GameObject("Button");

        buttonGO.SetActive(false);
        var buttonTransform = buttonGO.AddComponent <RectTransform>();
        var button          = buttonGO.AddComponent <OnScreenButton>();

        buttonGO.AddComponent <Button>();
        buttonGO.AddComponent <Image>(); // Give it a Graphic so the raycaster sees it.
        buttonTransform.SetParent(canvasTransform);
        buttonTransform.anchorMin        = new Vector2(0, 0);
        buttonTransform.anchorMax        = new Vector2(0, 0);
        buttonTransform.anchoredPosition = new Vector2(300, 100);
        buttonTransform.sizeDelta        = new Vector2(100, 100);
        button.controlPath = "<Gamepad>/buttonSouth";
        buttonGO.SetActive(true);

        // Add player and hook it up to the gamepad.
        var playerActions = new DefaultInputActions();
        var playerGO      = new GameObject("Player");

        playerGO.SetActive(false);
        var player = playerGO.AddComponent <PlayerInput>();

        player.actions = playerActions.asset;
        player.defaultControlScheme          = "Gamepad";
        player.neverAutoSwitchControlSchemes = true;
        playerGO.SetActive(true);

        yield return(null);

        eventSystem.Update();

        Assert.That(player.devices, Is.EquivalentTo(new[] { Gamepad.all[0] }));

        // Touch the stick and drag it upwards.
        BeginTouch(1, new Vector2(150, 150));
        yield return(null);

        eventSystem.Update();
        Assert.That(eventSystem.IsPointerOverGameObject(), Is.True);
        MoveTouch(1, new Vector2(150, 200));
        yield return(null);

        eventSystem.Update();
        InputSystem.Update(); // Stick is feeding events when responding to UI events.

        Assert.That(Gamepad.all[0].leftStick.ReadValue(), Is.EqualTo(new Vector2(0, 1)).Using(Vector2EqualityComparer.Instance));

        // Press the button.
        BeginTouch(2, new Vector2(350, 150));
        yield return(null);

        eventSystem.Update();
        InputSystem.Update(); // Button is feeding events when responding to UI events.

        Assert.That(Gamepad.all[0].buttonSouth.isPressed, Is.True);

        // Release the button.
        EndTouch(2, new Vector2(351, 151));
        yield return(null);

        eventSystem.Update();
        InputSystem.Update(); // Button is feeding events when responding to UI events.

        Assert.That(Gamepad.all[0].buttonSouth.isPressed, Is.False);
    }
 private void Awake()
 {
     PlayerInputActions = new DefaultInputActions();
 }
Beispiel #8
0
 private void Awake()
 {
     InputActionMap = new DefaultInputActions();
     PlayerBody     = transform.Find("Main").gameObject;
 }