SCKeyboardKey.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using SC.XR.Unity.Module_InputSystem;
  2. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. public class SCKeyboardKey : MonoBehaviour, IPointerHandler
  8. {
  9. public Color color_Gray = new Color32(87, 87, b: 87, 255);
  10. public Color color_Blue = new Color32(76, 166, 255, 200);
  11. protected virtual void OnEnable()
  12. {
  13. }
  14. protected virtual void Start()
  15. {
  16. RegistKey();
  17. }
  18. protected virtual void RegistKey()
  19. {
  20. PressableButton pressableButton = this.GetComponent<PressableButton>();
  21. TouchableButton touchableButton = this.GetComponent<TouchableButton>();
  22. if (pressableButton && touchableButton)
  23. {
  24. InteractionEvent interActionEvent = new InteractionEvent();
  25. interActionEvent.AddListener(OnNormalKeyClick);
  26. pressableButton.Triggers.Add(new InteractionPressableEntry() { eventID = InteractionPressableType.PointerClick, callback = interActionEvent });
  27. touchableButton.Triggers.Add(new InteractionTouchableEntry() { eventID = InteractionTouchableType.PokePress, callback = interActionEvent });
  28. }
  29. }
  30. protected virtual void OnNormalKeyClick(BaseEventData eventData)
  31. {
  32. TextMesh textMesh = this.GetComponentInChildren<TextMesh>();
  33. GameKey3Dboard gameKey3Dboard = this.GetComponentInParent<GameKey3Dboard>();
  34. gameKey3Dboard.OnNormalKeyClick(textMesh.text);
  35. }
  36. public void OnPointerExit(PointerEventData eventData)
  37. {
  38. this.GetComponentInChildren<MeshRenderer>().material.color = color_Gray;
  39. }
  40. public virtual void OnPointerEnter(PointerEventData eventData)
  41. {
  42. this.GetComponentInChildren<MeshRenderer>().material.color = color_Blue;
  43. }
  44. public void OnPointerDown(PointerEventData eventData)
  45. {
  46. }
  47. public void OnPointerClick(PointerEventData eventData)
  48. {
  49. }
  50. public void OnPointerUp(PointerEventData eventData)
  51. {
  52. }
  53. public void OnDrag(PointerEventData eventData)
  54. {
  55. }
  56. }