InputDataBase.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 AnotherEnterKeyAlias = InputKeyCode.NULL;
  20. public InputKeyCode ThreeEnterKeyAlias = InputKeyCode.NULL;
  21. public InputKeyCode CancelKeyAlias = InputKeyCode.Cancel;
  22. public InputKeyCode CalibrationKeyAlias = InputKeyCode.Function;
  23. bool _isVaild = false;
  24. /// <summary>
  25. /// 数据是否有效
  26. /// </summary>
  27. public bool isVaild {
  28. get {
  29. return _isVaild;
  30. }
  31. set {
  32. if(value != _isVaild) {
  33. _isVaild = value;
  34. DeviceVaildChanged(value);
  35. }
  36. }
  37. }
  38. /// <summary>
  39. /// 事件信息
  40. /// </summary>
  41. public SCPointEventData SCPointEventData;
  42. /// <summary>
  43. /// Posture,the inputDevice 6Dof Posture in the world
  44. /// </summary>
  45. public Vector3 position;
  46. public Quaternion rotation;
  47. #region Module Behavior
  48. public override void OnSCAwake() {
  49. base.OnSCAwake();
  50. isVaild = false;
  51. position = Vector3.zero;
  52. rotation = Quaternion.identity;
  53. SCPointEventData = new SCPointEventData(inputDevicePartBase, EventSystem.current);
  54. AddModule(inputKeys = new InputKeys(this));
  55. }
  56. public override void OnSCStart() {
  57. base.OnSCStart();
  58. inputKeys.ModuleStart();
  59. }
  60. public override void OnSCDisable() {
  61. base.OnSCDisable();
  62. isVaild = false;
  63. SCPointEventData.Clear();
  64. }
  65. public override void OnSCDestroy() {
  66. base.OnSCDestroy();
  67. position = Vector3.zero;
  68. rotation = Quaternion.identity;
  69. inputKeys = null;
  70. SCPointEventData = null;
  71. inputDevicePartBase = null;
  72. }
  73. #endregion
  74. void DeviceVaildChanged(bool newVaild) {
  75. inputKeys.VaildChanged();
  76. }
  77. }
  78. }