mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 12:03:04 +00:00
remove HUD related code from state class
This commit is contained in:
parent
5ed74ff3d1
commit
e6ecbc01e4
2 changed files with 2 additions and 196 deletions
|
@ -273,200 +273,6 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
||||||
|
|
||||||
public virtual void OnDrawHUD()
|
public virtual void OnDrawHUD()
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
|
|
||||||
if (!UIManager.Instance.UseTouchInput || !GameManager.CanPlayerReadInput())
|
|
||||||
{
|
|
||||||
// we are not using touch input, or we should not read input right now
|
|
||||||
// make sure that custom input is resetted
|
|
||||||
this.ResetCustomInput();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Event.current.type == EventType.Repaint) // repaint event is sent once per frame, when drawing
|
|
||||||
{
|
|
||||||
// reset input only during repaint event
|
|
||||||
this.ResetCustomInput();
|
|
||||||
|
|
||||||
// ignore mouse buttons when touch is enabled
|
|
||||||
CustomInput.Instance.SetButton("LeftClick", false);
|
|
||||||
if (!CustomInput.Instance.HasButton("RightClick"))
|
|
||||||
CustomInput.Instance.SetButton("RightClick", false);
|
|
||||||
CustomInput.Instance.SetButtonDown("LeftClick", false);
|
|
||||||
CustomInput.Instance.SetButtonDown("RightClick", false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// left side: movement buttons: arrows
|
|
||||||
// right side: action buttons: crouch, enter, fly, toggle sprint/walk, jump (repeat button), toggle aim
|
|
||||||
|
|
||||||
this.DrawMovementTouchInput();
|
|
||||||
this.DrawActionsTouchInput();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void ResetCustomInput()
|
|
||||||
{
|
|
||||||
var customInput = CustomInput.Instance;
|
|
||||||
|
|
||||||
if (!UIManager.Instance.UseTouchInput)
|
|
||||||
{
|
|
||||||
// touch input is not used
|
|
||||||
customInput.ResetAllInput();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// preserve input for: walk, sprint, aim
|
|
||||||
|
|
||||||
bool isWalkOn = customInput.GetButtonNoDefaultInput("Walk");
|
|
||||||
bool isSprintOn = customInput.GetButtonNoDefaultInput("Sprint");
|
|
||||||
bool isAimOn = customInput.GetButtonNoDefaultInput("RightClick");
|
|
||||||
|
|
||||||
customInput.ResetAllInput();
|
|
||||||
|
|
||||||
customInput.SetButton("Walk", isWalkOn);
|
|
||||||
customInput.SetButton("Sprint", isSprintOn);
|
|
||||||
customInput.SetButton("RightClick", isAimOn);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void DrawMovementTouchInput()
|
|
||||||
{
|
|
||||||
// movement buttons
|
|
||||||
|
|
||||||
float height = Screen.height * 0.4f;
|
|
||||||
float bottomMargin = Screen.height * 0.05f;
|
|
||||||
float horizontalMargin = bottomMargin;
|
|
||||||
|
|
||||||
// we'll need 3 rows of buttons: up, left & right, down
|
|
||||||
float buttonHeight = height / 3;
|
|
||||||
float buttonWidth = buttonHeight;
|
|
||||||
|
|
||||||
CustomInput customInput = CustomInput.Instance;
|
|
||||||
|
|
||||||
float movementVertical = 0f, movementHorizontal = 0f;
|
|
||||||
|
|
||||||
float topY = Screen.height - bottomMargin - buttonHeight;
|
|
||||||
if (GUI.RepeatButton(new Rect(horizontalMargin + buttonWidth, topY, buttonWidth, buttonHeight), UI.HUD.DownArrowTexture))
|
|
||||||
movementVertical -= 1f;
|
|
||||||
topY -= buttonHeight;
|
|
||||||
if (GUI.RepeatButton(new Rect(horizontalMargin, topY, buttonWidth, buttonHeight), UI.HUD.LeftArrowTexture))
|
|
||||||
movementHorizontal -= 1f;
|
|
||||||
if (GUI.RepeatButton(new Rect(horizontalMargin + buttonWidth * 2, topY, buttonWidth, buttonHeight), UI.HUD.RightArrowTexture))
|
|
||||||
movementHorizontal += 1f;
|
|
||||||
topY -= buttonHeight;
|
|
||||||
if (GUI.RepeatButton(new Rect(horizontalMargin + buttonWidth, topY, buttonWidth, buttonHeight), UI.HUD.UpArrowTexture))
|
|
||||||
movementVertical += 1f;
|
|
||||||
|
|
||||||
// set input for vertical and horizontal axis
|
|
||||||
customInput.SetAxis("Vertical", movementVertical);
|
|
||||||
customInput.SetAxis("Horizontal", movementHorizontal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void DrawActionsTouchInput()
|
|
||||||
{
|
|
||||||
// it's on the right side
|
|
||||||
// create buttons from bottom to top
|
|
||||||
|
|
||||||
CustomInput customInput = CustomInput.Instance;
|
|
||||||
|
|
||||||
float buttonHeight = Screen.height / 5f * 0.6f;
|
|
||||||
float buttonWidth = buttonHeight;
|
|
||||||
|
|
||||||
float bottomMargin = Screen.height * 0.05f;
|
|
||||||
float horizontalMargin = bottomMargin;
|
|
||||||
|
|
||||||
float xPos = Screen.width - horizontalMargin - buttonWidth;
|
|
||||||
float originalXPos = xPos;
|
|
||||||
float horizontalSpace = 5f;
|
|
||||||
|
|
||||||
// sprint/walk toggle button
|
|
||||||
|
|
||||||
bool isWalkOn = customInput.GetButton("Walk"); // preserve current value
|
|
||||||
bool isSprintOn = customInput.GetButton("Sprint"); // preserve current value
|
|
||||||
|
|
||||||
float topY = Screen.height - bottomMargin - buttonHeight;
|
|
||||||
GUI.contentColor = isWalkOn ? Color.blue : Color.white;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Walk"))
|
|
||||||
{
|
|
||||||
isWalkOn = !isWalkOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
//topY -= buttonHeight;
|
|
||||||
xPos -= buttonWidth + horizontalSpace;
|
|
||||||
GUI.contentColor = isSprintOn ? Color.blue : Color.white;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Sprint"))
|
|
||||||
{
|
|
||||||
isSprintOn = !isSprintOn;
|
|
||||||
}
|
|
||||||
GUI.contentColor = Color.white;
|
|
||||||
xPos = originalXPos;
|
|
||||||
|
|
||||||
// assign input
|
|
||||||
customInput.SetButton("Walk", isWalkOn);
|
|
||||||
customInput.SetButton("Sprint", isSprintOn);
|
|
||||||
|
|
||||||
// jump - repeat button
|
|
||||||
|
|
||||||
bool isJumpOn = false;
|
|
||||||
topY -= buttonHeight;
|
|
||||||
GUI.contentColor = m_ped.IsJumpOn ? Color.blue : Color.white;
|
|
||||||
if (GUI.RepeatButton(new Rect(xPos, topY, buttonWidth, buttonHeight), "Jump"))
|
|
||||||
{
|
|
||||||
isJumpOn = true;
|
|
||||||
}
|
|
||||||
GUI.contentColor = Color.white;
|
|
||||||
|
|
||||||
customInput.SetButton("Jump", isJumpOn);
|
|
||||||
|
|
||||||
// crouch
|
|
||||||
//topY -= buttonHeight;
|
|
||||||
xPos -= buttonWidth + horizontalSpace;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Crouch"))
|
|
||||||
{
|
|
||||||
customInput.SetKeyDown(KeyCode.C, true);
|
|
||||||
}
|
|
||||||
xPos = originalXPos;
|
|
||||||
|
|
||||||
// enter
|
|
||||||
topY -= buttonHeight;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Enter"))
|
|
||||||
{
|
|
||||||
customInput.SetButtonDown("Use", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// aim
|
|
||||||
bool isAimOn = customInput.GetButton("RightClick"); // preserve current value
|
|
||||||
topY -= buttonHeight;
|
|
||||||
GUI.contentColor = isAimOn ? Color.blue : Color.white;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Aim"))
|
|
||||||
{
|
|
||||||
isAimOn = !isAimOn;
|
|
||||||
}
|
|
||||||
GUI.contentColor = Color.white;
|
|
||||||
|
|
||||||
customInput.SetButton("RightClick", isAimOn);
|
|
||||||
|
|
||||||
// fire - repeat button
|
|
||||||
bool isFireOn = false;
|
|
||||||
xPos -= buttonWidth + horizontalSpace;
|
|
||||||
GUI.contentColor = m_ped.IsFireOn ? Color.blue : Color.white;
|
|
||||||
if (GUI.RepeatButton(new Rect(xPos, topY, buttonWidth, buttonHeight), "Fire"))
|
|
||||||
{
|
|
||||||
isFireOn = true;
|
|
||||||
}
|
|
||||||
GUI.contentColor = Color.white;
|
|
||||||
xPos = originalXPos;
|
|
||||||
|
|
||||||
customInput.SetButton("LeftClick", isFireOn);
|
|
||||||
|
|
||||||
// fly
|
|
||||||
topY -= buttonHeight;
|
|
||||||
if (GUI.Button(new Rect(xPos, topY, buttonWidth, buttonHeight), "Fly"))
|
|
||||||
{
|
|
||||||
customInput.SetKeyDown(KeyCode.T, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
- Android: add perms for read/write access to storage ; forbid screen rotation ; assign app version ;
|
- Android: add perms for read/write access to storage ; forbid screen rotation ; assign app version ;
|
||||||
|
|
||||||
- Touch input: vehicle touch input: forward, backward, handbrake, left & right ; weapon switching buttons ; lock cursor when testing finishes ; don't report mouse move input while movement button is being pressed ; remove HUD code from state class ; remove spamming logs ;
|
- Touch input: vehicle touch input: forward, backward, handbrake, left & right ; weapon switching buttons ; lock cursor when testing finishes ; don't report mouse move input while movement button is being pressed ; remove HUD code from state class ;
|
||||||
|
|
||||||
- Play sounds: horn ; empty weapon slot ; ped damage ; footsteps in run and sprint states ;
|
- Play sounds: horn ; empty weapon slot ; ped damage ; footsteps in run and sprint states ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue