ShowSystemInfo.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UnityUtils;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Text;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. using UnityEngine.UI;
  10. namespace OpenCVForUnityExample
  11. {
  12. public class ShowSystemInfo : MonoBehaviour
  13. {
  14. public Text systemInfoText;
  15. public InputField systemInfoInputField;
  16. private const string ASSET_NAME = "OpenCVForUnity";
  17. // Use this for initialization
  18. void Start()
  19. {
  20. StringBuilder sb = new StringBuilder();
  21. sb.Append("###### Build Info ######\n");
  22. IDictionary<string, string> buildInfo = GetBuildInfo();
  23. foreach (string key in buildInfo.Keys)
  24. {
  25. sb.Append(key).Append(" = ").Append(buildInfo[key]).Append("\n");
  26. }
  27. sb.Append("\n");
  28. #if UNITY_IOS || (UNITY_ANDROID && UNITY_2018_3_OR_NEWER)
  29. sb.Append("###### Device Info ######\n");
  30. IDictionary<string, string> deviceInfo = GetDeviceInfo();
  31. foreach (string key in deviceInfo.Keys)
  32. {
  33. sb.Append(key).Append(" = ").Append(deviceInfo[key]).Append("\n");
  34. }
  35. sb.Append("\n");
  36. #endif
  37. sb.Append("###### System Info ######\n");
  38. IDictionary<string, string> systemInfo = GetSystemInfo();
  39. foreach (string key in systemInfo.Keys)
  40. {
  41. sb.Append(key).Append(" = ").Append(systemInfo[key]).Append("\n");
  42. }
  43. sb.Append("#########################\n");
  44. systemInfoText.text = systemInfoInputField.text = sb.ToString();
  45. Debug.Log(sb.ToString());
  46. }
  47. // Update is called once per frame
  48. void Update()
  49. {
  50. }
  51. public Dictionary<string, string> GetBuildInfo()
  52. {
  53. Dictionary<string, string> dict = new Dictionary<string, string>();
  54. dict.Add(ASSET_NAME + " version", Core.NATIVE_LIBRARY_NAME + " " + Utils.getVersion() + " (" + Core.VERSION + ")");
  55. dict.Add("Build Unity version", Application.unityVersion);
  56. #if UNITY_EDITOR
  57. dict.Add("Build target", "Editor");
  58. #elif UNITY_STANDALONE_WIN
  59. dict.Add("Build target", "Windows");
  60. #elif UNITY_STANDALONE_OSX
  61. dict.Add("Build target", "Mac OSX");
  62. #elif UNITY_STANDALONE_LINUX
  63. dict.Add("Build target", "Linux");
  64. #elif UNITY_ANDROID
  65. dict.Add("Build target", "Android");
  66. #elif UNITY_IOS
  67. dict.Add("Build target", "iOS");
  68. #elif UNITY_WSA
  69. dict.Add("Build target", "WSA");
  70. #elif UNITY_WEBGL
  71. dict.Add("Build target", "WebGL");
  72. #else
  73. dict.Add("Build target", "");
  74. #endif
  75. #if ENABLE_MONO
  76. dict.Add("Scripting backend", "Mono");
  77. #elif ENABLE_IL2CPP
  78. dict.Add("Scripting backend", "IL2CPP");
  79. #elif ENABLE_DOTNET
  80. dict.Add("Scripting backend", ".NET");
  81. #else
  82. dict.Add("Scripting backend", "");
  83. #endif
  84. #if OPENCV_USE_UNSAFE_CODE
  85. dict.Add("Allow 'unsafe' Code", "Enabled");
  86. #else
  87. dict.Add("Allow 'unsafe' Code", "Disabled");
  88. #endif
  89. return dict;
  90. }
  91. public Dictionary<string, string> GetDeviceInfo()
  92. {
  93. Dictionary<string, string> dict = new Dictionary<string, string>();
  94. #if UNITY_IOS
  95. dict.Add("iOS.Device.generation", UnityEngine.iOS.Device.generation.ToString());
  96. dict.Add("iOS.Device.systemVersion", UnityEngine.iOS.Device.systemVersion.ToString());
  97. #endif
  98. #if UNITY_IOS && UNITY_2018_1_OR_NEWER
  99. dict.Add("UserAuthorization.WebCam", Application.HasUserAuthorization(UserAuthorization.WebCam).ToString());
  100. dict.Add("UserAuthorization.Microphone", Application.HasUserAuthorization(UserAuthorization.Microphone).ToString());
  101. #endif
  102. #if UNITY_ANDROID && UNITY_2018_3_OR_NEWER
  103. dict.Add("Android.Permission.Camera", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.Camera).ToString());
  104. dict.Add("Android.Permission.CoarseLocation", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.CoarseLocation).ToString());
  105. dict.Add("Android.Permission.ExternalStorageRead", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.ExternalStorageRead).ToString());
  106. dict.Add("Android.Permission.ExternalStorageWrite", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.ExternalStorageWrite).ToString());
  107. dict.Add("Android.Permission.FineLocation", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.FineLocation).ToString());
  108. dict.Add("Android.Permission.Microphone", UnityEngine.Android.Permission.HasUserAuthorizedPermission(UnityEngine.Android.Permission.Microphone).ToString());
  109. #endif
  110. return dict;
  111. }
  112. /// SystemInfo Class Propertys
  113. public SortedDictionary<string, string> GetSystemInfo()
  114. {
  115. SortedDictionary<string, string> dict = new SortedDictionary<string, string>();
  116. Type type = typeof(SystemInfo);
  117. MemberInfo[] members = type.GetMembers(
  118. BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  119. foreach (MemberInfo mb in members)
  120. {
  121. try
  122. {
  123. if (mb.MemberType == MemberTypes.Property)
  124. {
  125. if (mb.Name == "deviceUniqueIdentifier")
  126. {
  127. dict.Add(mb.Name, "xxxxxxxxxxxxxxxxxxxxxxxx");
  128. continue;
  129. }
  130. PropertyInfo pr = type.GetProperty(mb.Name);
  131. if (pr != null)
  132. {
  133. object resobj = pr.GetValue(type, null);
  134. dict.Add(mb.Name, resobj.ToString());
  135. }
  136. else
  137. {
  138. dict.Add(mb.Name, "");
  139. }
  140. }
  141. }
  142. catch (Exception e)
  143. {
  144. Debug.Log("Exception: " + e);
  145. }
  146. }
  147. return dict;
  148. }
  149. public void OnBackButtonClick()
  150. {
  151. SceneManager.LoadScene("OpenCVForUnityExample");
  152. }
  153. }
  154. }