123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace SC.XR.Unity.Module_Keyboard
- {
- public class SCKeyboard2DKey : SCKeyboardBaseKey
- {
- public override string Value
- {
- get
- {
- return base.Value;
- }
- set
- {
- base.Value = value;
- Text.text = value;
- }
- }
- private Text m_Text;
- public virtual Text Text
- {
- get
- {
- if (m_Text == null)
- m_Text = GetComponentInChildren<Text>();
- return m_Text;
- }
- set
- {
- m_Text = value;
- }
- }
- #region KeyboardKeyEnums
- public SCKeyboardKeyEnum m_SCKeyboardKeyEnum;
- public SpecialKeyEnum m_SpecialKeyEnum;
- public LanguageKeyEnum m_LanguageKeyEnum;
- public UGUIKeyEnum m_UGUIKeyEnum;
- #endregion
- #region KeyboardKey Init Events
- /// <summary>
- /// Init Normal Key
- /// </summary>
- public virtual void OnNormalKeyInit()
- {
- }
- public virtual void OnNumberKeyInit()
- {
- }
- /// <summary>
- /// Init Symbol Key
- /// </summary>
- public virtual void OnSymbolKeyInit()
- {
- }
- /// <summary>
- /// Init Special Key
- /// </summary>
- public virtual void OnSpecialKeyInit()
- {
- switch (m_SpecialKeyEnum)
- {
- case SpecialKeyEnum.Cn:
- case SpecialKeyEnum.En:
- switch (SCKeyboardMono.presentKeyboardType)
- {
- case SCKeyboardType.ASCIICapable:
- Value = "英";
- m_SpecialKeyEnum = SpecialKeyEnum.En;
- break;
- default:
- switch (SCKeyboard.currentSystemLanguage)
- {
- case KeyboardSystemLanguage.Chinese:
- Value = "中";
- m_SpecialKeyEnum = SpecialKeyEnum.Cn;
- break;
- default:
- Value = "英";
- m_SpecialKeyEnum = SpecialKeyEnum.En;
- break;
- }
- break;
- }
- break;
- }
-
- KeyboardStateChange(SCKeyboardMono.presentKeyboardState);
- }
- /// <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()
- {
- }
- /// <summary>
- /// Init UGUI Key
- /// </summary>
- public virtual void OnUGUIKeyInit()
- {
- }
- #endregion
- #region KeyboardKey Regist Events
- /// <summary>
- /// Regist Normal Key
- /// </summary>
- public virtual void OnNormalKeyRegist()
- {
- OnKeyClickEvent += OnNormalKeyClick;
- }
- /// <summary>
- /// Regist Number Key
- /// </summary>
- public virtual void OnNumberKeyRegist()
- {
- OnKeyClickEvent += OnNumberKeyClick;
- Text text = this.GetComponentInChildren<Text>();
- this.Value = text.text;
- }
- /// <summary>
- /// Regist Symbol Key
- /// </summary>
- public virtual void OnSymbolKeyRegist()
- {
- OnKeyClickEvent += OnNormalKeyClick;
- Text text = this.GetComponentInChildren<Text>();
- this.Value = text.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;
- if (SCKeyboardMono.specialKeysDic.ContainsKey(this.m_SpecialKeyEnum))
- {
- List<SCKeyboardBaseKey> scKeyboard2DKeys = SCKeyboardMono.specialKeysDic[this.m_SpecialKeyEnum];
- scKeyboard2DKeys.Add(this);
- SCKeyboardMono.specialKeysDic[this.m_SpecialKeyEnum] = scKeyboard2DKeys;
- }
- else
- {
- List<SCKeyboardBaseKey> scKeyboard2DKeys = new List<SCKeyboardBaseKey>();
- scKeyboard2DKeys.Add(this);
- SCKeyboardMono.specialKeysDic.Add(this.m_SpecialKeyEnum, scKeyboard2DKeys);
- }
- SCKeyboardMono.OnKeyboardStateChange += KeyboardStateChange;
- }
- /// <summary>
- /// Regist Pinyin Key
- /// </summary>
- public virtual void OnPinyinKeyRegist()
- {
- OnKeyClickEvent += OnPinyinKeyClick;
- Text text = this.GetComponentInChildren<Text>();
- this.Value = text.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;
- }
- /// <summary>
- /// Regist UGUI Key
- /// </summary>
- public virtual void OnUGUIKeyRegist()
- {
- OnKeyClickEvent += OnUGUIKeyClick;
- }
- #endregion
- #region KeyboardKey UnRegist Events
- /// <summary>
- /// UnRegist Normal Key
- /// </summary>
- public virtual void OnNormalKeyUnRegist()
- {
- OnKeyClickEvent -= OnNormalKeyClick;
- }
- /// <summary>
- /// UnRegist Number Key
- /// </summary>
- public virtual void OnNumberKeyUnRegist()
- {
- OnKeyClickEvent -= OnNumberKeyClick;
- }
- /// <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;
- SCKeyboardMono.specialKeysDic.Clear();
- SCKeyboardMono.OnKeyboardStateChange -= KeyboardStateChange;
- }
- /// <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;
- }
- /// <summary>
- /// UnRegist UGUI Key
- /// </summary>
- public virtual void OnUGUIKeyUnRegist()
- {
- OnKeyClickEvent -= OnUGUIKeyClick;
- }
- #endregion
- #region KeyboardKey Click Events
- public void OnNormalKeyClick()
- {
- SCKeyboardMono.OnNormalKeyClick(this.Value);
- }
- public void OnNumberKeyClick()
- {
- SCKeyboardMono.OnNumberKeyClick(this.Value);
- }
- public void OnSpecialKeyClick()
- {
- SCKeyboardMono.OnSpecialKeyClick(m_SpecialKeyEnum);
- switch (m_SpecialKeyEnum)
- {
- case SpecialKeyEnum.Cn:
- Value = "英";
- m_SpecialKeyEnum = SpecialKeyEnum.En;
- break;
- case SpecialKeyEnum.En:
- Value = "中";
- 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()
- {
- SCKeyboardMono.OnPromptKeyClick(this.Value);
- }
- public void OnUGUIKeyClick()
- {
- SCKeyboardMono.OnUGUIKeyClick(m_UGUIKeyEnum);
- }
- #endregion
- #region KeyboardKey State Events
- protected virtual void Shift(bool isShifted)
- {
- Text text = this.GetComponentInChildren<Text>();
- if (isShifted)
- {
- this.Value = this.Value.ToUpper();
- }
- else
- {
- this.Value = this.Value.ToLower();
- }
- }
- protected virtual void KeyboardStateChange(KeyboardState state)
- {
- switch (state)
- {
- case KeyboardState.Cn:
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.Special:
- switch (m_SpecialKeyEnum)
- {
- case SpecialKeyEnum.Enter:
- switch (SCKeyboardMono.presentKeyboardType)
- {
- case SCKeyboardType.URL:
- case SCKeyboardType.Search:
- this.Value = "搜索";
- break;
- default:
- this.Value = "确认";
- break;
- }
- break;
- case SpecialKeyEnum.Space:
- this.Value = "空格";
- break;
- case SpecialKeyEnum.Participle:
- this.Value = "分词";
- break;
- }
- break;
- }
- break;
- case KeyboardState.En:
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.Special:
- switch (m_SpecialKeyEnum)
- {
- case SpecialKeyEnum.Enter:
- switch (SCKeyboardMono.presentKeyboardType)
- {
- case SCKeyboardType.URL:
- case SCKeyboardType.Search:
- this.Value = "Search";
- break;
- default:
- this.Value = "Enter";
- break;
- }
- break;
- case SpecialKeyEnum.Space:
- this.Value = "Space";
- break;
- case SpecialKeyEnum.Participle:
- this.Value = "/";
- break;
- }
- break;
- }
- break;
- }
- }
- #endregion
- public override void Init()
- {
- base.Init();
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- OnNormalKeyInit();
- break;
- case SCKeyboardKeyEnum.Num:
- OnNumberKeyInit();
- 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;
- case SCKeyboardKeyEnum.UGUI:
- OnUGUIKeyInit();
- break;
- default:
- OnNormalKeyInit();
- break;
- }
- }
- protected override void RegistKey()
- {
- base.RegistKey();
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- OnNormalKeyRegist();
- break;
- case SCKeyboardKeyEnum.Num:
- OnNumberKeyRegist();
- 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;
- case SCKeyboardKeyEnum.UGUI:
- OnUGUIKeyRegist();
- break;
- default:
- OnNormalKeyRegist();
- break;
- }
- }
- protected override void UnRegistKey()
- {
- base.UnRegistKey();
- switch (m_SCKeyboardKeyEnum)
- {
- case SCKeyboardKeyEnum.ABC:
- OnNormalKeyUnRegist();
- break;
- case SCKeyboardKeyEnum.Num:
- OnNumberKeyUnRegist();
- 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;
- case SCKeyboardKeyEnum.UGUI:
- OnUGUIKeyUnRegist();
- break;
- default:
- OnNormalKeyUnRegist();
- break;
- }
- }
- }
- }
|