1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace SC.XR.Unity.Module_Keyboard
- {
- public class Custom_SCInputField : Selectable
- {
- public Text text;
- public Vector3 m_Position;
- public Vector3 m_Rotation;
- public Vector3 m_Scale;
- protected SCKeyboard m_Keyboard;
- private bool shouldDeactivateOnDeselect
- {
- get
- {
- //TODO
- return (m_Keyboard == null || m_Keyboard.status > 0)
- && EventSystem.current.currentSelectedGameObject != this.gameObject;
- }
- }
- private bool m_ShouldDeactivateNextUpdate = false;
- private void LateUpdate()
- {
- #region SCKeyboard
- if (m_Keyboard != null && m_Keyboard.status > 0 && EventSystem.current.currentSelectedGameObject != this.gameObject)
- {
- this.m_ShouldDeactivateNextUpdate = true;
- }
- bool shouldDeactivateNextUpdate = this.m_ShouldDeactivateNextUpdate;
- if (shouldDeactivateNextUpdate)
- {
- OnDeselect(null);
- this.m_ShouldDeactivateNextUpdate = false;
- }
- #endregion
- }
- public override void OnDeselect(BaseEventData eventData)
- {
- if (shouldDeactivateOnDeselect)
- {
- //this.DeactivateInputField();
- base.OnDeselect(eventData);
- SCKeyboard.Close(SCKeyboardEnum.SCKeyboard2D);
- m_Keyboard = null;
- }
- }
- public override void OnSelect(BaseEventData eventData)
- {
- base.OnSelect(eventData);
- m_Keyboard = SCKeyboard.Open(SCKeyboardEnum.SCKeyboard2D, "", SCKeyboardType.Default, m_Position, Quaternion.Euler(m_Rotation), m_Scale);
- m_Keyboard.transform.SetParent(transform);
- SetKeyboardRegistEvents(m_Keyboard);
- }
- private void SetKeyboardRegistEvents(SCKeyboard scKeyboard)
- {
- scKeyboard.ClearOnKeyClickEvent();
- scKeyboard.ClearOnSpecialKeyClickEvent(SpecialKeyEnum.Delete);
- scKeyboard.RegisterOnKeyClickEvent((str) => { text.text += str; });
- scKeyboard.RegisterOnSpecialKeyClickEvent(SpecialKeyEnum.Delete, ()=> {
- if (text.text.Length == 0)
- {
- return;
- }
- text.text = text.text.Substring(0, text.text.Length - 1);
- });
- }
- }
- }
|