From cf58771365b5953c6eac548b172aae880d1f0acd Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 19 May 2024 17:03:57 +0800 Subject: * rename --- .../Rewired.Demos/TouchJoystickExample.cs | 110 --------------------- 1 file changed, 110 deletions(-) delete mode 100644 Thronefall_1_57/Decompile/Rewired.Demos/TouchJoystickExample.cs (limited to 'Thronefall_1_57/Decompile/Rewired.Demos/TouchJoystickExample.cs') diff --git a/Thronefall_1_57/Decompile/Rewired.Demos/TouchJoystickExample.cs b/Thronefall_1_57/Decompile/Rewired.Demos/TouchJoystickExample.cs deleted file mode 100644 index f05af89..0000000 --- a/Thronefall_1_57/Decompile/Rewired.Demos/TouchJoystickExample.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -[RequireComponent(typeof(Image))] -public class TouchJoystickExample : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IDragHandler -{ - public bool allowMouseControl = true; - - public int radius = 50; - - private Vector2 origAnchoredPosition; - - private Vector3 origWorldPosition; - - private Vector2 origScreenResolution; - - private ScreenOrientation origScreenOrientation; - - [NonSerialized] - private bool hasFinger; - - [NonSerialized] - private int lastFingerId; - - public Vector2 position { get; private set; } - - private void Start() - { - if (SystemInfo.deviceType == DeviceType.Handheld) - { - allowMouseControl = false; - } - StoreOrigValues(); - } - - private void Update() - { - if ((float)Screen.width != origScreenResolution.x || (float)Screen.height != origScreenResolution.y || Screen.orientation != origScreenOrientation) - { - Restart(); - StoreOrigValues(); - } - } - - private void Restart() - { - hasFinger = false; - (base.transform as RectTransform).anchoredPosition = origAnchoredPosition; - position = Vector2.zero; - } - - private void StoreOrigValues() - { - origAnchoredPosition = (base.transform as RectTransform).anchoredPosition; - origWorldPosition = base.transform.position; - origScreenResolution = new Vector2(Screen.width, Screen.height); - origScreenOrientation = Screen.orientation; - } - - private void UpdateValue(Vector3 value) - { - Vector3 vector = origWorldPosition - value; - vector.y = 0f - vector.y; - vector /= (float)radius; - position = new Vector2(0f - vector.x, vector.y); - } - - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) - { - if (!hasFinger && (allowMouseControl || !IsMousePointerId(eventData.pointerId))) - { - hasFinger = true; - lastFingerId = eventData.pointerId; - } - } - - void IPointerUpHandler.OnPointerUp(PointerEventData eventData) - { - if (eventData.pointerId == lastFingerId && (allowMouseControl || !IsMousePointerId(eventData.pointerId))) - { - Restart(); - } - } - - void IDragHandler.OnDrag(PointerEventData eventData) - { - if (hasFinger && eventData.pointerId == lastFingerId) - { - Vector3 vector = new Vector3(eventData.position.x - origWorldPosition.x, eventData.position.y - origWorldPosition.y); - vector = Vector3.ClampMagnitude(vector, radius); - Vector3 value = origWorldPosition + vector; - base.transform.position = value; - UpdateValue(value); - } - } - - private static bool IsMousePointerId(int id) - { - if (id != -1 && id != -2) - { - return id == -3; - } - return true; - } -} -- cgit v1.1-26-g67d0