示例#1
0
        public void TryRegisterDevice(InputDevice device)
        {
            if (IsDeviceAdded(device))
            {
                return;
            }

            int playerId = -1;
            if (isXInputDevice(device))
            {
                XInputDevice xInputDevice = device as XInputDevice;
                playerId = xInputDevice.DeviceIndex;
            }
            else
            {
                playerId = NextId;
            }

            if (playerId >= 0)
            {
                PlayerDevice newPlayer = new PlayerDevice()
                {
                    id = playerId,
                    InControlDevice = device
                };
                AddPlayer(newPlayer);
            }
        }
示例#2
0
        public void Initialize()
        {
            List <Input> viableInputs = new List <Input>();

            for (int deviceNum = 0; deviceNum < InControl.InputManager.Devices.Count; ++deviceNum)
            {
                InControl.InputDevice device = InControl.InputManager.Devices[deviceNum];

                if (device != null)
                {
                    Input input = inputFactory.Create(deviceNum, device);
                    viableInputs.Add(input);
                }
            }

            if (viableInputs.Count == 0)
            {
                InControl.InputDevice device = new UnityInputDevice(new KeyboardAndMouseProfile());
                InControl.InputManager.AttachDevice(device);

                if (device != null)
                {
                    Input input = inputFactory.Create(0, device);
                    viableInputs.Add(input);
                }
            }

            inputs = new ReadOnlyCollection <Input>(viableInputs);
        }
		InputControlType ListenForControl( BindingListenOptions listenOptions, InputDevice device )
		{
			if (device.IsKnown)
			{
				var controlCount = device.Controls.Length;
				for (int i = 0; i < controlCount; i++)
				{
					var control = device.Controls[i];
					if (control != null && IsPressed( control ))
					{
						if (listenOptions.IncludeNonStandardControls || control.IsStandard)
						{
							var target = control.Target;
							if (target == InputControlType.Command && listenOptions.IncludeNonStandardControls)
							{
								continue;
							}
							return target;
						}
					}
				}
			}

			return InputControlType.None;
		}
示例#4
0
		public override float GetValue( InputDevice inputDevice )
		{
			var scale = 0.2f;

			switch (Control)
			{
				case Mouse.LeftButton:
					return Input.GetMouseButton( 0 ) ? 1.0f : 0.0f;
				case Mouse.RightButton:
					return Input.GetMouseButton( 1 ) ? 1.0f : 0.0f;
				case Mouse.MiddleButton:
					return Input.GetMouseButton( 2 ) ? 1.0f : 0.0f;
				case Mouse.NegativeX:
					return -Mathf.Min( Input.GetAxisRaw( "mouse x" ) * scale, 0.0f );
				case Mouse.PositiveX:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse x" ) * scale );
				case Mouse.NegativeY:
					return -Mathf.Min( Input.GetAxisRaw( "mouse y" ) * scale, 0.0f );
				case Mouse.PositiveY:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse y" ) * scale );
				case Mouse.NegativeScrollWheel:
					return -Mathf.Min( Input.GetAxisRaw( "mouse z" ) * scale, 0.0f );
				case Mouse.PositiveScrollWheel:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse z" ) * scale );
			}

			return 0.0f;
		}
    private void HandoutDevices()
    {
        if (!inputRequests.Any())
        {
            return;
        }
        IEnumerable <InputDevice> unusedDevices =
            from pair in devices
            where pair.Key != null && !pair.Value
            select pair.Key;
        List <InputDevice> sortedDevices = unusedDevices.OrderBy(d => d.SortOrder).ToList();

        if (sortedDevices.Any())
        {
            // This int is outside the loop because it must be used to remove
            // all fulfilled requests (if there are more requests than devices,
            // i will go up to the index of the first request left unfulfilled)
            int i = 0;
            for (; i < sortedDevices.Count && i < inputRequests.Count; i++)
            {
                InputDevice         device          = sortedDevices[i];
                InputDeviceCallback createdCallback = inputRequests.Values[i].Item1;
                Action action = inputRequests.Values[i].Item2;
                devices[device] = true;
                actions[device] = action;
                createdCallback(device);
            }
            Dictionary <int, Tuple <InputDeviceCallback, Action> > unfufilledRequestsDictionary = inputRequests.Skip(i).ToDictionary(
                pair => pair.Key, pair => pair.Value);
            inputRequests = new SortedList <int, Tuple <InputDeviceCallback, Action> >(unfufilledRequestsDictionary);
        }
    }
