ModelHand.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand
  6. {
  7. public class ModelHand : ModelBase {
  8. public InputDeviceHandPartUI inputDeviceHandPartUI {
  9. get {
  10. return inputDevicePartUIBase as InputDeviceHandPartUI;
  11. }
  12. }
  13. [Tooltip("All Vaild HandModel")]
  14. [SerializeField]
  15. private List<AbstractHandModel> mAllHandModelList;
  16. protected List<AbstractHandModel> AllHandModelList {
  17. get {
  18. if (mAllHandModelList.Count == 0) {
  19. mAllHandModelList = new List<AbstractHandModel>(GetComponentsInChildren<AbstractHandModel>(true)) ;
  20. }
  21. return mAllHandModelList;
  22. }
  23. }
  24. /// <summary>
  25. /// which HandModel Used For PointerModuel
  26. /// </summary>
  27. private AbstractHandModel mActiveHandModel;
  28. public AbstractHandModel ActiveHandModel {
  29. get {
  30. if (mActiveHandModel == null) {
  31. if (VisualHandModelList==null || VisualHandModelList.Count == 0) {
  32. //DebugMy.LogError("No Visual HandModel",this);
  33. return null;
  34. }
  35. foreach (var handmodel in VisualHandModelList) {
  36. if (handmodel.handModelType == PointerHand) {
  37. mActiveHandModel = handmodel;
  38. DebugMy.Log("PointerHand:"+ handmodel.handModelType, this,true);
  39. break;
  40. }
  41. }
  42. if (mActiveHandModel == null) {
  43. mActiveHandModel = VisualHandModelList[0];
  44. DebugMy.Log("No Find PointerHand, PointerHand" + mActiveHandModel.handModelType, this, true);
  45. }
  46. }
  47. return mActiveHandModel;
  48. }
  49. }
  50. [Tooltip("All Vaild Visual HandModel")]
  51. public List<AbstractHandModel> VisualHandModelList;
  52. /// <summary>
  53. /// Which HandModel Used For PointerModule
  54. /// </summary>
  55. [Tooltip("Which HandModel Used For PointerModule")]
  56. public HandModelType PointerHand = HandModelType.EffectHand;
  57. public FingerUI[] fingerUI {
  58. get {
  59. if (ActiveHandModel != null) {
  60. return ActiveHandModel.fingerUI;
  61. }
  62. return null;
  63. }
  64. }
  65. public override void OnSCStart() {
  66. base.OnSCStart();
  67. if (VisualHandModelList.Count == 0) {
  68. VisualHandModelList = new List<AbstractHandModel>();
  69. foreach (var handmodel in AllHandModelList) {
  70. AddModule(handmodel);
  71. if (handmodel.handModelType == HandModelType.EffectHand && inputDeviceHandPartUI.inputDeviceHandPart.EnableEffectHandModel) {
  72. VisualHandModelList.Add(handmodel);
  73. } else if (handmodel.handModelType == HandModelType.CubeHand && inputDeviceHandPartUI.inputDeviceHandPart.EnableCubeHandModel) {
  74. VisualHandModelList.Add(handmodel);
  75. }
  76. }
  77. }
  78. foreach (var handmodel in VisualHandModelList) {
  79. handmodel.ModuleStart();
  80. }
  81. }
  82. void OnDrawGizmos()
  83. {
  84. if (Application.isPlaying)
  85. {
  86. Gizmos.color = Color.black * 0.3f;
  87. Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition, 0.01f);
  88. Gizmos.color = Color.black * 0.2f;
  89. Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.normal * 0.05f, 0.01f);
  90. Gizmos.color = Color.black * 0.2f;
  91. Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.right * 0.05f, 0.01f);
  92. }
  93. }
  94. }
  95. }