123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.EventSystems;
- namespace SC.XR.Unity.Module_Keyboard
- {
- public class SCKeyboard3DKey : SCKeyboardBaseKey
- {
- #region KeyboardKeyEnums
- public SCKeyboardKeyEnum m_SCKeyboardKeyEnum;
- public SpecialKeyEnum m_SpecialKeyEnum;
- public LanguageKeyEnum m_LanguageKeyEnum;
- #endregion
- #region KeyboardKey Init Events
- /// <summary>
- /// Init Normal Key
- /// </summary>
- public virtual void OnNormalKeyInit()
- {
- }
- /// <summary>
- /// Init Symbol Key
- /// </summary>
- public virtual void OnSymbolKeyInit()
- {
- }
- /// <summary>
- /// Init Special Key
- /// </summary>
- public virtual void OnSpecialKeyInit()
- {
- }
- /// <summary>
- /// Init Pinyin Key
- /// </summary>
- public virtual void OnPinyinKeyInit()
- {
- }
- /// <summary>
- /// Init Language Key
- /// </summary>
- public virtual void OnLanguageKeyInit()
- {
- }
- /// <summary>
- /// Init Prompt Key
- /// </summary>
- public virtual void OnPromptKeyInit()
- {
- }
- #endregion
- #region KeyboardKey Regist Events
- /// <summary>
- /// Regist Normal Key
- /// </summary>
- public virtual void OnNormalKeyRegist()
- {
- OnKeyClickEvent += OnNormalKeyClick;
- }
- /// <summary>
- /// Regist Symbol Key
- /// </summary>
- public virtual void OnSymbolKeyRegist()
- {
- OnKeyClickEvent += OnNormalKeyClick;
- TextMesh textMesh = this.GetComponentInChildren<TextMesh>();
- this.Value = textMesh.text;
- if (SCKeyboardMono.symbolKeysDic.ContainsKey(this.Value))
- {
- List<SCKeyboardBaseKey> scKeyboard2DKeys = SCKeyboardMono.symbolKeysDic[this.Value];
- scKeyboard2DKeys.Add(this);
- SCKeyboardMono.symbolKeysDic[this.Value] = scKeyboard2DKeys;
- }
- else
- {
- List<SCKeyboardBaseKey> scKeyboard2DKeys = new List<SCKeyboardBaseKey>();
- scKeyboard2DKeys.Add(this);
- SCKeyboardMono.symbolKeysDic.Add(this.Value, scKeyboard2DKeys);
- }
- }
- /// <summary>
- /// Regist Special Key
- /// </summary>
- public virtual void OnSpecialKeyRegist()
- {
- OnKeyClickEvent += OnSpecialKeyClick;
- }
- /// <summary>
- /// Regist Pinyin Key
- /// </summary>
- public virtual void OnPinyinKeyRegist()
- {
- OnKeyClickEvent += OnPinyinKeyClick;
- TextMesh textMesh = this.GetComponentInChildren<TextMesh>();
- this.Value = textMesh.text;
- SCKeyboardMono.OnKeyboardShifted += Shift;
- }
- /// <summary>
- /// Regist Language Key
- /// </summary>
- public virtual void OnLanguageKeyRegist()
- {
- OnKeyClickEvent += OnLanguageKeyClick;
- }
- /// <summary>
- /// Regist Prompt Key
- /// </summary>
- public virtual void OnPromptKeyRegist()
- {
- OnKeyClickEvent += OnPromptKeyClick;
- }
- #endregion
- #region KeyboardKey UnRegist Events
- /// <summary>
- /// UnRegist Normal Key
- /// </summary>
- public virtual void OnNormalKeyUnRegist()
- {
- OnKeyClickEvent -= OnNormalKeyClick;
- }
- /// <summary>
- /// UnRegist Symbol Key
- /// </summary>
- public virtual void OnSymbolKeyUnRegist()
- {
- OnKeyClickEvent -= OnNormalKeyClick;
- SCKeyboardMono.symbolKeysDic.Clear();
- }
- /// <summary>
- /// UnRegist Special Key
- /// </summary>
- public virtual void OnSpecialKeyUnRegist()
- {
- OnKeyClickEvent -= OnSpecialKeyClick;
- }
- /// <summary>
- /// UnRegist Pinyin Key
- /// </summary>
- public virtual void OnPinyinKeyUnRegist()
- {
- OnKeyClickEvent -= OnPinyinKeyClick;
- SCKeyboardMono.OnKeyboardShifted -= Shift;
- }
- /// <summary>
- /// UnRegist Language Key
- /// </summary>
- public virtual void OnLanguageKeyUnRegist()
- {
- OnKeyClickEvent -= OnLanguageKeyClick;
- }
- /// <summary>
- /// UnRegist Prompt Key
- /// </summary>
- public virtual void OnPromptKeyUnRegist()
- {
- OnKeyClickEvent -= OnPromptKeyClick;
- }
- #endregion
- #region KeyboardKey Click Events
- public void OnNormalKeyClick()
- {
- SCKeyboardMono.OnNormalKeyClick(this.Value);
- }
- public void OnSpecialKeyClick()
- {
- SCKeyboardMono.OnSpecialKeyClick(m_SpecialKeyEnum);
- switch (m_SpecialKeyEnum)
- {
- case SpecialKeyEnum.Cn:
- GetComponentInChildren<TextMesh>().text = "英";
- m_SpecialKeyEnum = SpecialKeyEnum.En;
- break;
- case SpecialKeyEnum.En:
- GetComponentInChildren<TextMesh>().text = "中";
- m_SpecialKeyEnum = SpecialKeyEnum.Cn;
- break;
- }
- }
- public void OnPinyinKeyClick()
- {
- switch (SCKeyboardMono.presentKeyboardState)
- {
- case KeyboardState.Cn:
- if (SCKeyboardMono.IsShifted)
- {
- SCKeyboardMono.OnNormalKeyClick(this.Value);
- return;
- }
- SCKeyboardMono.OnPinyinKeyClick(this.Value);
- break;
- case KeyboardState.En:
- SCKeyboardMono.OnNormalKeyClick(this.Value);
- break;
- }
- }
- public void OnLanguageKeyClick()
- {
- SCKeyboardMono.OnLanguageKeyClick(m_LanguageKeyEnum);
- }
- public void OnPromptKeyClick()
- {
- TextMesh textMesh = this.GetComponentInChildren<TextMesh>();
- SCKeyboardMono.OnPromptKeyClick(textMesh.text);
- SCKeyboardMono.OnKeyClick?.Invoke(textMesh.text);
- for (int i = 0; i < textMesh.text.Length; i++)
- {
- SCKeyboardMono.OnWebKeyClick?.Invoke(textMesh.text[i].ToString());
- }
- }
- #endregion
- #region KeyboardKey State Events
- protected virtual void Shift(bool isShifted)
- {
- TextMesh textMesh = this.GetComponentInChildren<TextMesh>();
- if (isShifted)
- {
- string textUpper = textMesh.text.ToUpper();
- textMesh.text = textUpper;
- this.Value = textUpper;
- }
- else
- {
- string textLower = textMesh.text.ToLower();
- textMesh.text = textLower;
- this.Value = textLower;
- }
- }
- #endregion
- protected InteractionPressableEntry interactionPressableEntry;
- protected InteractionTouchableEntry interactionTouchableEntry;
- public override void Init()
- {
- base.Init();
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- case SCKeyboardKeyEnum.Num:
- OnNormalKeyInit();
- break;
- case SCKeyboardKeyEnum.Symbol:
- OnSymbolKeyInit();
- break;
- case SCKeyboardKeyEnum.Special:
- OnSpecialKeyInit();
- break;
- case SCKeyboardKeyEnum.Pinyin:
- OnPinyinKeyInit();
- break;
- case SCKeyboardKeyEnum.Prompt:
- OnPromptKeyInit();
- break;
- case SCKeyboardKeyEnum.Meme:
- break;
- case SCKeyboardKeyEnum.Language:
- OnLanguageKeyInit();
- break;
- default:
- OnNormalKeyInit();
- break;
- }
- }
- protected override void RegistKey()
- {
- PressableButton pressableButton = this.GetComponent<PressableButton>();
- TouchableButton touchableButton = this.GetComponent<TouchableButton>();
- if (pressableButton && touchableButton)
- {
- InteractionEvent interActionEvent = new InteractionEvent();
- interActionEvent.AddListener(OnKeyClick);
- interactionPressableEntry = new InteractionPressableEntry() { eventID = InteractionPressableType.PointerClick, callback = interActionEvent };
- interactionTouchableEntry = new InteractionTouchableEntry() { eventID = InteractionTouchableType.PokePress, callback = interActionEvent };
- pressableButton.Triggers.Add(interactionPressableEntry);
- touchableButton.Triggers.Add(interactionTouchableEntry);
- }
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- case SCKeyboardKeyEnum.Num:
- OnNormalKeyRegist();
- break;
- case SCKeyboardKeyEnum.Symbol:
- OnSymbolKeyRegist();
- break;
- case SCKeyboardKeyEnum.Special:
- OnSpecialKeyRegist();
- break;
- case SCKeyboardKeyEnum.Pinyin:
- OnPinyinKeyRegist();
- break;
- case SCKeyboardKeyEnum.Prompt:
- OnPromptKeyRegist();
- break;
- case SCKeyboardKeyEnum.Meme:
- break;
- case SCKeyboardKeyEnum.Language:
- OnLanguageKeyRegist();
- break;
- default:
- OnNormalKeyRegist();
- break;
- }
- }
- protected override void UnRegistKey()
- {
- PressableButton pressableButton = this.GetComponent<PressableButton>();
- TouchableButton touchableButton = this.GetComponent<TouchableButton>();
- if (pressableButton && touchableButton)
- {
- pressableButton.Triggers.Remove(interactionPressableEntry);
- touchableButton.Triggers.Remove(interactionTouchableEntry);
- }
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- case SCKeyboardKeyEnum.Num:
- OnNormalKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Symbol:
- OnSymbolKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Special:
- OnSpecialKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Pinyin:
- OnPinyinKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Prompt:
- OnPromptKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Meme:
- break;
- case SCKeyboardKeyEnum.Language:
- OnLanguageKeyUnRegist();
- break;
- default:
- OnNormalKeyUnRegist();
- break;
- }
- }
- }
- }
|