diff options
Diffstat (limited to 'Assets/Thirdparty/Joystick Pack/Scripts')
21 files changed, 570 insertions, 0 deletions
diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Base.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Base.meta new file mode 100644 index 0000000..48ea68a --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Base.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 04bf1fec540b6ee4987dc6524756477c +folderAsset: yes +timeCreated: 1513537865 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs new file mode 100644 index 0000000..656d714 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs @@ -0,0 +1,150 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+
+public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
+{
+ public float Horizontal { get { return (snapX) ? SnapFloat(input.x, AxisOptions.Horizontal) : input.x; } }
+ public float Vertical { get { return (snapY) ? SnapFloat(input.y, AxisOptions.Vertical) : input.y; } }
+ public Vector2 Direction { get { return new Vector2(Horizontal, Vertical); } }
+
+ public float HandleRange
+ {
+ get { return handleRange; }
+ set { handleRange = Mathf.Abs(value); }
+ }
+
+ public float DeadZone
+ {
+ get { return deadZone; }
+ set { deadZone = Mathf.Abs(value); }
+ }
+
+ public AxisOptions AxisOptions { get { return AxisOptions; } set { axisOptions = value; } }
+ public bool SnapX { get { return snapX; } set { snapX = value; } }
+ public bool SnapY { get { return snapY; } set { snapY = value; } }
+
+ [SerializeField] private float handleRange = 1;
+ [SerializeField] private float deadZone = 0;
+ [SerializeField] private AxisOptions axisOptions = AxisOptions.Both;
+ [SerializeField] private bool snapX = false;
+ [SerializeField] private bool snapY = false;
+
+ [SerializeField] protected RectTransform background = null;
+ [SerializeField] private RectTransform handle = null;
+ private RectTransform baseRect = null;
+
+ private Canvas canvas;
+ private Camera cam;
+
+ private Vector2 input = Vector2.zero;
+
+ protected virtual void Start()
+ {
+ HandleRange = handleRange;
+ DeadZone = deadZone;
+ baseRect = GetComponent<RectTransform>();
+ canvas = GetComponentInParent<Canvas>();
+ if (canvas == null)
+ Debug.LogError("The Joystick is not placed inside a canvas");
+
+ Vector2 center = new Vector2(0.5f, 0.5f);
+ background.pivot = center;
+ handle.anchorMin = center;
+ handle.anchorMax = center;
+ handle.pivot = center;
+ handle.anchoredPosition = Vector2.zero;
+ }
+
+ public virtual void OnPointerDown(PointerEventData eventData)
+ {
+ OnDrag(eventData);
+ }
+
+ public void OnDrag(PointerEventData eventData)
+ {
+ cam = null;
+ if (canvas.renderMode == RenderMode.ScreenSpaceCamera)
+ cam = canvas.worldCamera;
+
+ Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position);
+ Vector2 radius = background.sizeDelta / 2;
+ input = (eventData.position - position) / (radius * canvas.scaleFactor);
+ FormatInput();
+ HandleInput(input.magnitude, input.normalized, radius, cam);
+ handle.anchoredPosition = input * radius * handleRange;
+ }
+
+ protected virtual void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
+ {
+ if (magnitude > deadZone)
+ {
+ if (magnitude > 1)
+ input = normalised;
+ }
+ else
+ input = Vector2.zero;
+ }
+
+ private void FormatInput()
+ {
+ if (axisOptions == AxisOptions.Horizontal)
+ input = new Vector2(input.x, 0f);
+ else if (axisOptions == AxisOptions.Vertical)
+ input = new Vector2(0f, input.y);
+ }
+
+ private float SnapFloat(float value, AxisOptions snapAxis)
+ {
+ if (value == 0)
+ return value;
+
+ if (axisOptions == AxisOptions.Both)
+ {
+ float angle = Vector2.Angle(input, Vector2.up);
+ if (snapAxis == AxisOptions.Horizontal)
+ {
+ if (angle < 22.5f || angle > 157.5f)
+ return 0;
+ else
+ return (value > 0) ? 1 : -1;
+ }
+ else if (snapAxis == AxisOptions.Vertical)
+ {
+ if (angle > 67.5f && angle < 112.5f)
+ return 0;
+ else
+ return (value > 0) ? 1 : -1;
+ }
+ return value;
+ }
+ else
+ {
+ if (value > 0)
+ return 1;
+ if (value < 0)
+ return -1;
+ }
+ return 0;
+ }
+
+ public virtual void OnPointerUp(PointerEventData eventData)
+ {
+ input = Vector2.zero;
+ handle.anchoredPosition = Vector2.zero;
+ }
+
+ protected Vector2 ScreenPointToAnchoredPosition(Vector2 screenPosition)
+ {
+ Vector2 localPoint = Vector2.zero;
+ if (RectTransformUtility.ScreenPointToLocalPointInRectangle(baseRect, screenPosition, cam, out localPoint))
+ {
+ Vector2 pivotOffset = baseRect.pivot * baseRect.sizeDelta;
+ return localPoint - (background.anchorMax * baseRect.sizeDelta) + pivotOffset;
+ }
+ return Vector2.zero;
+ }
+}
+
+public enum AxisOptions { Both, Horizontal, Vertical }
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs.meta new file mode 100644 index 0000000..40806d8 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Base/Joystick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9fca4100a7477741b3973b4ff2c405f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Editor.meta new file mode 100644 index 0000000..fc35295 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8bf1b896f4e24d441975cb6f11f92e74 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs new file mode 100644 index 0000000..e562c3b --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs @@ -0,0 +1,35 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+[CustomEditor(typeof(DynamicJoystick))]
+public class DynamicJoystickEditor : JoystickEditor
+{
+ private SerializedProperty moveThreshold;
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ moveThreshold = serializedObject.FindProperty("moveThreshold");
+ }
+
+ public override void OnInspectorGUI()
+ {
+ base.OnInspectorGUI();
+
+ if (background != null)
+ {
+ RectTransform backgroundRect = (RectTransform)background.objectReferenceValue;
+ backgroundRect.anchorMax = Vector2.zero;
+ backgroundRect.anchorMin = Vector2.zero;
+ backgroundRect.pivot = center;
+ }
+ }
+
+ protected override void DrawValues()
+ {
+ base.DrawValues();
+ EditorGUILayout.PropertyField(moveThreshold, new GUIContent("Move Threshold", "The distance away from the center input has to be before the joystick begins to move."));
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs.meta new file mode 100644 index 0000000..bb13db0 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/DynamicJoystickEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 52071c88a467b46438b3cbf159bf988b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs new file mode 100644 index 0000000..9ae160e --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs @@ -0,0 +1,21 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+[CustomEditor(typeof(FloatingJoystick))]
+public class FloatingJoystickEditor : JoystickEditor
+{
+ public override void OnInspectorGUI()
+ {
+ base.OnInspectorGUI();
+
+ if (background != null)
+ {
+ RectTransform backgroundRect = (RectTransform)background.objectReferenceValue;
+ backgroundRect.anchorMax = Vector2.zero;
+ backgroundRect.anchorMin = Vector2.zero;
+ backgroundRect.pivot = center;
+ }
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs.meta new file mode 100644 index 0000000..1026f94 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/FloatingJoystickEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 614d06243900d764f9c50b4da2c950a3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs new file mode 100644 index 0000000..782c9f3 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs @@ -0,0 +1,64 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+[CustomEditor(typeof(Joystick), true)]
+public class JoystickEditor : Editor
+{
+ private SerializedProperty handleRange;
+ private SerializedProperty deadZone;
+ private SerializedProperty axisOptions;
+ private SerializedProperty snapX;
+ private SerializedProperty snapY;
+ protected SerializedProperty background;
+ private SerializedProperty handle;
+
+ protected Vector2 center = new Vector2(0.5f, 0.5f);
+
+ protected virtual void OnEnable()
+ {
+ handleRange = serializedObject.FindProperty("handleRange");
+ deadZone = serializedObject.FindProperty("deadZone");
+ axisOptions = serializedObject.FindProperty("axisOptions");
+ snapX = serializedObject.FindProperty("snapX");
+ snapY = serializedObject.FindProperty("snapY");
+ background = serializedObject.FindProperty("background");
+ handle = serializedObject.FindProperty("handle");
+ }
+
+ public override void OnInspectorGUI()
+ {
+ serializedObject.Update();
+
+ DrawValues();
+ EditorGUILayout.Space();
+ DrawComponents();
+
+ serializedObject.ApplyModifiedProperties();
+
+ if(handle != null)
+ {
+ RectTransform handleRect = (RectTransform)handle.objectReferenceValue;
+ handleRect.anchorMax = center;
+ handleRect.anchorMin = center;
+ handleRect.pivot = center;
+ handleRect.anchoredPosition = Vector2.zero;
+ }
+ }
+
+ protected virtual void DrawValues()
+ {
+ EditorGUILayout.PropertyField(handleRange, new GUIContent("Handle Range", "The distance the visual handle can move from the center of the joystick."));
+ EditorGUILayout.PropertyField(deadZone, new GUIContent("Dead Zone", "The distance away from the center input has to be before registering."));
+ EditorGUILayout.PropertyField(axisOptions, new GUIContent("Axis Options", "Which axes the joystick uses."));
+ EditorGUILayout.PropertyField(snapX, new GUIContent("Snap X", "Snap the horizontal input to a whole value."));
+ EditorGUILayout.PropertyField(snapY, new GUIContent("Snap Y", "Snap the vertical input to a whole value."));
+ }
+
+ protected virtual void DrawComponents()
+ {
+ EditorGUILayout.ObjectField(background, new GUIContent("Background", "The background's RectTransform component."));
+ EditorGUILayout.ObjectField(handle, new GUIContent("Handle", "The handle's RectTransform component."));
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs.meta new file mode 100644 index 0000000..59d5e45 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/JoystickEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d4b2b0d911a01a64ebfca9918e2b90b4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs new file mode 100644 index 0000000..f2ba979 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs @@ -0,0 +1,37 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+using UnityEditor;
+
+[CustomEditor(typeof(VariableJoystick))]
+public class VariableJoystickEditor : JoystickEditor
+{
+ private SerializedProperty moveThreshold;
+ private SerializedProperty joystickType;
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ moveThreshold = serializedObject.FindProperty("moveThreshold");
+ joystickType = serializedObject.FindProperty("joystickType");
+ }
+
+ public override void OnInspectorGUI()
+ {
+ base.OnInspectorGUI();
+
+ if (background != null)
+ {
+ RectTransform backgroundRect = (RectTransform)background.objectReferenceValue;
+ backgroundRect.pivot = center;
+ }
+ }
+
+ protected override void DrawValues()
+ {
+ base.DrawValues();
+ EditorGUILayout.PropertyField(moveThreshold, new GUIContent("Move Threshold", "The distance away from the center input has to be before the joystick begins to move."));
+ EditorGUILayout.PropertyField(joystickType, new GUIContent("Joystick Type", "The type of joystick the variable joystick is current using."));
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs.meta new file mode 100644 index 0000000..881d524 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Editor/VariableJoystickEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58b5a2db95af76c4c9d4116a09ec3697 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks.meta new file mode 100644 index 0000000..06db9f1 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 30f674d88470a814e8648e216b61b9ef +folderAsset: yes +timeCreated: 1513537874 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs new file mode 100644 index 0000000..4224550 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs @@ -0,0 +1,41 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+
+public class DynamicJoystick : Joystick
+{
+ public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
+
+ [SerializeField] private float moveThreshold = 1;
+
+ protected override void Start()
+ {
+ MoveThreshold = moveThreshold;
+ base.Start();
+ background.gameObject.SetActive(false);
+ }
+
+ public override void OnPointerDown(PointerEventData eventData)
+ {
+ background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
+ background.gameObject.SetActive(true);
+ base.OnPointerDown(eventData);
+ }
+
+ public override void OnPointerUp(PointerEventData eventData)
+ {
+ background.gameObject.SetActive(false);
+ base.OnPointerUp(eventData);
+ }
+
+ protected override void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
+ {
+ if (magnitude > moveThreshold)
+ {
+ Vector2 difference = normalised * (magnitude - moveThreshold) * radius;
+ background.anchoredPosition += difference;
+ }
+ base.HandleInput(magnitude, normalised, radius, cam);
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs.meta new file mode 100644 index 0000000..a236f7c --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/DynamicJoystick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba0d0e7a039f526499c356a3c5cd6d3f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs new file mode 100644 index 0000000..34ffec0 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FixedJoystick : Joystick +{ + +}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs.meta new file mode 100644 index 0000000..a5643e1 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FixedJoystick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45977bbae16431c46a013576a1aea384 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs new file mode 100644 index 0000000..95acaac --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs @@ -0,0 +1,26 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+
+public class FloatingJoystick : Joystick
+{
+ protected override void Start()
+ {
+ base.Start();
+ background.gameObject.SetActive(false);
+ }
+
+ public override void OnPointerDown(PointerEventData eventData)
+ {
+ background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
+ background.gameObject.SetActive(true);
+ base.OnPointerDown(eventData);
+ }
+
+ public override void OnPointerUp(PointerEventData eventData)
+ {
+ background.gameObject.SetActive(false);
+ base.OnPointerUp(eventData);
+ }
+}
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs.meta new file mode 100644 index 0000000..9667e61 --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/FloatingJoystick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a47f546fc70ec8428172694e78e4288 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs new file mode 100644 index 0000000..17e98db --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs @@ -0,0 +1,63 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+
+public class VariableJoystick : Joystick
+{
+ public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
+
+ [SerializeField] private float moveThreshold = 1;
+ [SerializeField] private JoystickType joystickType = JoystickType.Fixed;
+
+ private Vector2 fixedPosition = Vector2.zero;
+
+ public void SetMode(JoystickType joystickType)
+ {
+ this.joystickType = joystickType;
+ if(joystickType == JoystickType.Fixed)
+ {
+ background.anchoredPosition = fixedPosition;
+ background.gameObject.SetActive(true);
+ }
+ else
+ background.gameObject.SetActive(false);
+ }
+
+ protected override void Start()
+ {
+ base.Start();
+ fixedPosition = background.anchoredPosition;
+ SetMode(joystickType);
+ }
+
+ public override void OnPointerDown(PointerEventData eventData)
+ {
+ if(joystickType != JoystickType.Fixed)
+ {
+ background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
+ background.gameObject.SetActive(true);
+ }
+ base.OnPointerDown(eventData);
+ }
+
+ public override void OnPointerUp(PointerEventData eventData)
+ {
+ if(joystickType != JoystickType.Fixed)
+ background.gameObject.SetActive(false);
+
+ base.OnPointerUp(eventData);
+ }
+
+ protected override void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
+ {
+ if (joystickType == JoystickType.Dynamic && magnitude > moveThreshold)
+ {
+ Vector2 difference = normalised * (magnitude - moveThreshold) * radius;
+ background.anchoredPosition += difference;
+ }
+ base.HandleInput(magnitude, normalised, radius, cam);
+ }
+}
+
+public enum JoystickType { Fixed, Floating, Dynamic }
\ No newline at end of file diff --git a/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs.meta b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs.meta new file mode 100644 index 0000000..81f40bf --- /dev/null +++ b/Assets/Thirdparty/Joystick Pack/Scripts/Joysticks/VariableJoystick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 42844a4fccbd54746b90cade4ff70f73 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
