feature: Lock button when waiting for new message
This commit is contained in:
parent
b2bd875508
commit
cb907bc76a
4 changed files with 30 additions and 6 deletions
|
@ -1,17 +1,33 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Messaging.Composer {
|
||||
public class SendButton : MonoBehaviour {
|
||||
[SerializeField] private InputField inputField;
|
||||
|
||||
[SerializeField] private Sprite unlockedSprite;
|
||||
[SerializeField] private Sprite lockedSprite;
|
||||
private bool _locked;
|
||||
|
||||
[SerializeField] private Image button;
|
||||
|
||||
private MessageManager _messageManager;
|
||||
|
||||
private void Awake() {
|
||||
_messageManager = FindObjectOfType<MessageManager>();
|
||||
}
|
||||
|
||||
public void Lock() {
|
||||
_locked = true;
|
||||
button.sprite = lockedSprite;
|
||||
}
|
||||
public void Unlock() {
|
||||
_locked = false;
|
||||
button.sprite = unlockedSprite;
|
||||
}
|
||||
|
||||
public void SendEmojis() {
|
||||
if (CanSendText()) {
|
||||
_messageManager.CreateMessage(inputField.Text, true);
|
||||
|
@ -20,7 +36,8 @@ namespace Messaging.Composer {
|
|||
}
|
||||
|
||||
private bool CanSendText() {
|
||||
return !string.IsNullOrEmpty(inputField.Text) && !string.IsNullOrWhiteSpace(inputField.Text);
|
||||
bool isInputEmpty = string.IsNullOrEmpty(inputField.Text) || string.IsNullOrWhiteSpace(inputField.Text);
|
||||
return !isInputEmpty && !_locked;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue