コード例 #1
0
ファイル: SInput.cs プロジェクト: SophieH/Sinput
    static string[] tempInputGamepads;    //more optimal to have it defined here than inside the CheckGamepads function
    /// <summary>
    /// Checks whether connected gamepads have changed.
    /// <para>This is called before every input check so it is uneccesary for you to use it.</para>
    /// </summary>
    /// <param name="refreshGamepadsNow"></param>
    public static void CheckGamepads(bool refreshGamepadsNow = false)
    {
        if (Time.frameCount == lastCheckedGamepadRefreshFrame && !refreshGamepadsNow)
        {
            return;
        }
        lastCheckedGamepadRefreshFrame = Time.frameCount;

        //Debug.Log("checking gamepads");

        Init();

        tempInputGamepads = Input.GetJoystickNames();
        if (connectedGamepads != tempInputGamepads.Length)
        {
            refreshGamepadsNow = true;                                                        //number of connected gamepads has changed
        }
        if (!refreshGamepadsNow && nextGamepadCheck < Time.frameCount)
        {
            //this check is for the rare case gamepads get re-ordered in a single frame & the length of GetJoystickNames() stays the same
            nextGamepadCheck = Time.frameCount + 500;
            for (int i = 0; i < connectedGamepads; i++)
            {
                if (_gamepads[i] != tempInputGamepads[i].ToUpper())
                {
                    refreshGamepadsNow = true;
                }
            }
        }
        if (refreshGamepadsNow)
        {
            //Debug.Log("Refreshing gamepads");

            //connected gamepads have changed, lets update them
            _gamepads = new string[tempInputGamepads.Length];
            for (int i = 0; i < _gamepads.Length; i++)
            {
                _gamepads[i] = tempInputGamepads[i].ToUpper();
            }
            connectedGamepads = _gamepads.Length;

            //reload common mapping information for any new gamepads
            CommonGamepadMappings.ReloadCommonMaps();

            //refresh control information relating to gamepads
            if (schemeLoaded)
            {
                RefreshGamepadControls();
            }

            //xr stuff too
            _xr.UpdateJoystickIndeces();

            refreshGamepadsNow = false;
        }
    }
コード例 #2
0
ファイル: SInput.cs プロジェクト: forestrf/Sinput
    /// <summary>
    /// Checks whether connected gamepads have changed.
    /// <para>This is called before every input check so it is uneccesary for you to use it.</para>
    /// </summary>
    public static void CheckGamepads(bool refreshGamepadsNow = false)
    {
        if (Time.frameCount == lastCheckedGamepadRefreshFrame && !refreshGamepadsNow)
        {
            return;
        }
        lastCheckedGamepadRefreshFrame = Time.frameCount;

        //Debug.Log("checking gamepads");

        var tempInputGamepads = Input.GetJoystickNames();

        if (connectedGamepads != tempInputGamepads.Length)
        {
            refreshGamepadsNow = true;                                                        //number of connected gamepads has changed
        }
        if (!refreshGamepadsNow && nextGamepadCheck < Time.frameCount)
        {
            //this check is for the rare case gamepads get re-ordered in a single frame & the length of GetJoystickNames() stays the same
            nextGamepadCheck = Time.frameCount + 500;
            for (int i = 0; i < connectedGamepads; i++)
            {
                if (!_gamepads[i].Equals(tempInputGamepads[i], StringComparison.InvariantCultureIgnoreCase))
                {
                    refreshGamepadsNow = true;
                }
            }
        }
        if (refreshGamepadsNow)
        {
            //Debug.Log("Refreshing gamepads");

            //connected gamepads have changed, lets update them
            _gamepads = tempInputGamepads;             // reuse array given that we already have generated it using Input.GetJoystickNames()
            for (int i = 0; i < _gamepads.Length; i++)
            {
                _gamepads[i] = tempInputGamepads[i].ToUpper();
            }

            //reload common mapping information for any new gamepads
            SinputSystems.CommonGamepadMappings.ReloadCommonMaps();

            //refresh control information relating to gamepads
            if (schemeLoaded)
            {
                RefreshGamepadControls();
            }

            //xr stuff too
            _xr.UpdateJoystickIndeces();

            refreshGamepadsNow = false;
        }
    }