Beispiel #1
0
 public InputPress(InputTestFixture input, params ButtonControl[] controls)
 {
     this.input    = input;
     this.controls = controls;
     foreach (var control in controls)
     {
         input.Press(control);
     }
     InputSystem.Update();
 }
    public IEnumerator SetUp()
    {
        // Set up input.
        inputFixture = new InputTestFixture();
        inputFixture.Setup();

        // See if we have a platform set for the current test.
        var testProperties = TestContext.CurrentContext.Test.Properties;

        if (testProperties.ContainsKey("Platform"))
        {
            var value = (string)testProperties["Platform"][0];
            switch (value)
            {
            case "OSX": platform = RuntimePlatform.OSXPlayer; break;

            default: throw new NotImplementedException();
            }
        }
        else
        {
            platform = Application.platform;
        }
        DemoGame.platform = platform;

        // Give us a fresh scene.
        yield return(SceneManager.LoadSceneAsync("Assets/Demo/Demo.unity", LoadSceneMode.Single));

        game = GameObject.Find("DemoGame").GetComponent <DemoGame>();

        // Set up default device matrix for current platform.
        switch (platform)
        {
            #if UNITY_STANDALONE_OSX || UNITY_EDITOR
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.OSXEditor:
            keyboard    = InputSystem.AddDevice <Keyboard>();
            mouse       = InputSystem.AddDevice <Mouse>();
            ps4Gamepad  = InputSystem.AddDevice <DualShockGamepadHID>();
            xboxGamepad = InputSystem.AddDevice <XInputController>();
            ////TODO: joystick
            break;
            #endif

        ////TODO: other platforms
        default:
            throw new NotImplementedException();
        }
    }
    public IEnumerator SetUp()
    {
        // Set up input.
        input = new InputTestFixture();
        input.Setup();

        // See if we have a platform set for the current test.
        var testProperties = TestContext.CurrentContext.Test.Properties;

        if (testProperties.ContainsKey("Platform"))
        {
            var value = (string)testProperties["Platform"][0];
            switch (value.ToLower())
            {
            case "windows":
                platform = RuntimePlatform.WindowsPlayer;
                break;

            case "osx":
                platform = RuntimePlatform.OSXPlayer;
                break;

            case "android":
                platform = RuntimePlatform.Android;
                break;

            case "ios":
                platform = RuntimePlatform.IPhonePlayer;
                break;

            default:
                throw new NotImplementedException();
            }
        }
        else
        {
            platform = Application.platform;
        }
        DemoGame.platform = platform;

        // Give us a fresh scene.
        yield return(SceneManager.LoadSceneAsync("Assets/Demo/Demo.unity", LoadSceneMode.Single));

        game = GameObject.Find("DemoGame").GetComponent <DemoGame>();

        // If there's a "Platform" property on the test or no specific "Device" property, add the default
        // set of devices for the current platform.
        if (testProperties.ContainsKey("Platform") || !testProperties.ContainsKey("Device"))
        {
            // Set up default device matrix for current platform.
            // NOTE: We use strings here instead of types as not all devices are available in all players.
            switch (platform)
            {
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                keyboard    = (Keyboard)InputSystem.AddDevice("Keyboard");
                mouse       = (Mouse)InputSystem.AddDevice("Mouse");
                pen         = (Pen)InputSystem.AddDevice("Pen");
                touchscreen = (Touchscreen)InputSystem.AddDevice("Touchscreen");
                ps4Gamepad  = (DualShockGamepad)InputSystem.AddDevice("DualShockGamepadHID");
                xboxGamepad = (XInputController)InputSystem.AddDevice("XInputController");
                ////TODO: joystick
                break;

            case RuntimePlatform.OSXPlayer:
            case RuntimePlatform.OSXEditor:
                keyboard    = (Keyboard)InputSystem.AddDevice("Keyboard");
                mouse       = (Mouse)InputSystem.AddDevice("Mouse");
                ps4Gamepad  = (DualShockGamepad)InputSystem.AddDevice("DualShockGamepadHID");
                xboxGamepad = (XInputController)InputSystem.AddDevice("XInputController");
                ////TODO: joystick
                break;

            ////TODO: other platforms
            default:
                throw new NotImplementedException();
            }
        }

        // Add whatever devices are specified in explicit "Device" properties.
        if (testProperties.ContainsKey("Device"))
        {
            foreach (var value in testProperties["Device"])
            {
                switch (((string)value).ToLower())
                {
                case "gamepad":
                    InputSystem.AddDevice <Gamepad>();
                    break;

                case "keyboard":
                    InputSystem.AddDevice <Keyboard>();
                    break;

                case "mouse":
                    InputSystem.AddDevice <Mouse>();
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }

        // Check if we should add VR support.
        if (testProperties.ContainsKey("VR"))
        {
            var value = (string)testProperties["VR"][0];
            switch (value.ToLower())
            {
            case "":
            case "any":
                // Add a combination of generic XRHMD and XRController instances that don't
                // represent any specific set of hardware out there.
                hmd       = InputSystem.AddDevice <XRHMD>();
                leftHand  = InputSystem.AddDevice <XRController>();
                rightHand = InputSystem.AddDevice <XRController>();
                InputSystem.SetDeviceUsage(leftHand, CommonUsages.LeftHand);
                InputSystem.SetDeviceUsage(rightHand, CommonUsages.RightHand);
                break;

            default:
                throw new NotImplementedException();
            }

            DemoGame.vrSupported = true;
        }

        // Check if we should add Steam support.
        if (testProperties.ContainsKey("Steam"))
        {
            ////TODO: create steam test fixture
            steamController = InputSystem.AddDevice("SteamDemoController");
        }
    }