SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.0 KiB

4 years ago
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace ARLocation.Utils
  4. {
  5. public class Misc
  6. {
  7. public static bool IsARDevice()
  8. {
  9. return (
  10. Application.platform == RuntimePlatform.Android ||
  11. Application.platform == RuntimePlatform.IPhonePlayer
  12. );
  13. }
  14. public static float FloatListAverage(List<float> list)
  15. {
  16. var average = 0.0f;
  17. foreach (var value in list)
  18. {
  19. average += value;
  20. }
  21. return average / list.Count;
  22. }
  23. public static float GetNormalizedDegrees(float value)
  24. {
  25. if (value < 0)
  26. {
  27. return (360 + (value % 360));
  28. }
  29. return value % 360;
  30. }
  31. public static T FindAndGetComponent<T>(string name)
  32. {
  33. var gameObject = GameObject.Find(name);
  34. if (gameObject == null)
  35. {
  36. return default(T);
  37. }
  38. return gameObject.GetComponent<T>();
  39. }
  40. public static T FindAndGetComponentAndLogError<T>(string name, string message)
  41. {
  42. var result = FindAndGetComponent<T>(name);
  43. if (EqualityComparer<T>.Default.Equals(result, default(T)))
  44. {
  45. Debug.LogError(message);
  46. }
  47. return result;
  48. }
  49. public static GameObject FindAndLogError(string name, string message)
  50. {
  51. var go = GameObject.Find(name);
  52. if (go == null)
  53. {
  54. Debug.LogError(message);
  55. }
  56. return go;
  57. }
  58. public static Spline BuildSpline(SplineType type, Vector3[] points, int n, float alpha)
  59. {
  60. if (type == SplineType.CatmullromSpline)
  61. {
  62. return new CatmullRomSpline(points, n, alpha);
  63. }
  64. else
  65. {
  66. return new LinearSpline(points);
  67. }
  68. }
  69. public static void SetActiveOnAllChildren(GameObject go, bool value)
  70. {
  71. foreach (Transform child in go.transform)
  72. {
  73. child.gameObject.SetActive(value);
  74. }
  75. }
  76. public static void SetGameObjectVisible(GameObject go, bool value)
  77. {
  78. var meshRenderer = go.GetComponent<MeshRenderer>();
  79. var skinnedMeshRenderer = go.GetComponent<SkinnedMeshRenderer>();
  80. if (meshRenderer)
  81. {
  82. meshRenderer.enabled = value;
  83. }
  84. if (skinnedMeshRenderer)
  85. {
  86. skinnedMeshRenderer.enabled = value;
  87. }
  88. SetActiveOnAllChildren(go, value);
  89. }
  90. public static void HideGameObject(GameObject go)
  91. {
  92. SetGameObjectVisible(go, false);
  93. }
  94. public static void ShowGameObject(GameObject go)
  95. {
  96. SetGameObjectVisible(go, true);
  97. }
  98. }
  99. }