123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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>().text = "设置键盘系统语言为中文";
- englishBtn.GetComponentInChildren<Text>().text = "设置键盘系统语言为英文";
- useSystemLanguageToggle.GetComponentInChildren<TextMesh>().text = "自动获取系统语言";
- }
- public void OnClickEnglishBtn()
- {
- SCKeyboard.SetSystemLanguage(KeyboardSystemLanguage.English);
- chineseBtn.GetComponentInChildren<Text>().text = "Change Keyboard System Language To Chinese";
- englishBtn.GetComponentInChildren<Text>().text = "Change Keyboard System Language To English";
- useSystemLanguageToggle.GetComponentInChildren<TextMesh>().text = "Auto Get System Language";
- }
- public void OnUseSystemLanguageToggleValueChanged(bool value)
- {
- SCKeyboard.useSystemLanguage = value;
- }
- }
- }
|