コード例 #1
0
    public void Rumble(int player = 0, float duration = 0.5f, float weakMotor = 1f, float strongMotor = 1f, float startFading = -1f)
    {
        if (!active)
        {
            return;
        }

        //Player 0 means both players
        TemporalRumbleInfo rumble = new TemporalRumbleInfo(player, weakMotor, strongMotor, duration, (startFading == -1f ? duration * 0.75f : startFading));

        temporalRumbleList.Add(rumble);
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (temporalRumbleList.Count > 0 || continousRumbleList.Count > 0)
        {
            float p1Weak   = 0f;
            float p1Strong = 0f;
            float p2Weak   = 0f;
            float p2Strong = 0f;

            if (!pauseRumble)
            {
                for (int i = temporalRumbleList.Count - 1; i >= 0; --i)
                {
                    TemporalRumbleInfo rumble = temporalRumbleList[i];
                    rumble.Update();

                    if (rumble.duration > 0)
                    {
                        switch (rumble.player)
                        {
                        case 0:
                            p1Weak   = rumble.GetMaxWeakValue(p1Weak);
                            p1Strong = rumble.GetMaxStrongValue(p1Strong);

                            p2Weak   = rumble.GetMaxWeakValue(p2Weak);
                            p2Strong = rumble.GetMaxStrongValue(p2Strong);
                            break;

                        case 1:
                            p1Weak   = rumble.GetMaxWeakValue(p1Weak);
                            p1Strong = rumble.GetMaxStrongValue(p1Strong);
                            break;

                        case 2:
                            p2Weak   = rumble.GetMaxWeakValue(p2Weak);
                            p2Strong = rumble.GetMaxStrongValue(p2Strong);
                            break;
                        }
                    }
                    else
                    {
                        temporalRumbleList.RemoveAt(i);
                    }
                }


                foreach (ContinousRumbleInfo rumble in continousRumbleList.Values)
                {
                    switch (rumble.player)
                    {
                    case 0:
                        p1Weak   = rumble.GetMaxWeakValue(p1Weak);
                        p1Strong = rumble.GetMaxStrongValue(p1Strong);

                        p2Weak   = rumble.GetMaxWeakValue(p2Weak);
                        p2Strong = rumble.GetMaxStrongValue(p2Strong);
                        break;

                    case 1:
                        p1Weak   = rumble.GetMaxWeakValue(p1Weak);
                        p1Strong = rumble.GetMaxStrongValue(p1Strong);
                        break;

                    case 2:
                        p2Weak   = rumble.GetMaxWeakValue(p2Weak);
                        p2Strong = rumble.GetMaxStrongValue(p2Strong);
                        break;
                    }
                }
            }

            //GamePad.SetVibration(PlayerIndex.One, p1Strong, p1Weak);
            //GamePad.SetVibration(PlayerIndex.Two, p2Strong, p2Weak);

            if (ShouldVibratePlayer(1))
            {
                InputManager.Devices[0].Vibrate(p1Strong, p1Weak);
            }
            if (ShouldVibratePlayer(2))
            {
                InputManager.Devices[1].Vibrate(p2Strong, p2Weak);
            }
        }
    }