ControllerVisualFactory.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. /// <summary> A controller visual factory. </summary>
  15. internal static class ControllerVisualFactory
  16. {
  17. /// <summary> Creates controller visual object. </summary>
  18. /// <param name="visualType"> Type of the visual.</param>
  19. /// <returns> The new controller visual object. </returns>
  20. public static GameObject CreateControllerVisualObject(ControllerVisualType visualType)
  21. {
  22. GameObject visualObj = null;
  23. string prefabPath = "";
  24. string folderPath = "ControllerVisuals/";
  25. switch (visualType)
  26. {
  27. case ControllerVisualType.None:
  28. return null;
  29. case ControllerVisualType.NrealLight:
  30. prefabPath = folderPath + "nreal_light_controller_visual";
  31. break;
  32. case ControllerVisualType.Phone:
  33. prefabPath = folderPath + "phone_controller_visual";
  34. break;
  35. default:
  36. NRDebugger.Error("Can not find controller visual for: " + visualType + ", set to default visual");
  37. prefabPath = folderPath + "nreal_light_controller_visual";
  38. break;
  39. }
  40. if (!string.IsNullOrEmpty(prefabPath))
  41. {
  42. GameObject controllerPrefab = Resources.Load<GameObject>(prefabPath);
  43. if (controllerPrefab)
  44. visualObj = GameObject.Instantiate(controllerPrefab);
  45. }
  46. if (visualObj == null)
  47. NRDebugger.Error("Create controller visual failed, prefab path:" + prefabPath);
  48. return visualObj;
  49. }
  50. /// <summary> Gets default visual type. </summary>
  51. /// <param name="controllerType"> Type of the controller.</param>
  52. /// <returns> The default visual type. </returns>
  53. public static ControllerVisualType GetDefaultVisualType(ControllerType controllerType)
  54. {
  55. switch (controllerType)
  56. {
  57. case ControllerType.CONTROLLER_TYPE_HAND:
  58. return ControllerVisualType.None;
  59. case ControllerType.CONTROLLER_TYPE_PHONE:
  60. return ControllerVisualType.Phone;
  61. default:
  62. return ControllerVisualType.NrealLight;
  63. }
  64. }
  65. }
  66. }