NRTools.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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;
  12. using UnityEngine;
  13. /// <summary> A nr tools. </summary>
  14. public class NRTools
  15. {
  16. /// <summary> Full pathname of the persistent data file. </summary>
  17. private static string persistentDataPath;
  18. /// <summary> Initializes this object. </summary>
  19. public static void Init()
  20. {
  21. persistentDataPath = Application.persistentDataPath;
  22. }
  23. #region path utility
  24. /// <summary> Gets streaming assets path. </summary>
  25. /// <returns> The streaming assets path. </returns>
  26. public static string GetStreamingAssetsPath()
  27. {
  28. string path = Application.streamingAssetsPath;
  29. #if UNITY_EDITOR || UNITY_STANDALONE
  30. path = "file://" + Application.streamingAssetsPath + "/";
  31. #elif UNITY_IPHONE
  32. path = Application.dataPath +"/Raw/";
  33. #elif UNITY_ANDROID
  34. path ="jar:file://" + Application.dataPath + "!/assets/";
  35. #endif
  36. return path;
  37. }
  38. /// <summary> Gets sdcard path. </summary>
  39. /// <returns> The sdcard path. </returns>
  40. public static string GetSdcardPath()
  41. {
  42. string path = null;
  43. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  44. path = System.IO.Directory.GetParent(Application.dataPath).ToString() + "/";
  45. #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
  46. path = "file://" + System.IO.Directory.GetCurrentDirectory()+"/";
  47. #elif UNITY_ANDROID
  48. path ="file:///storage/emulated/0/";
  49. #endif
  50. return path;
  51. }
  52. /// <summary> Gets tracking image data generate path. </summary>
  53. /// <returns> The tracking image data generate path. </returns>
  54. public static string GetTrackingImageDataGenPath()
  55. {
  56. #if UNITY_EDITOR
  57. string path = Application.persistentDataPath + "/TrackingImageData/";
  58. #else
  59. string path = persistentDataPath + "/TrackingImageData/";
  60. #endif
  61. return path;
  62. }
  63. #endregion
  64. #region time stamp
  65. /// <summary> Gets time by m seconds. </summary>
  66. /// <param name="ms"> The milliseconds.</param>
  67. /// <returns> The time by m seconds. </returns>
  68. public static string GetTimeByMSeconds(long ms)
  69. {
  70. int s = (int)ms / 1000;
  71. int h = (int)(s / 3600);
  72. int m = (s % 3600) / 60;
  73. s = (s % 3600) % 60;
  74. return string.Format("{0}:{1}:{2}", h > 10 ? h.ToString() : "0" + h, m > 10 ? m.ToString() : "0" + m, s > 10 ? s.ToString() : "0" + s);
  75. }
  76. /// <summary> Gets time stamp. </summary>
  77. /// <returns> The time stamp. </returns>
  78. public static ulong GetTimeStamp()
  79. {
  80. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  81. return Convert.ToUInt64(ts.TotalMilliseconds);
  82. }
  83. /// <summary> Gets time stamp. </summary>
  84. /// <returns> The time stamp. </returns>
  85. public static ulong GetTimeStampNanos()
  86. {
  87. return GetTimeStamp() * 1000000;
  88. }
  89. #endregion
  90. }
  91. }