Exemplo n.º 1
0
    // Update is called once per frame
    private void Update()
    {
        // just to test if controllers work

        /*
         * for (int i = 0; i < 4; i++)
         * {
         *  print(i + " is connected: " + GamePad.GetState((PlayerIndex)i).IsConnected);
         *  if (GamePad.GetState((PlayerIndex)i).IsConnected)
         *  {
         *      GamePad.SetVibration((PlayerIndex)i, 1, 1);
         *      Debug.Log(i + " is vibrating");
         *  }
         * }*/
        // check for new controllers OLD

        /*for (int i = 0; i < 4; i++)
         * {
         *  if (!Players[i].ControllerIsConnected() && GamePad.GetState((PlayerIndex)i).IsConnected)
         *  {
         *      Player p = new Player(i);
         *      p.state = GamePad.GetState(p.index);
         *
         *      Players[i] = p;
         *
         *  }
         * }*/

        // check current ontrollers
        controllers = "";
        foreach (PlayerRumble p in Players)
        {
            p.UpdatePlayer();

            if (p.state.IsConnected)
            {
                p.Rumble();

                if (p.ButtonDown)
                {
                    LoggingManager.AddText(string.Format("***{0} pressed***", p));
                }

                controllers += p + " ";
            }
        }

        textObject.guiText.text = controllers;

        foreach (PlayerRumble p in Players)
        {
            if (p.state.IsConnected)
            {
                p.prevState = p.state;
            }
        }
    }
Exemplo n.º 2
0
    public void UpdatePlayer()
    {
        this.state = GamePad.GetState(this.index);

        // does not work??
        if (this.state.IsConnected && !this.prevState.IsConnected)
        {
            LoggingManager.AddText(this + " was added.");
        }

        // button to use
        ButtonDown = (state.Buttons.B == ButtonState.Pressed && prevState.Buttons.B != ButtonState.Pressed);
        ButtonUp   = (state.Buttons.B != ButtonState.Pressed && prevState.Buttons.B == ButtonState.Pressed);
    }
Exemplo n.º 3
0
    // 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();
        }
    }
Exemplo n.º 4
0
    public void Rumble()
    {
        timer += Time.deltaTime;

        if (timer >= whenToRumbleNext)               // get ready to rumble!
        {
            if (currentRumbleTimer < rumbleDuration) // rumble duration
            {
                if (!hasWrittenRumbleLog)
                {
                    hasWrittenRumbleLog = true;
                    LoggingManager.AddText(string.Format("{0} rumbles for {1} s with Power = ({2}; {3})", this, rumbleDuration, rumblePowerL, rumblePowerR));
                }
                currentRumbleTimer += Time.deltaTime;
                GamePad.SetVibration(this.index, rumblePowerL, rumblePowerR); // start rumbling
                //Debug.Log("Rumbling for " + (rumbleDuration-currentRumbleTimer) + " seconds");
            }
            else
            {
                GamePad.SetVibration(this.index, 0, 0); // stop rumbling
                StartRumbleCountdown();                 // get ready for next random rumble
            }
        }
    }