Assignment for RMIT Mixed Reality in 2020
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.

182 lines
6.9 KiB

  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using System.Text;
  5. using UnityEditor;
  6. using UnityEditorInternal;
  7. using UnityEditorInternal.VR;
  8. using UnityEngine;
  9. namespace VRTK
  10. {
  11. public sealed class VRTK_SupportInfoWindow : EditorWindow
  12. {
  13. private const string Separator = " ";
  14. private readonly StringBuilder stringBuilder = new StringBuilder();
  15. private int section;
  16. private Vector2 scrollPosition;
  17. [MenuItem("Window/VRTK/Support Info")]
  18. public static void ShowWindow()
  19. {
  20. GetWindow<VRTK_SupportInfoWindow>(true, "VRTK Support Info").RefreshData();
  21. }
  22. private void OnGUI()
  23. {
  24. GUIContent buttonContent = new GUIContent("Copy to clipboard");
  25. minSize = Vector2.Max(minSize, GUI.skin.button.CalcSize(buttonContent) + new Vector2(10, 0));
  26. using (EditorGUILayout.ScrollViewScope scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition))
  27. {
  28. scrollPosition = scrollViewScope.scrollPosition;
  29. using (new EditorGUILayout.VerticalScope(EditorStyles.textArea))
  30. {
  31. EditorGUILayout.LabelField(
  32. stringBuilder.ToString(),
  33. new GUIStyle(EditorStyles.label) { wordWrap = true },
  34. GUILayout.ExpandHeight(true)
  35. );
  36. }
  37. }
  38. if (GUILayout.Button(buttonContent))
  39. {
  40. EditorGUIUtility.systemCopyBuffer = stringBuilder.ToString();
  41. }
  42. }
  43. private void RefreshData()
  44. {
  45. stringBuilder.Length = 0;
  46. Assembly editorAssembly = typeof(VRTK_SDKManagerEditor).Assembly;
  47. Assembly assembly = typeof(VRTK_SDKManager).Assembly;
  48. Append(
  49. "Versions",
  50. () =>
  51. {
  52. Append("Unity", InternalEditorUtility.GetFullUnityVersion());
  53. Append("VRTK", VRTK_Defines.CurrentVersion + " (may not be correct if source is GitHub)");
  54. Type steamVRUpdateType = editorAssembly.GetType("SteamVR_Update");
  55. if (steamVRUpdateType != null)
  56. {
  57. FieldInfo currentVersionField = steamVRUpdateType.GetField("currentVersion", BindingFlags.NonPublic | BindingFlags.Static);
  58. if (currentVersionField != null)
  59. {
  60. string currentVersion = (string)currentVersionField.GetValue(null);
  61. Append("SteamVR", currentVersion);
  62. }
  63. }
  64. Type ovrPluginType = assembly.GetType("OVRPlugin");
  65. if (ovrPluginType != null)
  66. {
  67. Append(
  68. "OVRPlugin (Oculus Utilities)",
  69. () =>
  70. {
  71. FieldInfo wrapperVersionField = ovrPluginType.GetField("wrapperVersion", BindingFlags.Public | BindingFlags.Static);
  72. if (wrapperVersionField != null)
  73. {
  74. Version wrapperVersion = (Version)wrapperVersionField.GetValue(null);
  75. Append("wrapperVersion", wrapperVersion);
  76. }
  77. PropertyInfo versionField = ovrPluginType.GetProperty("version", BindingFlags.Public | BindingFlags.Static);
  78. if (versionField != null)
  79. {
  80. Version version = (Version)versionField.GetGetMethod().Invoke(null, null);
  81. Append("version", version);
  82. }
  83. PropertyInfo nativeSDKVersionField = ovrPluginType.GetProperty("nativeSDKVersion", BindingFlags.Public | BindingFlags.Static);
  84. if (nativeSDKVersionField != null)
  85. {
  86. Version nativeSDKVersion = (Version)nativeSDKVersionField.GetGetMethod().Invoke(null, null);
  87. Append("nativeSDKVersion", nativeSDKVersion);
  88. }
  89. }
  90. );
  91. }
  92. }
  93. );
  94. Append(
  95. "VR Settings",
  96. () =>
  97. {
  98. foreach (BuildTargetGroup targetGroup in VRTK_SharedMethods.GetValidBuildTargetGroups())
  99. {
  100. bool isVREnabled;
  101. #if UNITY_5_5_OR_NEWER
  102. isVREnabled = VREditor.GetVREnabledOnTargetGroup(targetGroup);
  103. #else
  104. isVREnabled = VREditor.GetVREnabled(targetGroup);
  105. #endif
  106. if (!isVREnabled)
  107. {
  108. continue;
  109. }
  110. string[] vrEnabledDevices;
  111. #if UNITY_5_5_OR_NEWER
  112. vrEnabledDevices = VREditor.GetVREnabledDevicesOnTargetGroup(targetGroup);
  113. #else
  114. vrEnabledDevices = VREditor.GetVREnabledDevices(targetGroup);
  115. #endif
  116. Append(targetGroup, string.Join(", ", vrEnabledDevices));
  117. }
  118. }
  119. );
  120. Append(
  121. "Scripting Define Symbols",
  122. () =>
  123. {
  124. foreach (BuildTargetGroup targetGroup in VRTK_SharedMethods.GetValidBuildTargetGroups())
  125. {
  126. string symbols = string.Join(
  127. ";",
  128. PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup)
  129. .Split(';')
  130. .Where(symbol => !symbol.StartsWith(VRTK_Defines.VersionScriptingDefineSymbolPrefix, StringComparison.Ordinal))
  131. .ToArray());
  132. if (!string.IsNullOrEmpty(symbols))
  133. {
  134. Append(targetGroup, symbols);
  135. }
  136. }
  137. }
  138. );
  139. stringBuilder.Length--;
  140. }
  141. private void Append(string value, Action sectionContentAction = null)
  142. {
  143. for (int index = 0; index < section; index++)
  144. {
  145. stringBuilder.Append(Separator);
  146. }
  147. stringBuilder.AppendLine(value);
  148. if (sectionContentAction != null)
  149. {
  150. section++;
  151. sectionContentAction();
  152. section--;
  153. }
  154. }
  155. private void Append(object tag, object value)
  156. {
  157. Append(string.Format("{0}: {1}", tag, value));
  158. }
  159. }
  160. }