示例#6
0
    private void Update()
    {
        InControl.InputDevice input = GameInput.GetPlayerDevice(0);

        if (EventSystem.current.currentSelectedGameObject == resolutionSelectable.gameObject)
        {
            if (input.LeftStickX.Value > 0.3f || input.DPadRight.WasPressed)
            {
                if (!wasInput)
                {
                    SelectNextResolution();
                    wasInput = true;
                }
            }
            else if (input.LeftStickX.Value < -0.3f || input.DPadLeft.WasPressed)
            {
                if (!wasInput)
                {
                    SelectPrevResolution();
                    wasInput = true;
                }
            }
            else if (wasInput)
            {
                wasInput = false;
            }
        }
    }
		public override float GetValue( InputDevice inputDevice )
		{
			var button = buttonTable[(int) Control];
			if (button >= 0)
			{
				return Input.GetMouseButton( button ) ? 1.0f : 0.0f;
			}

			switch (Control)
			{
				case Mouse.NegativeX:
					return -Mathf.Min( Input.GetAxisRaw( "mouse x" ) * ScaleX, 0.0f );
				case Mouse.PositiveX:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse x" ) * ScaleX );

				case Mouse.NegativeY:
					return -Mathf.Min( Input.GetAxisRaw( "mouse y" ) * ScaleY, 0.0f );
				case Mouse.PositiveY:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse y" ) * ScaleY );

				case Mouse.NegativeScrollWheel:
					return -Mathf.Min( Input.GetAxisRaw( "mouse z" ) * ScaleZ, 0.0f );
				case Mouse.PositiveScrollWheel:
					return Mathf.Max( 0.0f, Input.GetAxisRaw( "mouse z" ) * ScaleZ );
			}

			return 0.0f;
		}
示例#8
0
        private void UpdateControllerPlayerInputs(int playerID, InControl.InputDevice inputDevice)
        {
            if (inputDevice == null)
            {
                return;
            }

            var playerInput = playerInputs[playerID];

            playerInput.PlayerDevice = inputDevice.Name;

            playerInput.HorizontalMovement = inputDevice.LeftStick.X;
            playerInput.VerticalMovement   = inputDevice.LeftStick.Y;

            playerInput.HorizontalAim = inputDevice.RightStick.X;
            playerInput.VerticalAim   = inputDevice.RightStick.Y;

            playerInput.Jump     = inputDevice.LeftBumper.IsPressed;
            playerInput.Shooting = inputDevice.RightBumper.IsPressed;
            playerInput.Dashing  = inputDevice.RightTrigger.IsPressed;

            playerInput.Menu   = inputDevice.Command.WasPressed;
            playerInput.Select = inputDevice.Action1.WasPressed;
            playerInput.Back   = inputDevice.Action2.WasPressed;
        }
示例#9
0
		void UpdateCubeWithInputDevice( InputDevice inputDevice )
		{
			// Set object material color based on which action is pressed.
			if (inputDevice.Action1)
			{
				GetComponent<Renderer>().material.color = Color.green;
			}
			else
			if (inputDevice.Action2)
			{
				GetComponent<Renderer>().material.color = Color.red;
			}
			else
			if (inputDevice.Action3)
			{
				GetComponent<Renderer>().material.color = Color.blue;
			}
			else
			if (inputDevice.Action4)
			{
				GetComponent<Renderer>().material.color = Color.yellow;
			}
			else
			{
				GetComponent<Renderer>().material.color = Color.white;
			}
			
			// Rotate target object with both sticks and d-pad.
			transform.Rotate( Vector3.down,  500.0f * Time.deltaTime * inputDevice.Direction.X, Space.World );
			transform.Rotate( Vector3.right, 500.0f * Time.deltaTime * inputDevice.Direction.Y, Space.World );
			transform.Rotate( Vector3.down,  500.0f * Time.deltaTime * inputDevice.RightStickX, Space.World );
			transform.Rotate( Vector3.right, 500.0f * Time.deltaTime * inputDevice.RightStickY, Space.World );
		}
        Color GetColorFromActionButtons( InputDevice inputDevice )
        {
            if (inputDevice.Action1)
            {
                return Color.green;
            }

            if (inputDevice.Action2)
            {
                return Color.red;
            }

            if (inputDevice.Action3)
            {
                return Color.blue;
            }

            if (inputDevice.Action4)
            {
                return Color.yellow;
            }

            // Test for a combo keypress, mapped to left bumper.
            if (inputDevice.LeftBumper)
            {
                return Color.magenta;
            }

            return Color.white;
        }
        public VirtualControlInputDeviceManager()
        {
            device = new InputDevice( "VirtualControlInputDevice", 2, 2 );
            device.AddAnalogControl( InputControlType.LeftStickX, "Virtual Stick" );
            device.AddAnalogControl( InputControlType.LeftStickY, "Virtual Stick" );
            device.AddButtonControl( InputControlType.Action1, "Virtual Button 1" );
            device.AddButtonControl( InputControlType.Action2, "Virtual Button 2" );
            InputManager.AttachDevice( device );

            var virtualStick = new VirtualControlStick( InputControlType.LeftStickX, InputControlType.LeftStickY );
            Node.AddChild( virtualStick );
            virtualControls.Add( virtualStick );

            var buttonPosition1 = new Vector2( Futile.screen.halfWidth - 128, -Futile.screen.halfHeight + 64 );
            var virtualButton1 = new VirtualControlButton( InputControlType.Action1, "VirtualInput/ButtonA", buttonPosition1 );
            Node.AddChild( virtualButton1 );
            virtualControls.Add( virtualButton1 );

            var buttonPosition2 = new Vector2( Futile.screen.halfWidth - 64, -Futile.screen.halfHeight + 128 );
            var virtualButton2 = new VirtualControlButton( InputControlType.Action2, "VirtualInput/ButtonB", buttonPosition2 );
            Node.AddChild( virtualButton2 );
            virtualControls.Add( virtualButton2 );

            Futile.touchManager.AddMultiTouchTarget( this );
        }
