2
0
Fork 0
mirror of https://github.com/GTA-ASM/SanAndreasUnity synced 2025-03-05 07:37:17 +00:00

draw touch input for movement

This commit is contained in:
in0finite 2019-07-22 20:33:41 +02:00
parent 8ff92619ff
commit 2596a88be6
2 changed files with 57 additions and 0 deletions
Assets/Scripts/Behaviours/Ped/States

View file

@ -118,6 +118,61 @@ namespace SanAndreasUnity.Behaviours.Peds.States
m_ped.GetStateOrLogError<FlyState> ().EnterState (true);
}
public override void OnDrawHUD()
{
base.OnDrawHUD();
if (!UIManager.Instance.UseTouchInput)
return;
// left side: movement buttons: arrows
// right side: action buttons: crouch, enter, fly, toggle sprint, jump (repeat button), toggle aim
this.DrawMovementTouchInput();
}
protected virtual void DrawMovementTouchInput()
{
// movement buttons
// height - 1/3 screen height
float height = Screen.height / 3f;
float bottomMargin = 5f;
float horizontalMargin = 5f;
// we'll need 3 rows of buttons: up, left & right, down
float buttonHeight = (height - bottomMargin) / 3;
float buttonWidth = buttonHeight;
CustomInput customInput = CustomInput.Instance;
float movementVertical = 0f, movementHorizontal = 0f;
float topY = Screen.height - bottomMargin - buttonHeight;
if (GUI.Button(new Rect(horizontalMargin + buttonWidth, topY, buttonWidth, buttonHeight), "DOWN"))
movementVertical -= 1f;
topY -= buttonHeight;
if (GUI.Button(new Rect(horizontalMargin, topY, buttonWidth, buttonHeight), "LEFT"))
movementHorizontal -= 1f;
if (GUI.Button(new Rect(horizontalMargin + buttonWidth * 2, topY, buttonWidth, buttonHeight), "RIGHT"))
movementHorizontal += 1f;
topY -= buttonHeight;
if (GUI.Button(new Rect(horizontalMargin + buttonWidth, topY, buttonWidth, buttonHeight), "UP"))
movementVertical += 1f;
// set input for vertical and horizontal axis
customInput.SetAxis("Vertical", movementVertical);
customInput.SetAxis("Horizontal", movementHorizontal);
}
protected virtual void DrawActionsTouchInput()
{
}
}
}

View file

@ -296,6 +296,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
// inherited states only need to draw gui, read input from user, and assign input to custom input
// we will only draw gui for switching weapons
}