InputDeviceBT3DofPartStatus.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.InputDeviceGC.BT3Dof {
  8. public class InputDeviceBT3DofPartStatus : InputDeviceGCPartStatus {
  9. public InputDeviceBT3DofPart inputDeviceBT3DofPart;
  10. public InputDeviceBT3DofPartStatus(InputDeviceBT3DofPart inputDeviceBT3DofPart) : base(inputDeviceBT3DofPart) {
  11. this.inputDeviceBT3DofPart = inputDeviceBT3DofPart;
  12. }
  13. const string K02Name = "K02";
  14. const string K07Name = "K07";
  15. public override void OnSCStart() {
  16. base.OnSCStart();
  17. if(Application.platform != RuntimePlatform.Android) {
  18. bool isConnected = false;
  19. if(inputDeviceGCPart.inputDeviceGC.SimulateInEditorMode == true) {
  20. if(inputDeviceGCPart.PartType == InputDevicePartType.GCOne) {
  21. isConnected = inputDeviceBT3DofPart.inputDeviceBT3Dof.OneGCActive;
  22. if(isConnected) {
  23. InputDataBT3Dof.StatusDataList.Add(new InputDataBT3Dof.StatusData() { isConnected = isConnected, deviceID = (int)BT3DofIndex.BT3DofOne });
  24. }
  25. } else if(inputDeviceGCPart.PartType == InputDevicePartType.GCTwo) {
  26. isConnected = inputDeviceBT3DofPart.inputDeviceBT3Dof.TwoGCActive;
  27. if(isConnected) {
  28. InputDataBT3Dof.StatusDataList.Add(new InputDataBT3Dof.StatusData() { isConnected = isConnected, deviceID = (int)BT3DofIndex.BT3DofTwo });
  29. }
  30. }
  31. }
  32. } else if(Application.platform == RuntimePlatform.Android) {
  33. if(inputDeviceGCPart.PartType == InputDevicePartType.GCOne) {
  34. bool isConnected = AndroidPluginBase.ObjectFunctionCall<int>(AndroidPluginBT3Dof.BT3DofManager, "isHandShankConnected", 0) != 0 ? true : false;
  35. if(isConnected) {
  36. InputDataBT3Dof.StatusDataList.Add(new InputDataBT3Dof.StatusData() { isConnected = isConnected, deviceID = (int)BT3DofIndex.BT3DofOne });
  37. }
  38. } else if(inputDeviceGCPart.PartType == InputDevicePartType.GCTwo) {
  39. bool isConnected = AndroidPluginBase.ObjectFunctionCall<int>(AndroidPluginBT3Dof.BT3DofManager, "isHandShankConnected", 1) != 0 ? true : false;
  40. if(isConnected) {
  41. InputDataBT3Dof.StatusDataList.Add(new InputDataBT3Dof.StatusData() { isConnected = isConnected, deviceID = (int)BT3DofIndex.BT3DofTwo });
  42. }
  43. }
  44. }
  45. }
  46. public override void OnSCLateUpdate() {
  47. base.OnSCLateUpdate();
  48. if(InputDataBT3Dof.StatusDataList.Count > 0) {
  49. if((inputDeviceGCPart.PartType == InputDevicePartType.GCOne && InputDataBT3Dof.StatusDataList[0].deviceID == (int)BT3DofIndex.BT3DofOne)
  50. ||
  51. (inputDeviceGCPart.PartType == InputDevicePartType.GCTwo && InputDataBT3Dof.StatusDataList[0].deviceID == (int)BT3DofIndex.BT3DofTwo)) {
  52. inputDeviceGCPart.inputDataGC.isConnected = InputDataBT3Dof.StatusDataList[0].isConnected;
  53. InputDataBT3Dof.StatusDataList.RemoveAt(0);
  54. DebugMy.Log(inputDeviceGCPart.PartType + " StatusChange:" + inputDeviceGCPart.inputDataGC.isConnected, this, true);
  55. StatusChangeCallBack();
  56. }
  57. }
  58. }
  59. protected void StatusChangeCallBack() {
  60. if(inputDeviceGCPart.inputDataGC.isConnected && inputDeviceGCPart.inputDataBase.isVaild == false) {
  61. inputDeviceGCPart.inputDataBase.isVaild = UpdateDeviceInfo(inputDeviceBT3DofPart);
  62. } else {
  63. inputDeviceGCPart.inputDataBase.isVaild = UpdateDeviceInfo(inputDeviceBT3DofPart, true);
  64. }
  65. }
  66. protected virtual bool UpdateDeviceInfo(InputDeviceBT3DofPart part, bool isClear = false) {
  67. if(isClear == true) {
  68. part.inputDataGC.GCType = GCType.Null;
  69. part.inputDataGC.GCName = "";
  70. part.inputDataGC.SoftVesion = -1;
  71. DebugMy.LogError("UpdateDeviceInfo Clear!", this);
  72. return false;
  73. }
  74. BT3DofIndex index = part.inputDataBT3Dof.index;
  75. if(index != BT3DofIndex.BT3DofOne && index != BT3DofIndex.BT3DofTwo) {
  76. DebugMy.LogError("UpdateDeviceInfo Error:" + index, this);
  77. return false;
  78. }
  79. try {
  80. string typeFlag = AndroidPluginBase.ObjectFunctionCall<string>(AndroidPluginBT3Dof.BT3DofManager, "getManufacturerModel", (int)index);
  81. if(K07Name == typeFlag) {
  82. part.inputDataGC.GCType = GCType.K07;
  83. } else if(K02Name == typeFlag) {
  84. part.inputDataGC.GCType = GCType.K02;
  85. } else {
  86. part.inputDataGC.GCType = GCType.K02;
  87. }
  88. if(part.inputDataGC.GCType != GCType.K02 && part.inputDataGC.GCType != GCType.K07) {
  89. DebugMy.LogError("UpdateDeviceInfo Error:" + part.inputDataGC.GCType, this);
  90. return false;
  91. }
  92. part.inputDataGC.GCName = part.inputDataGC.GCType.ToString();
  93. part.inputDataGC.SoftVesion = 0;
  94. DebugMy.Log("UpdateDeviceInfo : "
  95. + " isConnected: " + part.inputDataGC.isConnected
  96. + " GCName: " + part.inputDataGC.GCName
  97. + " SoftVesion: " + part.inputDataGC.SoftVesion
  98. , this, true);
  99. } catch(Exception e) {
  100. Debug.Log(e);
  101. }
  102. return true;
  103. }
  104. }
  105. }