示例#12
0
        Player CreatePlayer( InputDevice inputDevice )
        {
            if (players.Count < maxPlayers)
            {
                // Pop a position off the list. We'll add it back if the player is removed.
                var playerPosition = playerPositions[0];
                playerPositions.RemoveAt( 0 );

                var gameObject = (GameObject) Instantiate( playerPrefab, playerPosition, Quaternion.identity );
                var player = gameObject.GetComponent<Player>();

                if (inputDevice == null)
                {
                    // We could create a new instance, but might as well reuse the one we have
                    // and it lets us easily find the keyboard player.
                    player.Actions = keyboardListener;
                }
                else
                {
                    // Create a new instance and specifically set it to listen to the
                    // given input device (joystick).
                    var actions = PlayerActions.CreateWithJoystickBindings();
                    actions.Device = inputDevice;

                    player.Actions = actions;
                }

                players.Add( player );

                return player;
            }

            return null;
        }
		public override bool GetState( InputDevice inputDevice )
		{
			if (inputDevice == null)
			{
				return false;
			}

			return inputDevice.GetControl( Control ).State;
		}
		public override float GetValue( InputDevice inputDevice )
		{
			if (inputDevice == null)
			{
				return 0.0f;
			}

			return inputDevice.GetControl( Control ).Value;
		}
		public override bool GetState( InputDevice device )
		{
			if (device == null)
			{
				return false;
			}

			return Utility.IsNotZero( GetValue( device ) );
		}
示例#16
0
    //Check for interact
    void OnTriggerStay(Collider c)
    {
        InControl.InputDevice input = InControl.InputManager.ActiveDevice;

        if (c.transform.tag == "Interactable" && (input.GetControl(InControl.InputControlType.Action1) || input.GetControl(InControl.InputControlType.Action3) || Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.Space)))
        {
            c.GetComponent <iInteractable>().Use(this.gameObject);
        }
    }
		public ICadeDeviceManager()
		{
			timeStep = Mathf.FloorToInt( Time.fixedDeltaTime * 1000.0f );
			bufferSize = 1;
			state = new RingBuffer<ICadeState>( bufferSize );

			device = new ICadeDevice( this );
			devices.Add( device );
		}
		public bool GetState( InputDevice inputDevice )
		{
			for (int i = 0; i < KeyCodeList.Length; i++)
			{
				if (!Input.GetKey( KeyCodeList[i] ))
				{
					return false;
				}
			}
			return true;
		}
示例#19
0
    private void GivenInputDevice(IC.InputDevice device)
    {
        inputDevice = device;
        GameManager.NotificationManager.NotifyMessage(Message.InputDeviceAssigned, gameObject);
        PlayerPuppet puppet = GetComponent <PlayerPuppet>();

        if (puppet == null || !puppet.doPuppeting)
        {
            broadcast = StartCoroutine(ControlsBroadcast());
        }
    }
示例#20
0
        public override bool GetState( InputDevice inputDevice )
        {
            foreach(InputControlSource source in sources)
            {
                if(source.GetState( inputDevice ))
                {
                    return true;
                }
            }

            return false;
        }
示例#21
0
        public void Update( IEnumerable<FTouch> touches, InputDevice device, float updateTime )
        {
            value = 0.0f;

            foreach (var touch in touches)
            {
                UpdateWithTouch( touch );
            }

            device.GetControl( controlType ).UpdateWithValue( value, updateTime );

            alpha = Mathf.MoveTowards( alpha, value > 0.0f ? 1.0f : 0.5f, 1.0f / 15.0f );
        }
示例#22
0
 public static void CheckButtonEvents(IC.InputControlType type,
                                      IC.InputDevice device,
                                      GameObject player,
                                      Message?pressedEvent  = null,
                                      Message?releasedEvent = null)
 {
     if (device != null)
     {
         IC.InputControl button = device.GetControl(type);
         SendButtonEvent(button.WasPressed, button.WasReleased,
                         player, pressedEvent, releasedEvent);
     }
 }
示例#23
0
        public void Update( IEnumerable<FTouch> touches, InputDevice device, float updateTime )
        {
            foreach (var touch in touches)
            {
                UpdateWithTouch( touch );
            }

            device.GetControl( xAxis ).UpdateWithValue( value.x, updateTime );
            device.GetControl( yAxis ).UpdateWithValue( value.y, updateTime );

            alpha = Mathf.MoveTowards( alpha, touchId == -1 ? 0.5f : 1.0f, 1.0f / 15.0f );

            headSprite.SetPosition( delta );
        }
