SCKeyboardSpecialKey.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. public enum SpecialKeyEnum
  7. {
  8. Done,
  9. Clear,
  10. Delete,
  11. Space,
  12. Shift,
  13. ShowNum,
  14. ShowSymbol,
  15. ShowEnUp,
  16. ShowEnLow,
  17. ShowCn
  18. }
  19. public class SCKeyboardSpecialKey : SCKeyboardKey
  20. {
  21. public SpecialKeyEnum specialKeyEnum;
  22. private static Dictionary<SpecialKeyEnum, Action> specialCallbackDic;
  23. private static GameKey3Dboard game3DKayboardCache;
  24. protected override void OnEnable()
  25. {
  26. InitSpecialCallbackDic();
  27. }
  28. protected override void RegistKey()
  29. {
  30. PressableButton pressableButton = this.GetComponent<PressableButton>();
  31. TouchableButton touchableButton = this.GetComponent<TouchableButton>();
  32. if (pressableButton && touchableButton)
  33. {
  34. InteractionEvent interActionEvent = new InteractionEvent();
  35. interActionEvent.AddListener(OnSpecialKeyClick);
  36. pressableButton.Triggers.Add(new InteractionPressableEntry() { eventID = InteractionPressableType.PointerClick, callback = interActionEvent });
  37. touchableButton.Triggers.Add(new InteractionTouchableEntry() { eventID = InteractionTouchableType.PokePress, callback = interActionEvent });
  38. }
  39. }
  40. private void OnSpecialKeyClick(BaseEventData eventData)
  41. {
  42. if (specialCallbackDic != null && specialCallbackDic.ContainsKey(specialKeyEnum))
  43. {
  44. Action callback = specialCallbackDic[specialKeyEnum];
  45. callback?.Invoke();
  46. }
  47. }
  48. private void InitSpecialCallbackDic()
  49. {
  50. if (specialCallbackDic == null)
  51. {
  52. specialCallbackDic = new Dictionary<SpecialKeyEnum, Action>();
  53. }
  54. GameKey3Dboard gameKey3Dboard = this.GetComponentInParent<GameKey3Dboard>();
  55. if ( game3DKayboardCache != gameKey3Dboard)
  56. {
  57. specialCallbackDic.Clear();
  58. specialCallbackDic.Add(SpecialKeyEnum.Done, gameKey3Dboard.OnDoneClick);
  59. specialCallbackDic.Add(SpecialKeyEnum.Clear, gameKey3Dboard.OnClearKeyClick);
  60. specialCallbackDic.Add(SpecialKeyEnum.Delete, gameKey3Dboard.OnDeleteKeyClick);
  61. specialCallbackDic.Add(SpecialKeyEnum.ShowNum, gameKey3Dboard.ShowNum);
  62. specialCallbackDic.Add(SpecialKeyEnum.ShowSymbol, gameKey3Dboard.ShowSymbol);
  63. specialCallbackDic.Add(SpecialKeyEnum.ShowEnUp, gameKey3Dboard.ShowEnUp);
  64. specialCallbackDic.Add(SpecialKeyEnum.ShowEnLow, gameKey3Dboard.ShowEnLow);
  65. specialCallbackDic.Add(SpecialKeyEnum.Space, gameKey3Dboard.OnSpaceClick);
  66. specialCallbackDic.Add(SpecialKeyEnum.Shift, gameKey3Dboard.OnShiftClick);
  67. specialCallbackDic.Add(SpecialKeyEnum.ShowCn, gameKey3Dboard.ShowCN);
  68. }
  69. }
  70. }