InputDevicePartUIBase.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. namespace SC.XR.Unity.Module_InputSystem {
  8. public abstract class InputDevicePartUIBase : SCModuleMono {
  9. /// <summary>
  10. /// 输入设备Part所属Device模块
  11. /// </summary>;
  12. InputDevicePartBase _inputDevicePartBase;
  13. public InputDevicePartBase inputDevicePartBase {
  14. get {
  15. if(_inputDevicePartBase == null) {
  16. _inputDevicePartBase = GetComponentInParent<InputDevicePartBase>();
  17. }
  18. return _inputDevicePartBase;
  19. }
  20. }
  21. ModelBase _modelBase;
  22. public ModelBase modelBase {
  23. get {
  24. if(_modelBase == null) {
  25. _modelBase = GetComponentInChildren<ModelBase>(true);
  26. }
  27. return _modelBase;
  28. }
  29. protected set {
  30. _modelBase = value;
  31. }
  32. }
  33. #region Module Behavior
  34. public override void OnSCAwake() {
  35. base.OnSCAwake();
  36. AddModule(modelBase);
  37. }
  38. public override void OnSCStart() {
  39. base.OnSCStart();
  40. modelBase?.ModuleStart();
  41. }
  42. public override void OnSCLateUpdate() {
  43. UpdateTransform();
  44. base.OnSCLateUpdate();
  45. }
  46. public override void OnSCDestroy() {
  47. base.OnSCDestroy();
  48. _modelBase = null;
  49. _inputDevicePartBase = null;
  50. }
  51. #endregion
  52. public virtual void UpdateTransform() {
  53. transform.position = inputDevicePartBase.inputDataBase.position;
  54. transform.rotation = inputDevicePartBase.inputDataBase.rotation;
  55. }
  56. }
  57. }