SCKeyboardKey.cs 2.0 KB

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