2
0
Fork 0
mirror of https://github.com/GTA-ASM/SanAndreasUnity synced 2025-02-18 13:58:28 +00:00

vehicle turning input done ?

This commit is contained in:
in0finite 2019-07-25 03:34:27 +02:00
parent 56bee753ed
commit f85a7d813b
2 changed files with 64 additions and 20 deletions
Assets/Scripts

View file

@ -86,11 +86,16 @@ namespace SanAndreasUnity.UI
void OnLoaderFinished()
{
// assign textures to movement button's arrows
// assign textures to movement buttons' arrows
movementButton.leftArrow.texture = HUD.LeftArrowTexture;
movementButton.rightArrow.texture = HUD.RightArrowTexture;
movementButton.upArrow.texture = HUD.DownArrowTexture;
movementButton.downArrow.texture = HUD.UpArrowTexture;
turnVehicleButton.leftArrow.texture = HUD.LeftArrowTexture;
turnVehicleButton.rightArrow.texture = HUD.RightArrowTexture;
}
void Update()
@ -114,7 +119,7 @@ namespace SanAndreasUnity.UI
CustomInput.Instance.SetButtonDown("LeftClick", false);
CustomInput.Instance.SetButtonDown("RightClick", false);
this.UpdateMovementInput();
this.UpdatePedMovementInput();
this.UpdateActionsInput();
@ -144,30 +149,50 @@ namespace SanAndreasUnity.UI
customInput.SetButton("RightClick", isAimOn);
}
void UpdateMovementInput()
void UpdatePedMovementInput()
{
// obtain input from arrow button
this.UpdateMovementInput(movementButton, movementButton.GetMovement());
}
var customInput = CustomInput.Instance;
void UpdateVehicleTurningInput()
{
// obtain input from arrow button
Vector2 input = turnVehicleButton.GetMovementPercentage();
// ignore y axis
input.y = 0;
// now input has only x value between -1 and 1
// obtain input from movement button
this.UpdateMovementInput(turnVehicleButton, input);
}
Vector2 input = Vector2.zero;
if (movementButton.IsPointerDown && movementButton.IsPointerInside)
void UpdateMovementInput(ArrowsMovementButton arrowButton, Vector2 input)
{
if (arrowButton.IsPointerDown && arrowButton.IsPointerInside)
{
input = movementButton.GetMovement();
// ignore mouse move input while movement button is pressed
customInput.SetAxis("Mouse X", 0);
customInput.SetAxis("Mouse Y", 0);
customInput.SetAxis("Joystick X", 0);
customInput.SetAxis("Joystick Y", 0);
// ignore mouse move input while arrow button is pressed
this.ResetMouseMoveInput();
}
// set input for vertical and horizontal axis
this.SetMovementAxesInput(input);
}
void ResetMouseMoveInput()
{
var customInput = CustomInput.Instance;
customInput.SetAxis("Mouse X", 0);
customInput.SetAxis("Mouse Y", 0);
customInput.SetAxis("Joystick X", 0);
customInput.SetAxis("Joystick Y", 0);
}
void SetMovementAxesInput(Vector2 input)
{
var customInput = CustomInput.Instance;
customInput.SetAxis("Vertical", input.y);
customInput.SetAxis("Horizontal", input.x);
}
void UpdateActionsInput()

View file

@ -43,7 +43,7 @@ namespace SanAndreasUnity.Utilities
this.IsPointerInside = false;
}
public Vector2 GetMovement()
public Vector2 GetMovementNonNormalized()
{
if (!m_isPointerDown || !this.IsPointerInside)
return Vector2.zero;
@ -52,9 +52,28 @@ namespace SanAndreasUnity.Utilities
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, mousePos, null, out localPoint))
return Vector2.zero;
Vector2 diff = localPoint;
if (diff.sqrMagnitude < float.Epsilon)
return diff;
}
public Vector2 GetMovement()
{
return this.GetMovementNonNormalized().normalized;
}
public Vector2 GetMovementPercentage()
{
Rect rect = (this.transform as RectTransform).rect;
float width = rect.width;
float height = rect.height;
if (width < float.Epsilon || height < float.Epsilon)
return Vector2.zero;
return diff.normalized;
Vector2 diff = this.GetMovementNonNormalized();
float xPerc = diff.x / (width * 0.5f);
float yPerc = diff.y / (height * 0.5f);
xPerc = Mathf.Clamp(xPerc, -1f, 1f);
yPerc = Mathf.Clamp(yPerc, -1f, 1f);
return new Vector2(xPerc, yPerc);
}