summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.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/CustomControllerDemo.cs
parent4a4cc82d069b26bc4d4532e73860f86b211ca239 (diff)
*renameHEADmaster
Diffstat (limited to 'Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.cs')
-rw-r--r--Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.cs144
1 files changed, 0 insertions, 144 deletions
diff --git a/Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.cs b/Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.cs
deleted file mode 100644
index 2c67e86..0000000
--- a/Thronefall_1_0/Rewired/Rewired.Demos/CustomControllerDemo.cs
+++ /dev/null
@@ -1,144 +0,0 @@
-using System;
-using UnityEngine;
-
-namespace Rewired.Demos;
-
-[AddComponentMenu("")]
-public class CustomControllerDemo : MonoBehaviour
-{
- public int playerId;
-
- public string controllerTag;
-
- public bool useUpdateCallbacks;
-
- private int buttonCount;
-
- private int axisCount;
-
- private float[] axisValues;
-
- private bool[] buttonValues;
-
- private TouchJoystickExample[] joysticks;
-
- private TouchButtonExample[] buttons;
-
- private CustomController controller;
-
- [NonSerialized]
- private bool initialized;
-
- private void Awake()
- {
- ScreenOrientation screenOrientation = ScreenOrientation.LandscapeLeft;
- if (SystemInfo.deviceType == DeviceType.Handheld && Screen.orientation != screenOrientation)
- {
- Screen.orientation = screenOrientation;
- }
- Initialize();
- }
-
- private void Initialize()
- {
- ReInput.InputSourceUpdateEvent += OnInputSourceUpdate;
- joysticks = GetComponentsInChildren<TouchJoystickExample>();
- buttons = GetComponentsInChildren<TouchButtonExample>();
- axisCount = joysticks.Length * 2;
- buttonCount = buttons.Length;
- axisValues = new float[axisCount];
- buttonValues = new bool[buttonCount];
- Player player = ReInput.players.GetPlayer(playerId);
- controller = player.controllers.GetControllerWithTag<CustomController>(controllerTag);
- if (controller == null)
- {
- Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\"");
- }
- if (controller.buttonCount != buttonValues.Length || controller.axisCount != axisValues.Length)
- {
- Debug.LogError("Controller has wrong number of elements!");
- }
- if (useUpdateCallbacks && controller != null)
- {
- controller.SetAxisUpdateCallback(GetAxisValueCallback);
- controller.SetButtonUpdateCallback(GetButtonValueCallback);
- }
- initialized = true;
- }
-
- private void Update()
- {
- if (ReInput.isReady && !initialized)
- {
- Initialize();
- }
- }
-
- private void OnInputSourceUpdate()
- {
- GetSourceAxisValues();
- GetSourceButtonValues();
- if (!useUpdateCallbacks)
- {
- SetControllerAxisValues();
- SetControllerButtonValues();
- }
- }
-
- private void GetSourceAxisValues()
- {
- for (int i = 0; i < axisValues.Length; i++)
- {
- if (i % 2 != 0)
- {
- axisValues[i] = joysticks[i / 2].position.y;
- }
- else
- {
- axisValues[i] = joysticks[i / 2].position.x;
- }
- }
- }
-
- private void GetSourceButtonValues()
- {
- for (int i = 0; i < buttonValues.Length; i++)
- {
- buttonValues[i] = buttons[i].isPressed;
- }
- }
-
- private void SetControllerAxisValues()
- {
- for (int i = 0; i < axisValues.Length; i++)
- {
- controller.SetAxisValue(i, axisValues[i]);
- }
- }
-
- private void SetControllerButtonValues()
- {
- for (int i = 0; i < buttonValues.Length; i++)
- {
- controller.SetButtonValue(i, buttonValues[i]);
- }
- }
-
- private float GetAxisValueCallback(int index)
- {
- if (index >= axisValues.Length)
- {
- return 0f;
- }
- return axisValues[index];
- }
-
- private bool GetButtonValueCallback(int index)
- {
- if (index >= buttonValues.Length)
- {
- return false;
- }
- return buttonValues[index];
- }
-}