ModelHand.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. public AbstractHandModel ActiveHandModel { get; private set; }
  25. private HandModelType currentHandModelType;
  26. public FingerUI[] fingerUI {
  27. get {
  28. if (ActiveHandModel != null) {
  29. return ActiveHandModel.fingerUI;
  30. }
  31. return null;
  32. }
  33. }
  34. public override void OnSCAwake() {
  35. base.OnSCAwake();
  36. foreach (var handmodel in AllHandModelList) {
  37. AddModule(handmodel);
  38. }
  39. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "HandModelType")) {
  40. System.Enum.TryParse<HandModelType>(API_Module_SDKConfiguration.GetString("Module_InputSystem", "HandModelType", "EffectHand"), false, out currentHandModelType);
  41. }
  42. DebugMy.Log("HandModelType:" + currentHandModelType, this, true);
  43. }
  44. public override void OnSCStart() {
  45. base.OnSCStart();
  46. HandModelChange(currentHandModelType);
  47. }
  48. public override void OnSCDisable() {
  49. base.OnSCDisable();
  50. ActiveHandModel = null;
  51. }
  52. public void HandModelChange(HandModelType type) {
  53. if (ActiveHandModel == null || type != ActiveHandModel.handModelType) {
  54. if (ActiveHandModel) {
  55. ActiveHandModel.ModuleStop();
  56. }
  57. foreach (var handmodel in AllHandModelList) {
  58. if (type == handmodel.handModelType) {
  59. handmodel.ModuleStart();
  60. ActiveHandModel = handmodel;
  61. currentHandModelType = type;
  62. }
  63. }
  64. }
  65. }
  66. //void OnDrawGizmos()
  67. //{
  68. // if (Application.isPlaying)
  69. // {
  70. // Gizmos.color = Color.black * 0.3f;
  71. // Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition, 0.01f);
  72. // Gizmos.color = Color.yellow * 1f;
  73. // Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.normal * 0.05f, 0.01f);
  74. // Gizmos.color = Color.blue * 1f;
  75. // Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.up * 0.05f, 0.01f);
  76. // Gizmos.color = Color.black * 0.2f;
  77. // Gizmos.DrawSphere(inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPartUI.inputDeviceHandPart.inputDataHand.handInfo.right * 0.05f, 0.01f);
  78. // }
  79. //}
  80. }
  81. }