示例#24
0
        GolfPlayerController FindPlayerUsingDevice( InputDevice inputDevice )
        {
            var playerCount = players.Count;
            for (int i = 0; i < playerCount; i++)
            {
                var player = players[i];
                if (player.device == inputDevice)
                {
                    return player;
                }
            }

            return null;
        }
示例#25
0
    private void InputDeviceDisconnectedCallback()
    {
        PlayerMovement movement = GetComponent <PlayerMovement>();

        movement?.StopAllMovement();

        if (broadcast != null)
        {
            StopCoroutine(broadcast);
        }
        broadcast = null;
        stateManager?.AttemptStartState(delegate { }, delegate { });
        inputDevice = null;
    }
示例#26
0
        Player FindPlayerUsingJoystick( InputDevice inputDevice )
        {
            var playerCount = players.Count;
            for (int i = 0; i < playerCount; i++)
            {
                var player = players[i];
                if (player.Actions.Device == inputDevice)
                {
                    return player;
                }
            }

            return null;
        }
示例#27
0
    private void InputDeviceDisconnectedCallback()
    {
        // TODO dkonik: Since we are making a public game now, we need to do more on
        // controller disconnect than just stopping movement and stuff.
        //PlayerMovement movement = GetComponent<PlayerMovement>();
        //movement?.StopAllMovement();

        if (broadcast != null)
        {
            StopCoroutine(broadcast);
        }
        broadcast = null;
        stateManager.TransitionToState(State.StartupState);
        inputDevice = null;
    }
示例#28
0
		public override float GetValue( InputDevice inputDevice )
		{
			int axisValue = 0;
			
			if (Input.GetKey( negativeKeyCode ))
			{
				axisValue--;
			}
			
			if (Input.GetKey( positiveKeyCode ))
			{
				axisValue++;
			}
			
			return axisValue;
		}
		public float GetValue( InputDevice inputDevice )
		{
			int axisValue = 0;
			
			if (Input.GetKey( NegativeKeyCode ))
			{
				axisValue--;
			}
			
			if (Input.GetKey( PositiveKeyCode ))
			{
				axisValue++;
			}
			
			return axisValue;
		}
    // Returns the next available input device; null if none is available.
    // Registers the action to be called when a device is detached (one-time only).
    public InputDevice GetInputDevice(Action action)
    {
        KeyValuePair <InputDevice, bool> e = devices.FirstOrDefault(ee => ee.Value == false);

        InputDevice device = e.Key;

        if (device == null)
        {
            return(null);
        }

        devices[device] = true;
        actions[device] = action;

        return(device);
    }
示例#31
0
        public override float GetValue( InputDevice inputDevice )
        {
            // CAVEAT: multiple input sources could be giving values, but we only want one
            //   thus, we'll take the first one in the list
            //   so the user can control priority simply by ordering the list
            foreach(InputControlSource source in sources)
            {
                var thisValue = source.GetValue( inputDevice );
                if(thisValue != 0f)
                {
                    return thisValue;
                }
            }

            return 0f;
        }
示例#32
0
        Player CreatePlayer( InputDevice inputDevice )
        {
            if (players.Count < maxPlayers)
            {
                // Pop a position off the list. We'll add it back if the player is removed.
                var playerPosition = playerPositions[0];
                playerPositions.RemoveAt( 0 );

                var gameObject = (GameObject) Instantiate( playerPrefab, playerPosition, Quaternion.identity );
                var player = gameObject.GetComponent<Player>();
                player.Device = inputDevice;
                players.Add( player );

                return player;
            }

            return null;
        }
        FencingInputHandler CreatePlayer( InputDevice inputDevice )
        {
            if (players.Count < maxPlayers)
            {
                // Pop a position off the list. We'll add it back if the player is removed.
                var playerPosition = spawnPoints[0];
                spawnPoints.RemoveAt( 0 );
                var gameObject = (GameObject) Instantiate( playerPrefab, playerPosition, Quaternion.identity );
                var player = gameObject.GetComponent<FencingInputHandler>();
                player.device = inputDevice;
            //	Debug.Log("Player count: " + players.Count + " color: " + playerColors[players.Count]);
                //player.GetComponent<PlayerControllerMatt>().color = playerColors[players.Count];
                player.transform.parent = this.transform;
                players.Add( player );

                return player;
            }

            return null;
        }
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeKeys)
			{
				return null;
			}

			if (detectFound.Count > 0)
			{
				if (!detectFound.IsPressed)
				{
					if (detectPhase == 2)
					{
						var bindingSource = new KeyBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var keyCombo = KeyCombo.Detect( listenOptions.IncludeModifiersAsFirstClassKeys );
			if (keyCombo.Count > 0)
			{
				if (detectPhase == 1)
				{
					detectFound = keyCombo;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeControllers || device.IsUnknown)
			{
				return null;
			}

			if (detectFound != InputControlType.None)
			{
				if (!IsPressed( detectFound, device ))
				{
					if (detectPhase == 2)
					{
						var bindingSource = new DeviceBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var control = ListenForControl( listenOptions, device );
			if (control != InputControlType.None)
			{
				if (detectPhase == 1)
				{
					detectFound = control;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeMouseButtons)
			{
				return null;
			}

			if (detectFound != Mouse.None)
			{
				if (!MouseBindingSource.ButtonIsPressed( detectFound ))
				{
					if (detectPhase == 2)
					{
						var bindingSource = new MouseBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var control = ListenForControl();
			if (control != Mouse.None)
			{
				if (detectPhase == 1)
				{
					detectFound = control;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
		public static void Setup()
		{
			Platform = (SystemInfo.operatingSystem + " " + SystemInfo.deviceModel).ToUpper();

			initialTime = 0.0f;
			currentTime = 0.0f;
			lastUpdateTime = 0.0f;

			currentTick = 0;

			inputDeviceManagers.Clear();
			Devices.Clear();
			activeDevice = InputDevice.Null;

			isSetup = true;

			#if UNITY_STANDALONE_WIN || UNITY_EDITOR
			if (enableXInput)
			{
				if (Application.platform == RuntimePlatform.WindowsPlayer ||
					Application.platform == RuntimePlatform.WindowsEditor)
				{
					HideDevicesWithProfile( typeof( Xbox360WinProfile ) );
					HideDevicesWithProfile( typeof( LogitechF710ModeXWinProfile ) );
					InputManager.AddDeviceManager( new XInputDeviceManager() );
				}
			}
			#endif

			AddDeviceManager( new UnityInputDeviceManager() );

			if (OnSetup != null)
			{
				OnSetup.Invoke();
				OnSetup = null;
			}
		}
示例#38
0
		Color GetColorFromActionButtons( InputDevice inputDevice )
		{
			if (inputDevice.Action1)
			{
				return Color.green;
			}

			if (inputDevice.Action2)
			{
				return Color.red;
			}

			if (inputDevice.Action3)
			{
				return Color.blue;
			}

			if (inputDevice.Action4)
			{
				return Color.yellow;
			}

			return Color.white;
		}
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeUnknownControllers || device.IsKnown)
			{
				return null;
			}

			if (detectPhase == DetectPhase.WaitForControlRelease && detectFound)
			{
				if (!IsPressed( detectFound, device ))
				{
					var bindingSource = new UnknownDeviceBindingSource( detectFound );
					Reset();
					return bindingSource;
				}
			}

			var control = ListenForControl( listenOptions, device );
			if (control)
			{
				if (detectPhase == DetectPhase.WaitForControlPress)
				{
					detectFound = control;
					detectPhase = DetectPhase.WaitForControlRelease;
				}
			}
			else
			{
				if (detectPhase == DetectPhase.WaitForInitialRelease)
				{
					detectPhase = DetectPhase.WaitForControlPress;
				}
			}

			return null;
		}
 public override float GetValue(InputDevice device)
 {
     return(Control.GetValue(device));
 }
示例#41
0
    // Check for pause and select button press
    void Update()
    {
        InControl.InputDevice input = InControl.InputManager.ActiveDevice;

        if ((Input.GetKeyDown(KeyCode.Escape) || input.GetControl(InControl.InputControlType.Start)) && m_state.Peek() == State.InGame)
        {
            m_state.Push(State.Pause);
            m_inGameUI.SetActive(false);
            m_pauseMenuUI.SetActive(true);
            m_pauseMenuUI.GetComponentInChildren <Button>().Select();//Set selected (random first button)
            Pause();
        }

        else if ((Input.GetKeyDown(KeyCode.Tab) || input.GetControl(InControl.InputControlType.Select) || input.GetControl(InControl.InputControlType.DPadDown)) && m_state.Peek() == State.InGame)
        {
            m_state.Push(State.Upgrades);
            m_inGameUI.SetActive(false);
            m_mutagenMenuUI.SetActive(true);
            m_mutagenMenuUI.GetComponentInChildren <Button>().Select();//Set selected (random first button)
            Pause();
        }

        else if ((Input.GetKeyDown(KeyCode.Escape) || input.GetControl(InControl.InputControlType.Action2)) && (m_state.Peek() == State.Upgrades || m_state.Peek() == State.Settings || m_state.Peek() == State.Pause))
        {
            m_state.Pop(); //Out of upgrades/options to inGame
            if (m_state.Peek() == State.Title)
            {
                m_titleMenuUI.SetActive(true);
                m_settingsUI.SetActive(false);
            }
            else if (m_state.Peek() == State.Pause)
            {
                m_pauseMenuUI.SetActive(true);
                m_settingsUI.SetActive(false);
            }
            else
            {
                m_inGameUI.SetActive(true);
                //set all possibilities to false
                m_mutagenMenuUI.SetActive(false);
                m_scrapMenuUI.SetActive(false);
                m_pauseMenuUI.SetActive(false);
                m_settingsUI.SetActive(false);
                //Unpause
                UnPause();
            }
        }
        else if ((Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A) || input.GetControl(InControl.InputControlType.LeftBumper) || input.GetControl(InControl.InputControlType.RightBumper)) && !m_menuSwitch && m_state.Peek() == State.Upgrades)
        {
            m_menuSwitch = true;
            ScrapMutaMenuToggle();
        }
        else if (!input.GetControl(InControl.InputControlType.LeftBumper) && !input.GetControl(InControl.InputControlType.RightBumper) && m_menuSwitch)
        {
            m_menuSwitch = false;
        }
        if (m_state.Peek() == State.InGame)
        {
            m_timer += Time.deltaTime;
        }
    }
示例#42
0
 public float GetValue(InputDevice inputDevice)
 {
     return(Input.GetAxisRaw(MouseAxisQuery));
 }
示例#43
0
        internal static bool SetupInternal()
        {
            if (IsSetup)
            {
                return(false);
            }

#if !NETFX_CORE && !UNITY_WEBPLAYER && !UNITY_EDITOR_OSX && (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
            Platform = Utility.GetWindowsVersion().ToUpper();
#else
            Platform = (SystemInfo.operatingSystem + " " + SystemInfo.deviceModel).ToUpper();
#endif

            enabled = true;

            initialTime          = 0.0f;
            currentTime          = 0.0f;
            lastUpdateTime       = 0.0f;
            currentTick          = 0;
            applicationIsFocused = true;

            deviceManagers.Clear();
            deviceManagerTable.Clear();
            devices.Clear();
            Devices      = new ReadOnlyCollection <InputDevice>(devices);
            activeDevice = InputDevice.Null;

            playerActionSets.Clear();

            // TODO: Can this move further down along with the OnSetup callback?
            IsSetup = true;

            var enableUnityInput = true;

            var nativeInputIsEnabled = EnableNativeInput && NativeInputDeviceManager.Enable();
            if (nativeInputIsEnabled)
            {
                enableUnityInput = false;
            }

#if UNITY_STANDALONE_WIN || UNITY_EDITOR
            if (EnableXInput && enableUnityInput)
            {
                XInputDeviceManager.Enable();
            }
#endif

#if UNITY_IOS
            if (EnableICade)
            {
                ICadeDeviceManager.Enable();
            }
#endif

#if UNITY_XBOXONE
            if (XboxOneInputDeviceManager.Enable())
            {
                enableUnityInput = false;
            }
#endif

#if UNITY_SWITCH
            if (NintendoSwitchInputDeviceManager.Enable())
            {
                enableUnityInput = false;
            }
#endif

            // TODO: Can this move further down after the UnityInputDeviceManager is added?
            // Currently, it allows use of InputManager.HideDevicesWithProfile()
            if (OnSetup != null)
            {
                OnSetup.Invoke();
                OnSetup = null;
            }

#if UNITY_ANDROID && INCONTROL_OUYA && !UNITY_EDITOR
            enableUnityInput = false;
#endif

            if (enableUnityInput)
            {
                AddDeviceManager <UnityInputDeviceManager>();
            }

            return(true);
        }
 public override bool GetState(InputDevice inputDevice)
 {
     return(Utility.IsNotZero(GetValue(inputDevice)));
 }
示例#45
0
 public bool LastChangedAfter(InputDevice device)
 {
     return(device == null || LastChangeTick > device.LastChangeTick);
 }
示例#46
0
 public override bool GetState(InputDevice inputDevice)
 {
     return(Control.IsPressed);
 }
示例#47
0
 public bool LastChangedAfter(InputDevice otherDevice)
 {
     return(LastChangeTick > otherDevice.LastChangeTick);
 }
示例#48
0
 /// <summary>
 /// Read a bool value from the binding source in the context of an optional InputDevice.
 /// </summary>
 /// <returns><c>true</c> if the value of the binding is non-zero; otherwise <c>false</c>.</returns>
 /// <param name="inputDevice">An input device which serves as the context for this source, if applicable. Pass in null when not applicable.</param>
 public abstract bool GetState(InputDevice inputDevice);
    // Source: http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html
    public Vector2 GetLeftStickInput(InputDevice device)
    {
        Vector2 stickInput = new Vector2(device.LeftStickX, device.LeftStickY);

        return(ApplyRadialDeadzone(stickInput));
    }
 public User(InputDevice device)
 {
     this.device = device;
 }
示例#51
0
 public void SetControllerId(int controllerId_)
 {
     controllerId    = controllerId_;
     inControlDevice = InControl.InputManager.Devices[controllerId];
 }
示例#52
0
 internal void Update(ulong updateTick, float deltaTime, InputDevice device)
 {
     Device = device;
     UpdateBindings(updateTick, deltaTime);
     DetectBindings();
 }
示例#53
0
    // Update is called once per frame
    void Update()
    {
        // Stop drilling after x seconds
        AnimationEnum nextAnimation = animation;

        if (animation == AnimationEnum.Drill)
        {
            const float SecondsToDrill = 3f;
            if (Time.time - m_DrillStartTime > SecondsToDrill)
            {
                m_DrillStartTime = 0;
                nextAnimation    = AnimationEnum.Idle;
            }
        }


        float movementX = 0;
        float movementY = 0;
        bool  jump      = false;
        bool  drill     = false;

        // Use last device which provided input.
        if (InControl.InputManager.Devices.Count == 0)
        {
            return;
        }
        if (PlayerIndex < InControl.InputManager.Devices.Count)
        {
            InControl.InputDevice device = InControl.InputManager.Devices[PlayerIndex];
            movementX = device.LeftStickX;
            if (device.DPadLeft)
            {
                movementX = -1;
            }
            else if (device.DPadRight)
            {
                movementX = 1;
            }
            movementY = device.LeftStickY;
            if (device.DPadUp)
            {
                movementY = 1;
            }
            else if (device.DPadDown)
            {
                movementY = -1;
            }
            jump  = device.Action1.WasPressed;
            drill = device.Action3.WasPressed;
        }
        else
        {
            InControl.InputDevice device = InControl.InputManager.Devices[0];
            movementX = device.RightStickX;
            movementY = device.RightStickY;
            jump      = device.Action2.WasPressed;
            drill     = device.Action4.WasPressed;
        }

        // Move if able
        if (nextAnimation != AnimationEnum.Drill)
        {
            rb.velocity = new Vector2(3.0f * movementX, rb.velocity.y);

            if (rb.velocity.x == 0)
            {
                nextAnimation = AnimationEnum.Idle;
            }
            else
            {
                nextAnimation = AnimationEnum.Walk;
            }
        }

        // Look the correct way
        if (rb.velocity.x < 0)
        {
            transform.localScale = new Vector3(MirrorHack * -1 * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
        }
        else if (rb.velocity.x > 0)
        {
            transform.localScale = new Vector3(MirrorHack * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
        }

        // Apply the animation
        SetAnimation(nextAnimation);

        // Walking sound
        if (collider.Raycast(Vector2.down, new RaycastHit2D[] { new RaycastHit2D() }, collider.bounds.extents.y + 0.125f) > 0 &&
            movementX != 0.0f && !audio.isPlaying)
        {
            audio.PlayOneShot(walkSound);
        }


        //if( inputDevice.GetControl(InControl.InputControlType))
        // Rotate target object with left stick.
        //transform.Rotate(Vector3.down, 500.0f * Time.deltaTime * inputDevice.LeftStickX, Space.World);
        //transform.Rotate(Vector3.right, 500.0f * Time.deltaTime * inputDevice.LeftStickY, Space.World);

        // Check direct inputs
        CheckButton(ActionEnum.Jump, jump);
        CheckButton(ActionEnum.Drill, drill);

        // Check for received transmissions
        if (null == transmissionManager.TransmissionControllers)
        {
            return;
        }
        foreach (var transmission in transmissionManager.TransmissionControllers)
        {
            if (transmission.TransmittedAction.SourcePlayer == gameObject || transmission.TransmittedAction.Seen)
            {
                continue;
            }
            float distanceToSource     = Vector3.Distance(transform.position, transmission.transform.position);
            float transmissionDistance = transmission.TransmissionDistance();
            if (transmissionDistance > distanceToSource)
            {
                //Debug.LogFormat ("See transmission: {0} > {1}", transmissionDistance, distanceToSource);
                audio.PlayOneShot(recvSound, .75f);
                ActivateButton(transmission.TransmittedAction.Button);
                transmission.TransmittedAction.Seen = true;
            }
        }
    }
 public float GetValue(InputDevice inputDevice)
 {
     return(GetState(inputDevice) ? 1.0f : 0.0f);
 }
 public override float GetValue(InputDevice inputDevice)
 {
     return(GetValue(Control));
 }
示例#56
0
    // Update is called once per frame
    void Update()
    {
        InControl.InputDevice input = InControl.InputManager.ActiveDevice;
        //Input
        //Works with both WASD and Left joystick
        Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * m_speed;

        if (move.sqrMagnitude >= m_speed * m_speed)
        {
            move = move.normalized * m_speed;
        }
        //No controller
        //if (input == InControl.InputDevice.Null) {
        transform.LookAt(GetMouseToPlayerPlanePoint());     //look at mouse
        //}
        //Joystick
        if (input.GetControl(InControl.InputControlType.RightStickX) != 0 || input.GetControl(InControl.InputControlType.RightStickY) != 0)
        {
            float heading = Mathf.Atan2(input.GetControl(InControl.InputControlType.RightStickX), input.GetControl(InControl.InputControlType.RightStickY)) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.Euler(0f, heading, 0f);
        }
        else
        {
        }


        //Moving back or forward for animation blending EXPAND to side ways as well
        if (Vector3.Dot(transform.forward, move) < 0)
        {
            m_animator.SetFloat("Speed", -move.magnitude / m_speed);//Backwards
        }
        else
        {
            m_animator.SetFloat("Speed", move.magnitude / m_speed);
        }
        //Keep grounded
        if (!m_controller.isGrounded)
        {
            //fall
            move.y += Physics.gravity.y * 10 * Time.deltaTime;
        }
        else
        {
            move.y = 0;
        }

        //Move using controller
        m_controller.Move(move * Time.deltaTime);

        //Range shoot input. only will do another action if in Movement (not doing other actions)
        if (m_animator.GetCurrentAnimatorStateInfo(1).IsName("UpperBody.Movement"))
        {
            if ((input.GetControl(InControl.InputControlType.LeftTrigger) > 0 || Input.GetMouseButtonDown(0)) && m_rangeTimer >= m_rangeCooldown && m_bulletPrefabs.Count > 0 && m_bulletExitPos != null)
            {
                m_animator.SetTrigger("Shoot");
                HideMelee();
                ShowRange();

                //CreateBullet();//Animator now calls it
                m_rangeTimer = 0;
            }//Melee
            else if ((input.GetControl(InControl.InputControlType.RightTrigger) > 0 || Input.GetMouseButtonDown(1)) && m_meleeTimer >= m_meleeCooldown)
            {
                m_animator.SetTrigger("Melee");


                //Hit check Animator calls the function now
                // MeleeSwing();
                //Set timer to 0
                m_meleeTimer = 0;
            }
            else if ((input.GetControl(InControl.InputControlType.LeftBumper).IsPressed || Input.GetKeyDown(KeyCode.Q)) && m_blockTimer >= m_blockCooldown)
            {
                //Blocking
                GameObject spawn = Instantiate <GameObject>(m_defEffPrefab, transform.position, transform.rotation);
                spawn.GetComponent <EffectDestroy>().m_duration = m_blockDuration;
                spawn.transform.parent = this.transform;
                m_animator.SetTrigger("Block");
                m_incomeDamMod -= m_blockChange; //drop the mod
                m_blockCounter  = 0.01f;         //Counts up to duration MATCH WITH ANIMATION?
                m_blockTimer    = 0;             //Cooldown
            }
            else if ((input.GetControl(InControl.InputControlType.RightBumper).IsPressed || Input.GetKeyDown(KeyCode.E)) && GameManager.Instance.MutaGenAmount() > m_healCost && m_healTimer > m_healCooldown)
            {
                //Heal
                GameObject spawn = Instantiate <GameObject>(m_healEffPrefab, transform.position, transform.rotation);
                spawn.GetComponent <EffectDestroy>().m_duration = 1.0f;
                spawn.transform.parent = this.transform;
                IncreaseCurrentHP(m_healAmount);
                GameManager.Instance.ChangeMutaGen(-m_healCost);
                m_healTimer = 0;
                //Create glow or something?
            }
            else if ((input.GetControl(InControl.InputControlType.Action4) || Input.GetAxis("Mouse ScrollWheel") != 0 || Input.GetKeyDown(KeyCode.R)))
            {
                //Cycle through weapons
                m_bulletIndex++;
                if (m_bulletIndex >= m_bulletPrefabs.Count)
                {
                    m_bulletIndex = 0;                                         //Cycle
                }
            }
        }
        Debug.Log(m_animator.GetCurrentAnimatorStateInfo(1).IsName("UpperBody.Movement"));
        //Timers
        if (m_rangeTimer < m_rangeCooldown)
        {
            m_rangeTimer += Time.deltaTime;
        }
        if (m_meleeTimer < m_meleeCooldown)
        {
            m_meleeTimer += Time.deltaTime;
        }
        if (m_blockTimer < m_blockCooldown)
        {
            m_blockTimer += Time.deltaTime;
        }
        //If not 0 increase until hits duration
        if (m_blockCounter > 0 && m_blockCounter < m_blockDuration)
        {
            m_blockCounter += Time.deltaTime;
        }
        //If its out of duration set block damage back to normal
        if (m_blockCounter >= m_blockDuration)
        {
            m_incomeDamMod += m_blockChange;//reset modifier
            m_blockCounter  = 0.0f;
        }
        if (m_healTimer < m_healCooldown)
        {
            m_healTimer += Time.deltaTime;
        }
    }
示例#57
0
        public static void DetachDevice( InputDevice inputDevice )
        {
            AssertIsSetup();

            Devices.Remove( inputDevice );
            SortDevices();

            if (ActiveDevice == inputDevice) {
            ActiveDevice = InputDevice.Null;
            }

            if (OnDeviceDetached != null) {
            OnDeviceDetached( inputDevice );
            }
        }
示例#58
0
 /// <summary>
 /// Read a float value from the binding source in the context of an optional InputDevice.
 /// </summary>
 /// <returns>The value, usually in the range -1..1, but not necessarily, for example,
 /// in the case of mouse movement.</returns>
 /// <param name="inputDevice">An input device which serves as the context for this source, if applicable. Pass in null when not applicable.</param>
 public abstract float GetValue(InputDevice inputDevice);
示例#59
0
 public override bool GetState(InputDevice inputDevice)
 {
     return(!Mathf.Approximately(GetValue(inputDevice), 0.0f));
 }
        public float GetValue(InputDevice inputDevice)
        {
            var unityDevice = inputDevice as UnityInputDevice;

            return(unityDevice.ReadRawAnalogValue(AnalogIndex));
        }