InputDevicePartUIBase.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. //init position
  42. transform.position = Vector3.up * 10;
  43. }
  44. public override void OnSCLateUpdate() {
  45. UpdateTransform();
  46. base.OnSCLateUpdate();
  47. }
  48. public override void OnSCDestroy() {
  49. base.OnSCDestroy();
  50. _modelBase = null;
  51. _inputDevicePartBase = null;
  52. }
  53. #endregion
  54. public virtual void UpdateTransform() {
  55. transform.localPosition = inputDevicePartBase.inputDataBase.position;
  56. transform.localRotation = inputDevicePartBase.inputDataBase.rotation;
  57. }
  58. }
  59. }