diff --git a/Plugins/SimpleInput/Scripts/AxisInputs/Joystick.cs b/Plugins/SimpleInput/Scripts/AxisInputs/Joystick.cs index 8edde81..645650b 100644 --- a/Plugins/SimpleInput/Scripts/AxisInputs/Joystick.cs +++ b/Plugins/SimpleInput/Scripts/AxisInputs/Joystick.cs @@ -12,7 +12,7 @@ public enum MovementAxes { XandY, X, Y }; public SimpleInput.AxisInput yAxis = new SimpleInput.AxisInput( "Vertical" ); private RectTransform joystickTR; - private Image background; + private Graphic background; public MovementAxes movementAxes = MovementAxes.XandY; public float valueMultiplier = 1f; @@ -48,10 +48,10 @@ private void Awake() joystickTR = (RectTransform) transform; thumbTR = thumb.rectTransform; - Image bgImage = GetComponent(); - if( bgImage != null ) + Graphic bgGraphic = GetComponent(); + if( bgGraphic ) { - background = bgImage; + background = bgGraphic; background.raycastTarget = false; } @@ -67,6 +67,8 @@ private void Awake() _1OverMovementAreaRadius = 1f / movementAreaRadius; movementAreaRadiusSqr = movementAreaRadius * movementAreaRadius; + + thumbTR.localPosition = Vector3.zero; } private void Start() @@ -76,28 +78,17 @@ private void Start() eventReceiver = thumbTR.gameObject.AddComponent(); else { - if( dynamicJoystickMovementArea == null ) + if( !dynamicJoystickMovementArea ) { - Transform canvasTransform = thumb.canvas.transform; - dynamicJoystickMovementArea = new GameObject( "Dynamic Joystick Movement Area", typeof( RectTransform ), typeof( Image ) ).GetComponent(); - - dynamicJoystickMovementArea.SetParent( canvasTransform, false ); + dynamicJoystickMovementArea = new GameObject( "Dynamic Joystick Movement Area", typeof( RectTransform ) ).GetComponent(); + dynamicJoystickMovementArea.SetParent( thumb.canvas.transform, false ); dynamicJoystickMovementArea.SetAsFirstSibling(); - dynamicJoystickMovementArea.anchorMin = Vector2.zero; dynamicJoystickMovementArea.anchorMax = Vector2.one; dynamicJoystickMovementArea.sizeDelta = Vector2.zero; dynamicJoystickMovementArea.anchoredPosition = Vector2.zero; } - Image dynamicJoystickMovementAreaRaycastTarget = dynamicJoystickMovementArea.GetComponent(); - if( dynamicJoystickMovementAreaRaycastTarget == null ) - dynamicJoystickMovementAreaRaycastTarget = dynamicJoystickMovementArea.gameObject.AddComponent(); - - dynamicJoystickMovementAreaRaycastTarget.sprite = thumb.sprite; - dynamicJoystickMovementAreaRaycastTarget.color = Color.clear; - dynamicJoystickMovementAreaRaycastTarget.raycastTarget = true; - eventReceiver = dynamicJoystickMovementArea.gameObject.AddComponent(); } @@ -184,7 +175,7 @@ private void OnUpdate() c.a = opacity; thumb.color = c; - if( background != null ) + if( background ) { c = background.color; c.a = opacity; diff --git a/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs b/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs new file mode 100644 index 0000000..d648551 --- /dev/null +++ b/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs @@ -0,0 +1,17 @@ +using UnityEngine.UI; + +namespace SimpleInputNamespace +{ + // Credit: http://answers.unity.com/answers/1157876/view.html + public class NonDrawingGraphic : Graphic + { + public override void SetMaterialDirty() { return; } + public override void SetVerticesDirty() { return; } + + protected override void OnPopulateMesh( VertexHelper vh ) + { + vh.Clear(); + return; + } + } +} \ No newline at end of file diff --git a/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs.meta b/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs.meta new file mode 100644 index 0000000..d6ee0d3 --- /dev/null +++ b/Plugins/SimpleInput/Scripts/Core/NonDrawingGraphic.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c9542c931e1c82442a58750f0f44fcd8 +timeCreated: 1572698215 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/SimpleInput/Scripts/Core/SimpleInputDragListener.cs b/Plugins/SimpleInput/Scripts/Core/SimpleInputDragListener.cs index d3d0dc4..5fcd309 100644 --- a/Plugins/SimpleInput/Scripts/Core/SimpleInputDragListener.cs +++ b/Plugins/SimpleInput/Scripts/Core/SimpleInputDragListener.cs @@ -13,11 +13,8 @@ public class SimpleInputDragListener : MonoBehaviour, IPointerDownHandler, IDrag private void Awake() { Graphic graphic = GetComponent(); - if( graphic == null ) - { - graphic = gameObject.AddComponent(); - graphic.color = Color.clear; - } + if( !graphic ) + graphic = gameObject.AddComponent(); graphic.raycastTarget = true; } diff --git a/Plugins/SimpleInput/Scripts/Core/SimpleInputMultiDragListener.cs b/Plugins/SimpleInput/Scripts/Core/SimpleInputMultiDragListener.cs index a914a37..aeaff1c 100644 --- a/Plugins/SimpleInput/Scripts/Core/SimpleInputMultiDragListener.cs +++ b/Plugins/SimpleInput/Scripts/Core/SimpleInputMultiDragListener.cs @@ -23,11 +23,8 @@ public class SimpleInputMultiDragListener : MonoBehaviour, IPointerDownHandler, private void Awake() { Graphic graphic = GetComponent(); - if( graphic == null ) - { - graphic = gameObject.AddComponent(); - graphic.color = Color.clear; - } + if( !graphic ) + graphic = gameObject.AddComponent(); graphic.raycastTarget = true; } diff --git a/README.md b/README.md index c9bf5a0..405a173 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ **WebGL Demo:** http://yasirkula.net/SimpleInputDemo/ -## ABOUT - SimpleInput is an improvement over Unity's standard **Input** system that allows you to use custom input providers like on-screen joysticks, UI buttons and d-pads. In other words, it lets you simulate e.g. Input.GetAxis when a button is pressed or a virtual joystick is dragged. It also supports using custom axes and buttons that don't necessarily exist in Edit-Project Settings-Input. -To use the SimpleInput system, simply replace Input with **SimpleInput** in your scripts; i.e: +## HOW TO + +First, import [SimpleInput.unitypackage](https://github.com/yasirkula/UnitySimpleInput/releases) to your project. To use the SimpleInput system, simply replace Input with **SimpleInput** in your scripts; i.e: - Input.GetAxis -> SimpleInput.GetAxis - Input.GetAxisRaw -> SimpleInput.GetAxisRaw @@ -31,10 +31,6 @@ By default, SimpleInput receives input from Unity's Input system, as well. That' SimpleInput works almost identically to standard Input system; only the lerping of Input.GetAxis might differ slightly. Lerp modifier can be configured via `SimpleInput.AxisLerpModifier`. -## UPGRADING FROM PREVIOUS VERSIONS - -If you are upgrading from a very old version of SimpleInput, values of axes, buttons, mouse buttons and keys in SimpleInput components might get reset after the upgrade. So, you should write down these values somewhere before upgrading the plugin. - ## BUILT-IN INPUT COMPONENTS ### SimpleInput.GetAxis Inputs diff --git a/SimpleInput.unitypackage b/SimpleInput.unitypackage deleted file mode 100644 index 3ff7eb7..0000000 Binary files a/SimpleInput.unitypackage and /dev/null differ