mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
action buttons are working
This commit is contained in:
parent
1ad26f11ed
commit
6622ecd5a1
4 changed files with 150 additions and 2 deletions
|
@ -15,8 +15,15 @@ namespace SanAndreasUnity.UI
|
|||
Canvas canvas;
|
||||
GameObject pedMovementInputGo;
|
||||
Button walkButton, sprintButton, jumpButton, crouchButton, enterButton, aimButton, fireButton, flyButton;
|
||||
UIEventsPickup jumpButtonEventsPickup, fireButtonEventsPickup;
|
||||
Text walkButtonText, sprintButtonText, aimButtonText, jumpButtonText, fireButtonText;
|
||||
ArrowsMovementButton movementButton;
|
||||
|
||||
bool m_walkPressed, m_sprintPressed, m_aimPressed, m_crouchPressed, m_enterPressed, m_flyPressed;
|
||||
|
||||
public Color activeButtonColor = Color.blue;
|
||||
public Color inactiveButtonColor = Color.black;
|
||||
|
||||
|
||||
|
||||
void Awake ()
|
||||
|
@ -39,6 +46,30 @@ namespace SanAndreasUnity.UI
|
|||
flyButton = parent.Find("FlyButton").GetComponent<Button>();
|
||||
movementButton = parent.Find("MovementButton").GetComponent<ArrowsMovementButton>();
|
||||
|
||||
// repeat buttons: jump, fire
|
||||
jumpButtonEventsPickup = jumpButton.gameObject.GetOrAddComponent<UIEventsPickup>();
|
||||
fireButtonEventsPickup = fireButton.gameObject.GetOrAddComponent<UIEventsPickup>();
|
||||
|
||||
// text components
|
||||
walkButtonText = walkButton.GetComponentInChildren<Text>();
|
||||
sprintButtonText = sprintButton.GetComponentInChildren<Text>();
|
||||
aimButtonText = aimButton.GetComponentInChildren<Text>();
|
||||
jumpButtonText = jumpButton.GetComponentInChildren<Text>();
|
||||
fireButtonText = fireButton.GetComponentInChildren<Text>();
|
||||
|
||||
// setup button event handlers
|
||||
// note: for this to work properly, EventSystem.Update() must run before our Update()
|
||||
|
||||
// toggle buttons
|
||||
walkButton.onClick.AddListener( () => m_walkPressed = true );
|
||||
sprintButton.onClick.AddListener( () => m_sprintPressed = true );
|
||||
aimButton.onClick.AddListener( () => m_aimPressed = true );
|
||||
|
||||
// click buttons: crouch, enter, fly
|
||||
crouchButton.onClick.AddListener( () => m_crouchPressed = true );
|
||||
enterButton.onClick.AddListener( () => m_enterPressed = true );
|
||||
flyButton.onClick.AddListener( () => m_flyPressed = true );
|
||||
|
||||
}
|
||||
|
||||
void OnLoaderFinished()
|
||||
|
@ -72,6 +103,7 @@ namespace SanAndreasUnity.UI
|
|||
CustomInput.Instance.SetButtonDown("RightClick", false);
|
||||
|
||||
this.UpdateMovementInput();
|
||||
this.UpdateActionsInput();
|
||||
|
||||
|
||||
}
|
||||
|
@ -87,7 +119,7 @@ namespace SanAndreasUnity.UI
|
|||
return;
|
||||
}
|
||||
|
||||
// preserve input for: walk, sprint, aim
|
||||
// preserve input for toggle buttons: walk, sprint, aim
|
||||
|
||||
bool isWalkOn = customInput.GetButtonNoDefaultInput("Walk");
|
||||
bool isSprintOn = customInput.GetButtonNoDefaultInput("Sprint");
|
||||
|
@ -121,6 +153,50 @@ namespace SanAndreasUnity.UI
|
|||
|
||||
}
|
||||
|
||||
void UpdateActionsInput()
|
||||
{
|
||||
|
||||
var customInput = CustomInput.Instance;
|
||||
// Ped ped = Ped.Instance;
|
||||
// bool pedExists = ped != null;
|
||||
|
||||
|
||||
// get status of jump & fire repeat butons
|
||||
|
||||
bool isJumpOn = jumpButtonEventsPickup.IsPointerInside && jumpButtonEventsPickup.IsPointerDown;
|
||||
bool isFireOn = fireButtonEventsPickup.IsPointerInside && fireButtonEventsPickup.IsPointerDown;
|
||||
|
||||
customInput.SetButton("Jump", isJumpOn);
|
||||
customInput.SetButton("LeftClick", isFireOn);
|
||||
|
||||
// process click events
|
||||
|
||||
if (m_walkPressed)
|
||||
customInput.SetButton("Walk", ! customInput.GetButton("Walk"));
|
||||
if (m_sprintPressed)
|
||||
customInput.SetButton("Sprint", ! customInput.GetButton("Sprint"));
|
||||
if (m_aimPressed)
|
||||
customInput.SetButton("RightClick", ! customInput.GetButton("RightClick"));
|
||||
if (m_crouchPressed)
|
||||
customInput.SetKeyDown(KeyCode.C, true);
|
||||
if (m_enterPressed)
|
||||
customInput.SetButtonDown("Use", true);
|
||||
if (m_flyPressed)
|
||||
customInput.SetKeyDown(KeyCode.T, true);
|
||||
|
||||
m_walkPressed = m_sprintPressed = m_aimPressed = m_crouchPressed = m_enterPressed = m_flyPressed = false;
|
||||
|
||||
// set color of toggle & repeat buttons
|
||||
|
||||
jumpButtonText.color = isJumpOn ? this.activeButtonColor : this.inactiveButtonColor;
|
||||
fireButtonText.color = isFireOn ? this.activeButtonColor : this.inactiveButtonColor;
|
||||
|
||||
walkButtonText.color = customInput.GetButton("Walk") ? this.activeButtonColor : this.inactiveButtonColor;
|
||||
sprintButtonText.color = customInput.GetButton("Sprint") ? this.activeButtonColor : this.inactiveButtonColor;
|
||||
aimButtonText.color = customInput.GetButton("RightClick") ? this.activeButtonColor : this.inactiveButtonColor;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
61
Assets/Scripts/Utilities/UI/UIEventsPickup.cs
Normal file
61
Assets/Scripts/Utilities/UI/UIEventsPickup.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SanAndreasUnity.Utilities
|
||||
{
|
||||
|
||||
public class UIEventsPickup : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler,
|
||||
IPointerUpHandler
|
||||
{
|
||||
|
||||
public event Action<PointerEventData> onPointerClick = delegate {};
|
||||
public event Action<PointerEventData> onPointerEnter = delegate {};
|
||||
public event Action<PointerEventData> onPointerExit = delegate {};
|
||||
public event Action<PointerEventData> onPointerDown = delegate {};
|
||||
public event Action<PointerEventData> onPointerUp = delegate {};
|
||||
|
||||
public bool IsPointerInside { get; private set; } = false;
|
||||
public bool IsPointerDown { get; private set; } = false;
|
||||
|
||||
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
this.IsPointerInside = false;
|
||||
this.IsPointerDown = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick (PointerEventData eventData)
|
||||
{
|
||||
onPointerClick (eventData);
|
||||
}
|
||||
|
||||
public void OnPointerEnter (PointerEventData eventData)
|
||||
{
|
||||
this.IsPointerInside = true;
|
||||
onPointerEnter (eventData);
|
||||
}
|
||||
|
||||
public void OnPointerExit (PointerEventData eventData)
|
||||
{
|
||||
this.IsPointerInside = false;
|
||||
onPointerExit (eventData);
|
||||
}
|
||||
|
||||
public void OnPointerDown (PointerEventData eventData)
|
||||
{
|
||||
this.IsPointerDown = true;
|
||||
onPointerDown (eventData);
|
||||
}
|
||||
|
||||
public void OnPointerUp (PointerEventData eventData)
|
||||
{
|
||||
this.IsPointerDown = false;
|
||||
onPointerUp (eventData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Utilities/UI/UIEventsPickup.cs.meta
Normal file
11
Assets/Scripts/Utilities/UI/UIEventsPickup.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d85310033fdb20f2b92cb9dadc9bff6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
- Chat
|
||||
|
||||
- Android: HUD must run before other UI scripts ; add perms for read/write access to storage ; forbid screen rotation ; disable left and right mouse click ; vehicle touch input: forward, backward, handbrake, left & right ; weapon switching buttons ; circular button for movement ; lock cursor when testing finishes ; must use new UI system ; don't report mouse move input while movement button is being pressed ; remove HUD code from state class ;
|
||||
- Android: HUD must run before other UI scripts ; add perms for read/write access to storage ; forbid screen rotation ; disable left and right mouse click ; vehicle touch input: forward, backward, handbrake, left & right ; weapon switching buttons ; circular button for movement ; lock cursor when testing finishes ; must use new UI system ; don't report mouse move input while movement button is being pressed ; remove HUD code from state class ; event system should have SEO defined ;
|
||||
|
||||
- Play sounds: horn ; empty weapon slot ; ped damage ; footsteps in run and sprint states ;
|
||||
|
||||
|
|
Loading…
Reference in a new issue