InputDataBase.cs 2.3 KB

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