Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- using UnityEngine.InputSystem;
- [System.Serializable]
- public class InputManager : MonoBehaviour
- {
- protected ScrollRect scrollRect;
- protected RectTransform contentPanel;
- public TMP_InputField searchBar, userInput, currentInput;
- public MainPlayerControls controls;
- private void Awake()
- {
- searchBar.enabled = false;
- userInput.enabled = true;
- currentInput = userInput;
- KeepFocus();
- controls = new MainPlayerControls();
- // the "context" variable stores a few things in it, but since we're just using a button it doesn't matter what we call it -- just a variable
- controls.Player.Search.performed += context => ChangeFocus(searchBar);
- controls.Player.CancelSearch.performed += context => ChangeFocus(userInput);
- }
- private void Update()
- {
- if (currentInput.isFocused == false)
- {
- KeepFocus();
- }
- }
- public void KeepFocus()
- {
- currentInput.Select();
- currentInput.ActivateInputField();
- }
- public void ChangeFocus(TMP_InputField i)
- {
- Debug.Log("PLAYER HIT SEARCH.");
- currentInput = i;
- KeepFocus();
- }
- public void SnapTo(RectTransform target)
- {
- Canvas.ForceUpdateCanvases();
- contentPanel.anchoredPosition =
- (Vector2)scrollRect.transform.InverseTransformPoint(contentPanel.position)
- - (Vector2)scrollRect.transform.InverseTransformPoint(target.position);
- }
- private void OnEnable()
- {
- controls.Enable();
- }
- private void OnDisable()
- {
- controls.Disable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement