当前位置: 首页>>代码示例>>C#>>正文


C# XInputDotNetPure.GamePadState类代码示例

本文整理汇总了C#中XInputDotNetPure.GamePadState的典型用法代码示例。如果您正苦于以下问题:C# GamePadState类的具体用法?C# GamePadState怎么用?C# GamePadState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GamePadState类属于XInputDotNetPure命名空间,在下文中一共展示了GamePadState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

	// Update is called once per frame
	void Update () {

        #region Update Controller State
        // update controller state
        prevState = state;
        state = GamePad.GetState(playerIndex);

        // Find a PlayerIndex, for a single player game
        // Will find the first controller that is connected ans use it
        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex testPlayerIndex = (PlayerIndex)i;
                GamePadState testState = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    //Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex = testPlayerIndex;
                    playerIndexSet = true;
                }
            }
        }
        #endregion

        // OVR RESET
        if (state.Buttons.Back == ButtonState.Pressed)
        {
            OVRManager.display.RecenterPose();  // OVR Reset function for 0.4.3
        }
	
	}
开发者ID:Soverance,项目名称:EndlessReach,代码行数:33,代码来源:XInputState.cs

示例2: GetDirection

    public static InputDirection.Direction GetDirection(XBOX_DIRECTION direction, GamePadState pad)
    {
        InputDirection.Direction d = new InputDirection.Direction(0, 0);

        if (!pad.IsConnected)
        {
            return d;
        }

        switch (direction)
        {
            case XBOX_DIRECTION.Pad:
                if (pad.DPad.Down == ButtonState.Pressed)
                    d.y--;
                if (pad.DPad.Up == ButtonState.Pressed)
                    d.y++;
                if (pad.DPad.Right == ButtonState.Pressed)
                    d.x++;
                if (pad.DPad.Left == ButtonState.Pressed)
                    d.x--;
                break;
            case XBOX_DIRECTION.StickLeft:
                d.x = pad.ThumbSticks.Left.X;
                d.y = pad.ThumbSticks.Left.Y;
                break;
            case XBOX_DIRECTION.StickRight:
                d.x = pad.ThumbSticks.Right.X;
                d.y = pad.ThumbSticks.Right.Y;
                break;
        }

        return d;
    }
开发者ID:sylafrs,项目名称:rugby,代码行数:33,代码来源:XboxInputs.cs

示例3: MapPlayerInput

        // TODO: Maybe reduce it to only the inputs actually used in the game?
        private void MapPlayerInput(InputMapper inputMapper, GamePadState state, GamePadState previousState)
        {
            foreach (int axisInt in InputMapperAsset.GetMappedXboxAxis())
            {
                MapXboxAxis(axisInt, inputMapper, state);
            }

            foreach (int buttonInt in InputMapperAsset.GetMappedXboxButtons())
            {
                MapXboxButton(buttonInt, inputMapper, state, previousState);
            }

            // TODO: Put the following code into another class, so we can have 2 distinct XboxManager and KeyboardManager classes

            // We map only the keyboard keys that are going to be used in the game

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeys())
            {
                inputMapper.SetRawButtonState(100 + key, Input.GetKey((KeyCode)key), Input.GetKey((KeyCode)key) && !Input.GetKeyDown((KeyCode)key));
            }

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeysAxis())
            {
                float value = Input.GetKey((KeyCode)key) ? 1f : 0f;

                inputMapper.SetRawAxisValue(100 + key, value);
            }
        }
开发者ID:ConjureETS,项目名称:OuijaMTLGJ2016,代码行数:29,代码来源:ControllerManager.cs

