You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace CnControls
|
|
{
|
|
public class SensitiveJoystick : SimpleJoystick
|
|
{
|
|
public AnimationCurve SensitivityCurve = new AnimationCurve(
|
|
new Keyframe(0f, 0f, 1f, 1f),
|
|
new Keyframe(1f, 1f, 1f, 1f)
|
|
);
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
|
{
|
|
base.OnDrag(eventData);
|
|
|
|
// Read the raw values
|
|
float linearHorizontalValue = HorizontalAxis.Value;
|
|
float linearVerticalValue = VerticalAxis.Value;
|
|
|
|
// Keep the sign for correct direction
|
|
float horizontalSign = Mathf.Sign(linearHorizontalValue);
|
|
float verticalSign = Mathf.Sign(linearVerticalValue);
|
|
|
|
// Remap via the curve
|
|
HorizontalAxis.Value = horizontalSign * SensitivityCurve.Evaluate(horizontalSign * linearHorizontalValue);
|
|
VerticalAxis.Value = verticalSign * SensitivityCurve.Evaluate(verticalSign * linearVerticalValue);
|
|
}
|
|
}
|
|
}
|