InputDataBase.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. namespace SC.XR.Unity.Module_InputSystem {
  9. public abstract class InputDataBase : SCModule {
  10. public InputDevicePartBase inputDevicePartBase;
  11. public InputDataBase(InputDevicePartBase inputDevicePartBase) {
  12. this.inputDevicePartBase = inputDevicePartBase;
  13. }
  14. /// <summary>
  15. /// Key数据
  16. /// </summary>
  17. public InputKeys inputKeys;
  18. public InputKeyCode EnterKeyAlias = InputKeyCode.Trigger;
  19. public InputKeyCode CancelKeyAlias = InputKeyCode.Cancel;
  20. public InputKeyCode CalibrationKeyAlias = InputKeyCode.Function;
  21. bool _isVaild = false;
  22. /// <summary>
  23. /// 数据是否有效
  24. /// </summary>
  25. public bool isVaild {
  26. get {
  27. return _isVaild;
  28. }
  29. set {
  30. if(value != _isVaild) {
  31. _isVaild = value;
  32. DeviceVaildChanged(value);
  33. }
  34. }
  35. }
  36. /// <summary>
  37. /// 事件信息
  38. /// </summary>
  39. public SCPointEventData SCPointEventData;
  40. /// <summary>
  41. /// Posture,the inputDevice 6Dof Posture in the world
  42. /// </summary>
  43. public Vector3 position;
  44. public Quaternion rotation;
  45. #region Module Behavior
  46. public override void OnSCAwake() {
  47. base.OnSCAwake();
  48. isVaild = false;
  49. position = Vector3.zero;
  50. rotation = Quaternion.identity;
  51. SCPointEventData = new SCPointEventData(inputDevicePartBase, EventSystem.current);
  52. AddModule(inputKeys = new InputKeys(this));
  53. }
  54. public override void OnSCStart() {
  55. base.OnSCStart();
  56. inputKeys.ModuleStart();
  57. }
  58. public override void OnSCDisable() {
  59. base.OnSCDisable();
  60. isVaild = false;
  61. position = Vector3.zero;
  62. rotation = Quaternion.identity;
  63. SCPointEventData.Clear();
  64. }
  65. public override void OnSCDestroy() {
  66. base.OnSCDestroy();
  67. inputKeys = null;
  68. SCPointEventData = null;
  69. inputDevicePartBase = null;
  70. }
  71. #endregion
  72. void DeviceVaildChanged(bool newVaild) {
  73. inputKeys.VaildChanged();
  74. }
  75. }
  76. }