using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace SC.XR.Unity.Module_Keyboard { public class Example : MonoBehaviour { SCKeyboard m_Keyboard; public Vector3 m_Position; public Vector3 m_Rotation; public Vector3 m_Scale; public Transform m_Parent; public SCKeyboardEnum m_SCKeyboardEnum; public Button chineseBtn; public Button englishBtn; public SCToggleCheckbox3D useSystemLanguageToggle; void Start() { // Register static Events. SCKeyboard.OnActiveStateChanged += OnActiveStateChanged; SCKeyboard.RegisterOnWebKeyClickEvent(OnWebKeyClickEvent); chineseBtn.onClick.AddListener(OnClickChineseBtn); englishBtn.onClick.AddListener(OnClickEnglishBtn); useSystemLanguageToggle.onValueChanged.AddListener(OnUseSystemLanguageToggleValueChanged); } private void OnDestroy() { chineseBtn.onClick.RemoveListener(OnClickChineseBtn); englishBtn.onClick.RemoveListener(OnClickEnglishBtn); useSystemLanguageToggle.onValueChanged.RemoveListener(OnUseSystemLanguageToggleValueChanged); } void Update() { // Open Keyboard. if (Input.GetKeyDown(KeyCode.O)) { m_Keyboard = SCKeyboard.Open(SCKeyboardEnum.SCKeyboard2D, "", SCKeyboardType.Default, m_Position, Quaternion.Euler(m_Rotation), m_Scale); } if (Input.GetKeyDown(KeyCode.L)) { m_Keyboard = SCKeyboard.Open(SCKeyboardEnum.SCKeyboard2D, ""); } if (Input.GetKeyDown(KeyCode.M)) { if (m_Keyboard != null) m_Keyboard.transform.position = m_Position; if (m_Keyboard != null) m_Keyboard.transform.rotation = Quaternion.Euler(m_Rotation); if (m_Keyboard != null) m_Keyboard.transform.localScale = m_Scale; } if (Input.GetKeyDown(KeyCode.P)) { if (m_Keyboard != null) m_Keyboard.transform.SetParent(m_Parent); } // Close Keyboard. if (Input.GetKeyDown(KeyCode.C)) { if (m_Keyboard != null) SCKeyboard.Close(m_SCKeyboardEnum); } // Register button press event. if (Input.GetKeyDown(KeyCode.R)) { if (m_Keyboard != null) m_Keyboard.RegisterOnKeyClickEvent(OnKeyClickEvent); } } public void OnActiveStateChanged(bool val) { Debug.Log("OnActiveStateChanged :"+val); } public void OnKeyClickEvent(string val) { Debug.Log("OnKeyClickEvent :" + val); } public void OnWebKeyClickEvent(string val) { Debug.Log("OnWebKeyClickEvent :" + val); } public void OnClickChineseBtn() { SCKeyboard.SetSystemLanguage(KeyboardSystemLanguage.Chinese); chineseBtn.GetComponentInChildren().text = "设置键盘系统语言为中文"; englishBtn.GetComponentInChildren().text = "设置键盘系统语言为英文"; useSystemLanguageToggle.GetComponentInChildren().text = "自动获取系统语言"; } public void OnClickEnglishBtn() { SCKeyboard.SetSystemLanguage(KeyboardSystemLanguage.English); chineseBtn.GetComponentInChildren().text = "Change Keyboard System Language To Chinese"; englishBtn.GetComponentInChildren().text = "Change Keyboard System Language To English"; useSystemLanguageToggle.GetComponentInChildren().text = "Auto Get System Language"; } public void OnUseSystemLanguageToggleValueChanged(bool value) { SCKeyboard.useSystemLanguage = value; } } }