示例4: StateChanged

	bool StateChanged (GamePadState s1, GamePadState s2)
	{
		bool changed = false;
		changed |= s1.Buttons.A != s2.Buttons.A;
		changed |= s1.Buttons.B != s2.Buttons.B;
		changed |= s1.Buttons.X != s2.Buttons.X;
		changed |= s1.Buttons.Y != s2.Buttons.Y;
		changed |= s1.Buttons.Start != s2.Buttons.Start;
		changed |= s1.Buttons.Back != s2.Buttons.Back;
		changed |= s1.Buttons.LeftShoulder != s2.Buttons.LeftShoulder;
		changed |= s1.Buttons.RightShoulder != s2.Buttons.RightShoulder;
		changed |= s1.Buttons.LeftStick != s2.Buttons.LeftStick;
		changed |= s1.Buttons.RightStick != s2.Buttons.RightStick;
		changed |= s1.DPad.Up != s2.DPad.Up;
		changed |= s1.DPad.Down != s2.DPad.Down;
		changed |= s1.DPad.Left != s2.DPad.Left;
		changed |= s1.DPad.Right != s2.DPad.Right;
		changed |= Mathf.Abs (s1.Triggers.Left - s2.Triggers.Left) / Time.deltaTime > thresholdVelocity;
		changed |= Mathf.Abs (s1.Triggers.Right - s2.Triggers.Right) / Time.deltaTime > thresholdVelocity;
		changed |= Mathf.Abs (s1.ThumbSticks.Left.X - s2.ThumbSticks.Left.X) / Time.deltaTime > thresholdVelocity;
		changed |= Mathf.Abs (s1.ThumbSticks.Left.Y - s2.ThumbSticks.Left.Y) / Time.deltaTime > thresholdVelocity;
		changed |= Mathf.Abs (s1.ThumbSticks.Right.X - s2.ThumbSticks.Right.X) / Time.deltaTime > thresholdVelocity;
		changed |= Mathf.Abs (s1.ThumbSticks.Right.Y - s2.ThumbSticks.Right.Y) / Time.deltaTime > thresholdVelocity;
		
		return changed;
	}
开发者ID:fatsopanda,项目名称:morning_coffee_ggj,代码行数:26,代码来源:XGamepadDevice.cs

示例5: CheckGamePad

    private void CheckGamePad()
    {
        if (!playerIndexSet && !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex testPlayerIndex = (PlayerIndex)i;
                GamePadState testState = GamePad.GetState(testPlayerIndex, GamePadDeadZone.None);
                if (testState.IsConnected)
                {
                    Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex = testPlayerIndex;
                    playerIndexSet = true;

                    // Set vibration according to triggers
                    GamePad.SetVibration(playerIndex, state.Triggers.Left, state.Triggers.Right);
                }
            }
        }

        prevState = state;
        state = GamePad.GetState(playerIndex);

        
    }
开发者ID:SaverioDiLazzaro,项目名称:TheGGJGame,代码行数:25,代码来源:InputManager.cs

示例6: FixedUpdate

	void FixedUpdate()
	{

        state = GamePad.GetState(playerIndexNum);

        Vector3 pos = poi.position;
        if(state.Buttons.Y == ButtonState.Pressed)
		    pos -= poi.forward * -distance;
        else
            pos -= poi.forward * distance;
        pos += poi.up * height;
		Vector3 rot = poi.localEulerAngles;

		Vector3 pos2 = (1 - u) * transform.position + u * pos;
		//Vector3 rot2 = (1 - v) * transform.localEulerAngles + v * rot;
        //rot2.y = poi.transform.localEulerAngles.y;



        if (shake) {
			pos2.x += Random.value * shakeIntensity * Random .Range(-1, 1);
			pos2.y += Random.value * shakeIntensity * Random .Range(-1, 1);
			pos2.z += Random.value * shakeIntensity * Random .Range(-1, 1);
		}

        
		transform.position = pos2;

        transform.rotation = Quaternion.Slerp(camTarget.rotation, transform.rotation, 2f * Time.fixedDeltaTime);
        //transform.localEulerAngles = rot2;

    }
开发者ID:kkalina,项目名称:CyborgKatz,代码行数:32,代码来源:ThirdPersonCamera.cs

示例7: Update

    // Update is called once per frame
    void Update()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;

        #region Update Controller State
        prevState_p1 = state_p1;
        state_p1 = GamePad.GetState(pad_PlayerOne);
        #endregion

        if( Input.GetKeyDown(KeyCode.Space) ||
            Input.GetKeyDown(KeyCode.Escape) ||
            state_p1.Buttons.A == ButtonState.Pressed ||
            state_p1.Buttons.Start == ButtonState.Pressed ||
            state_p1.Buttons.Back == ButtonState.Pressed)
        {
            f_LevelTimer = f_LevelTimer_Max + 1f;
        }

        UpdateLerpTimer();

        // Lerp from the previous graphic's alpha value to its new alpha
        if(go_Graphic != null)
        {
            Color clr_Curr = go_Graphic.GetComponent<Image>().color;
            clr_Curr.a = f_LerpPerc;
            go_Graphic.GetComponent<Image>().color = clr_Curr;
        }
    }
开发者ID:ChrisCrossed,项目名称:CodeExamples,代码行数:30,代码来源:Cs_IntroScreenLogic.cs

示例8: Update

    override protected void Update()
    {
        GPState = GamePad.GetState(PlayerIndex.One);

        m_TargetVelocity = (Vector3.forward * GPState.ThumbSticks.Left.Y +
                           Vector3.right * GPState.ThumbSticks.Left.X).normalized * Time.deltaTime;
        m_TargetVelocity = m_SpeedIsCapped ? m_TargetVelocity * m_ReducedSpeed : m_TargetVelocity * m_Speed;

        m_Velocity = Vector3.Lerp(m_Velocity, m_TargetVelocity, m_DampingFactor);
        BoundZVelocity();
        if (m_Velocity != Vector3.zero)
        {
            m_Animator.SetBool("Walking", true);
            m_Animator.SetFloat("WalkingMultiplier", m_SpeedIsCapped ? m_ReducedSpeed / m_Speed : 1f);
        }
        else
        {
            m_Animator.SetBool("Walking", false);
        }
        UpdatePose();

        float X = m_Velocity.x;
        float Y = m_Velocity.z;

        float deltaAngle = (X / m_DistanceToCenter) * Mathf.Rad2Deg;
        m_Angle += deltaAngle;

        m_DistanceToCenter -= Y;
        BoundDistanceToCenter();

        base.Update();
    }
开发者ID:JabberSnatch,项目名称:GGJ2016,代码行数:32,代码来源:RotatingPlayerController.cs

示例9: Update

    // Update is called once per frame
    void Update()
    {
        prevState = state;
        state = GamePad.GetState(playerIndex);

        if (InputEnabled) {
            // axis crontrols for horizontal movement
            if (Mathf.Abs(state.ThumbSticks.Left.X) > .5f || Mathf.Abs(state.ThumbSticks.Left.Y) > .5f){
                CurrentRot = Quaternion.Euler(new Vector3(0 ,0 ,Mathf.Atan2(-state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y)* Mathf.Rad2Deg));
                StickPosSnap.x = state.ThumbSticks.Left.X;
                StickPosSnap.y = state.ThumbSticks.Left.Y;
         			}
            transform.rotation = CurrentRot;
            // player thrust control
            if (state.Triggers.Right > .05f){
                RB.AddForce(new Vector2(StickPosSnap.x * Speed * state.Triggers.Right, StickPosSnap.y * Speed * state.Triggers.Right));
                if (ThrusterSprite.activeSelf == false){
                    ThrusterSprite.SetActive(true);
                }
            }else {
                if (ThrusterSprite.activeSelf == true){
                    ThrusterSprite.SetActive(false);
                }
            }
            // menu control
            if (state.Buttons.Start == ButtonState.Pressed && prevState.Buttons.Start == ButtonState.Released && Time.timeScale == 1) {

                //InputEnabled = false;
                //Time.timeScale = 0;

            }

        }
    }
开发者ID:NIUGameDesignClub,项目名称:Arc-Lightning-Game,代码行数:35,代码来源:PlayerControlScript.cs

示例10: Update

    // Update is called once per frame
    protected virtual void Update()
    {
        // if we haven't gotten the correct player number yet
        if (!gotNumber)
        {
          playerIndex = (PlayerIndex)GetComponentInParent<PlayerController>().playerNumber;
          gotNumber = true;
        }

        prevState = state;
        state = GamePad.GetState(playerIndex);

        // short out if input's disabled
        if (!inputEnabled)
          return;

        // if the right bumper is being pressed
        if (prevState.Buttons.RightShoulder == ButtonState.Released && state.Buttons.RightShoulder == ButtonState.Pressed)
        {
          // and we have enough resources
          if (plCont.currCharge >= reqCharge)
          {
        // do whatever our special is
        Fire();
          }
        }
    }
开发者ID:izzy-sabur,项目名称:polish_proj,代码行数:28,代码来源:BaseSpecial.cs

示例11: Convert

        public override SF4InputState Convert()
        {
            SF4InputState outputState = new SF4InputState();

            gamePadState = GamePad.GetState(playerIndex);

            //Options
            outputState.Options.Back = gamePadState.Buttons.Back == ButtonState.Pressed;
            outputState.Options.Start = gamePadState.Buttons.Start == ButtonState.Pressed;

            //Punches
            outputState.Punches.Light = gamePadState.Buttons.X == ButtonState.Pressed;
            outputState.Punches.Medium = gamePadState.Buttons.Y == ButtonState.Pressed;
            outputState.Punches.Hard = gamePadState.Buttons.RightShoulder == ButtonState.Pressed;

            //Kicks
            outputState.Kicks.Light = gamePadState.Buttons.A == ButtonState.Pressed;
            outputState.Kicks.Medium = gamePadState.Buttons.B == ButtonState.Pressed;
            outputState.Kicks.Hard = gamePadState.Triggers.Right > 0.25f;

            //Determine if Dpad has any input
            outputState.Directions.Right = (gamePadState.DPad.Right == ButtonState.Pressed || gamePadState.ThumbSticks.Left.X > 0.25f);

            outputState.Directions.Left = (gamePadState.DPad.Left == ButtonState.Pressed || -gamePadState.ThumbSticks.Left.X > 0.25f);

            outputState.Directions.Up = (gamePadState.DPad.Up == ButtonState.Pressed || gamePadState.ThumbSticks.Left.Y > 0.25f);

            outputState.Directions.Down = (gamePadState.DPad.Down == ButtonState.Pressed || -gamePadState.ThumbSticks.Left.Y > 0.25f);

            return outputState;
        }
