summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-20 22:36:58 +0800
committerchai <215380520@qq.com>2024-05-20 22:36:58 +0800
commita22c505984697881f5f911a165ee022087b69e09 (patch)
treed3c030aef1ae9b8a01c889dd2902bb1e3324e72b /Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs
parent4a4cc82d069b26bc4d4532e73860f86b211ca239 (diff)
*renameHEADmaster
Diffstat (limited to 'Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs')
-rw-r--r--Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs114
1 files changed, 0 insertions, 114 deletions
diff --git a/Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs b/Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs
deleted file mode 100644
index 3213b71..0000000
--- a/Thronefall_1_0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-using System.Collections.Generic;
-using UnityEngine;
-
-namespace Rewired.Demos;
-
-[AddComponentMenu("")]
-public class FallbackJoystickIdentificationDemo : MonoBehaviour
-{
- private const float windowWidth = 250f;
-
- private const float windowHeight = 250f;
-
- private const float inputDelay = 1f;
-
- private bool identifyRequired;
-
- private Queue<Joystick> joysticksToIdentify;
-
- private float nextInputAllowedTime;
-
- private GUIStyle style;
-
- private void Awake()
- {
- if (ReInput.unityJoystickIdentificationRequired)
- {
- ReInput.ControllerConnectedEvent += JoystickConnected;
- ReInput.ControllerDisconnectedEvent += JoystickDisconnected;
- IdentifyAllJoysticks();
- }
- }
-
- private void JoystickConnected(ControllerStatusChangedEventArgs args)
- {
- IdentifyAllJoysticks();
- }
-
- private void JoystickDisconnected(ControllerStatusChangedEventArgs args)
- {
- IdentifyAllJoysticks();
- }
-
- public void IdentifyAllJoysticks()
- {
- Reset();
- if (ReInput.controllers.joystickCount != 0)
- {
- Joystick[] joysticks = ReInput.controllers.GetJoysticks();
- if (joysticks != null)
- {
- identifyRequired = true;
- joysticksToIdentify = new Queue<Joystick>(joysticks);
- SetInputDelay();
- }
- }
- }
-
- private void SetInputDelay()
- {
- nextInputAllowedTime = Time.time + 1f;
- }
-
- private void OnGUI()
- {
- if (!identifyRequired)
- {
- return;
- }
- if (joysticksToIdentify == null || joysticksToIdentify.Count == 0)
- {
- Reset();
- return;
- }
- Rect screenRect = new Rect((float)Screen.width * 0.5f - 125f, (float)Screen.height * 0.5f - 125f, 250f, 250f);
- GUILayout.Window(0, screenRect, DrawDialogWindow, "Joystick Identification Required");
- GUI.FocusWindow(0);
- if (!(Time.time < nextInputAllowedTime) && ReInput.controllers.SetUnityJoystickIdFromAnyButtonOrAxisPress(joysticksToIdentify.Peek().id, 0.8f, positiveAxesOnly: false))
- {
- joysticksToIdentify.Dequeue();
- SetInputDelay();
- if (joysticksToIdentify.Count == 0)
- {
- Reset();
- }
- }
- }
-
- private void DrawDialogWindow(int windowId)
- {
- if (identifyRequired)
- {
- if (style == null)
- {
- style = new GUIStyle(GUI.skin.label);
- style.wordWrap = true;
- }
- GUILayout.Space(15f);
- GUILayout.Label("A joystick has been attached or removed. You will need to identify each joystick by pressing a button on the controller listed below:", style);
- Joystick joystick = joysticksToIdentify.Peek();
- GUILayout.Label("Press any button on \"" + joystick.name + "\" now.", style);
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("Skip"))
- {
- joysticksToIdentify.Dequeue();
- }
- }
- }
-
- private void Reset()
- {
- joysticksToIdentify = null;
- identifyRequired = false;
- }
-}