Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/VRKeyboard/Utils/KeyboardManager.cs
2026-02-21 16:45:37 +08:00

160 lines
2.9 KiB
C#

using BitStrap;
using UnityEngine;
using UnityEngine.UI;
namespace VRKeyboard.Utils
{
public class KeyboardManager : MonoBehaviour
{
[Header("User defined")]
[Tooltip("If the character is uppercase at the initialization")]
public bool isUppercase;
public int maxInputLength;
[Header("UI Elements")]
public Text inputText;
public InputField inputField;
[Header("Essentials")]
public Transform keys;
private Key[] keyList;
private bool capslockFlag;
[Header("ColorBlock")]
public ColorBlock colorBlock = default(ColorBlock);
public Font font;
private string Input
{
get
{
return inputText.text;
}
set
{
inputText.text = value;
}
}
private void Awake()
{
keyList = keys.GetComponentsInChildren<Key>();
}
private void Start()
{
Key[] array = keyList;
foreach (Key key in array)
{
key.OnKeyClicked += GenerateInput;
}
capslockFlag = isUppercase;
CapsLock();
}
public void Backspace()
{
if (Input.Length > 0)
{
Input = Input.Remove(Input.Length - 1);
}
}
public void Clear()
{
Input = string.Empty;
}
public void CapsLock()
{
Key[] array = keyList;
foreach (Key key in array)
{
if (key is Alphabet)
{
key.CapsLock(capslockFlag);
}
}
capslockFlag = !capslockFlag;
}
public void Shift()
{
Key[] array = keyList;
foreach (Key key in array)
{
if (key is Shift)
{
key.ShiftKey();
}
}
}
public void GenerateInput(string s)
{
if (maxInputLength <= 0 || Input.Length < maxInputLength)
{
Input += s;
}
}
public void ChangeInputField(InputField newInputField)
{
inputField = newInputField;
if ((bool)inputField)
{
maxInputLength = inputField.characterLimit;
Input = inputField.text;
}
}
public void SendText()
{
if ((bool)inputField)
{
inputField.text = Input;
}
if ((bool)inputField && (bool)inputField.GetComponentInParent<HUDMultiplayer>())
{
HUDManager.Instance.hudMultiplayer.SendInputFieldMessage();
Clear();
}
else
{
Close();
}
}
public void Close()
{
if ((bool)inputField && (bool)inputField.GetComponentInParent<HUDMultiplayer>())
{
GameController.Instance.fishingPlayer.EnterChat(false);
HUDManager.Instance.hudMultiplayer.EnterInputMode(false);
GameController.Instance.fishingPlayer.vrPlayertUIInput.TurnOnUIController(false);
}
VRManager.Instance.HideKeyboard();
}
[Button]
public void FixButtonsHover()
{
Key[] componentsInChildren = keys.GetComponentsInChildren<Key>();
Key[] array = componentsInChildren;
foreach (Key key in array)
{
Button component = key.GetComponent<Button>();
component.GetComponent<Image>().color = Color.white;
component.transition = Selectable.Transition.ColorTint;
component.colors = colorBlock;
component.GetComponentInChildren<Text>().font = font;
}
}
}
}