123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace SC.XR.Unity.Module_Keyboard
- {
- public abstract class SCKeyboardBaseKey : MonoBehaviour, IPointerDownHandler
- {
- [SerializeField]
- private string m_Value;
- public virtual string Value {
- get {
- return m_Value;
- }
- set {
- m_Value = value;
- }
- }
-
- private SCKeyboardMono m_SCKeyboardMono;
- protected SCKeyboardMono SCKeyboardMono {
- get
- {
- if (m_SCKeyboardMono == null)
- {
- m_SCKeyboardMono = GetComponentInParent<SCKeyboardMono>();
- }
- return m_SCKeyboardMono;
- }
- }
- public Action OnKeyClickEvent;
- Button button;
- UnityAction call;
- protected virtual void Awake()
- {
- RegistKey();
- }
- protected virtual void OnEnable()
- {
- Init();
- }
- protected virtual void OnDisable()
- {
- }
- protected virtual void Start()
- {
-
- }
- protected virtual void OnDestroy()
- {
- UnRegistKey();
- }
- public virtual void Init()
- {
- }
- protected virtual void RegistKey()
- {
- if (button == null) button = this.GetComponent<Button>();
- if (call == null) call = OnKeyClick;
- if (button)
- {
- button.onClick.AddListener(call);
- }
- }
- protected virtual void UnRegistKey()
- {
- if (button)
- {
- button.onClick.RemoveListener(call);
- button = null;
- call = null;
- }
- }
- protected virtual void OnKeyClick()
- {
- OnKeyClickEvent?.Invoke();
- }
- protected virtual void OnKeyClick(BaseEventData eventData) { OnKeyClickEvent?.Invoke(); }
- public virtual void OnPointerDown(PointerEventData eventData)
- {
- SCKeyboardMono.OnPointerDown?.Invoke(eventData);
- }
- }
- }
|