开发者ID:jeremyschultz,项目名称:SF4ComboTrainer,代码行数:31,代码来源:XInputConverter.cs

示例12: Update

    // Update is called once per frame
    void Update()
    {
        currentState = GamePad.GetState(pIndex);

        if(currentState.ThumbSticks.Right.X < 0)
        {
            pTran.Translate(Vector3.left*Time.deltaTime*9, Space.World);
            //pTran.rotation = Quaternion.Lerp(pTran.rotation, rotLeft, Time.deltaTime*50);
        }
        else if(currentState.ThumbSticks.Right.X > 0)
        {
            pTran.Translate(Vector3.right*Time.deltaTime*9, Space.World);
            //pTran.rotation = Quaternion.Lerp(pTran.rotation, rotRight, Time.deltaTime*50);
        }

        if(currentState.ThumbSticks.Right.Y < 0)
        {
            pTran.Translate(Vector3.down*Time.deltaTime*9, Space.World);
            //pTran.rotation = Quaternion.Lerp(pTran.rotation, rotLeft, Time.deltaTime*50);
        }
        else if(currentState.ThumbSticks.Right.Y > 0)
        {
            pTran.Translate(Vector3.up*Time.deltaTime*9, Space.World);
            //pTran.rotation = Quaternion.Lerp(pTran.rotation, rotRight, Time.deltaTime*50);
        }
    }
开发者ID:Wikzo,项目名称:P6_CouchGaming,代码行数:27,代码来源:EyeMove.cs

示例13: Update

	// Update is called once per frame
	void Update ()
    {
        Timer += Time.deltaTime;

        if (Timer >= SwapTime && CanTimer)
        {
            Timer = 0;
            NextCanvas += 1;
            ChangeSlide(NextCanvas);
        }

        prevState = state;
        state = GamePad.GetState(playerIndex);

        if (Cooldown <= 0 && prevState.IsConnected)
        {
            state = GamePad.GetState(playerIndex);
            CheckControllers();
        }

        else
        {
            Cooldown -= Time.deltaTime;
        }

    }
开发者ID:ChrisCrossed,项目名称:SpaceTube,代码行数:27,代码来源:CreditsHandler.cs

示例14: Update

    // Update is called once per frame
    void Update()
    {
        prevState = state;
        state = GamePad.GetState(playerIndex);
        if (bEnabled)
        {
            if (Cooldown <= 0)
            {
                if (state.IsConnected)
                {
                    //print(state.IsConnected);
                    // Get the state //
                    state = GamePad.GetState(playerIndex);

                    // Check Player 1's controller for input //
                    CheckControllers();
                }
            }

            else
            {
                Cooldown -= 0.1f;
            }
            CheckControllers();

        }
    }
开发者ID:ChrisCrossed,项目名称:SpaceTube,代码行数:28,代码来源:ControllerMenu.cs

示例15: PlayerRumble

    // constructor
    public PlayerRumble(int index)
    {
        switch (index)
        {
            case 1:
                this.index = PlayerIndex.One;
                break;
            case 2:
                this.index = PlayerIndex.Two;
                break;
            case 3:
                this.index = PlayerIndex.Three;
                break;
            case 4:
                this.index = PlayerIndex.Four;
                break;
            default:
                Debug.Log(string.Format("ERROR! {0}'s gamepad index has not been assigned!", index));
                this.index = PlayerIndex.One;
                break;
        }

        this.state = GamePad.GetState(this.index);
        this.prevState = GamePad.GetState(this.index);

        if (this.state.IsConnected)
        {
            Debug.Log(string.Format("GamePad found P{0}", (int)this.index));
            LoggingManager.AddText(this + " was added.");
            this.StartRumbleCountdown();
        }
    }
开发者ID:Wikzo,项目名称:P6_CouchGaming,代码行数:33,代码来源:RandomRumble.cs


注:本文中的XInputDotNetPure.GamePadState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。