NxrControllerHelper.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. namespace Nxr.Internal
  3. {
  4. public class NxrControllerHelper
  5. {
  6. public static int RIGHT_HAND_MODE = 0;
  7. public static int LEFT_HAND_MODE = 1;
  8. public static int HandMode3DOF
  9. {
  10. set; get;
  11. }
  12. public static bool Is3DofControllerConnected
  13. {
  14. set;get;
  15. }
  16. public static bool IsLeftNoloControllerConnected
  17. {
  18. set;get;
  19. }
  20. public static bool IsRightNoloControllerConnected
  21. {
  22. set; get;
  23. }
  24. public static int ControllerType
  25. {
  26. set;get;
  27. }
  28. public static void Reset()
  29. {
  30. HandMode3DOF = RIGHT_HAND_MODE;
  31. Is3DofControllerConnected = false;
  32. IsLeftNoloControllerConnected = false;
  33. IsRightNoloControllerConnected = false;
  34. ControllerRaycastObject = null;
  35. ControllerType = (int)NxrInstantNativeApi.NibiruControllerId.NONE;
  36. }
  37. public static void InitController(int type)
  38. {
  39. ControllerType = type;
  40. switch (type)
  41. {
  42. case (int)NxrInstantNativeApi.NibiruControllerId.NOLO:
  43. IsLeftNoloControllerConnected = true;
  44. IsRightNoloControllerConnected = true;
  45. CreateNoloController();
  46. break;
  47. case (int)NxrInstantNativeApi.NibiruControllerId.NORMAL_3DOF:
  48. Is3DofControllerConnected = true;
  49. HandMode3DOF = RIGHT_HAND_MODE;
  50. break;
  51. default:
  52. Is3DofControllerConnected = false;
  53. break;
  54. }
  55. }
  56. public static GameObject CreateNoloController()
  57. {
  58. GameObject obj = GameObject.Find("ControllerNOLO");
  59. if (obj != null)
  60. {
  61. return obj;
  62. }
  63. GameObject objPrefab = (GameObject)Resources.Load("Prefabs/ControllerNOLO");
  64. return (GameObject)GameObject.Instantiate(objPrefab, Vector3.zero, Quaternion.identity);
  65. }
  66. public static GameObject ControllerRaycastObject { set; get; }
  67. }
  68. }