PageRenderTime 26ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Assets/TBE_3Dception/Utilities/Editor/TBE_SetupDiagnose.cs

https://gitlab.com/netcell/NightOfShame
C# | 205 lines | 162 code | 32 blank | 11 comment | 19 complexity | 701351cdf7abf32b444e6094172bd393 MD5 | raw file
  1. /* Diagnose and setup 3Dception
  2. * Setup: creates 3Dception Global object, sets script execution order
  3. * Diagnose: Check if plugin paths are correct and if plugins exist. Also checks
  4. * if the native plugin and the unity plugin are compatible.
  5. *
  6. * Copyright (c) Two Big Ears Ltd., 2015
  7. * support@twobigears.com
  8. */
  9. using UnityEngine;
  10. using UnityEditor;
  11. using System.Collections;
  12. using System.IO;
  13. namespace TBE
  14. {
  15. namespace Utilities
  16. {
  17. public class TBE_SetupDiagnose : EditorWindow
  18. {
  19. string windows32Status = string.Empty;
  20. string windows64Status = string.Empty;
  21. string linux32Status = string.Empty;
  22. string linux64Status = string.Empty;
  23. string osxStatus = string.Empty;
  24. string iosStatus = string.Empty;
  25. string androidStatus = string.Empty;
  26. string versionStatus = string.Empty;
  27. bool toggleGlobalObject = true;
  28. bool toggleScriptExecOrder = true;
  29. static Vector2 windowSize = new Vector2 (300, 440);
  30. public static TBE_SetupDiagnose instance { get; private set; }
  31. [MenuItem ("3Dception/Setup And Diagnostics")]
  32. static void Init ()
  33. {
  34. // Get existing open window or if none, make a new one:
  35. instance = (TBE_SetupDiagnose)EditorWindow.GetWindow (typeof(TBE_SetupDiagnose));
  36. instance.ShowUtility ();
  37. instance.titleContent = new GUIContent("Setup/Diagnose");
  38. instance.minSize = windowSize;
  39. instance.maxSize = windowSize;
  40. }
  41. void OnGUI ()
  42. {
  43. EditorGUILayout.Space ();
  44. GUILayout.Label ("3Dception — Project Setup", EditorStyles.boldLabel);
  45. EditorGUILayout.LabelField ("Chose the options below and click on 'Setup Scene' to automatically setup your scene.\n\n" +
  46. "The 3Dception Global object includes an initialisation and environment components, for controlling global environment properties .\n\n" +
  47. "'Set Execution Order' ensures the various components for 3Dception are executed in the correct order.\n", EditorStyles.wordWrappedLabel);
  48. toggleGlobalObject = GUILayout.Toggle (toggleGlobalObject, "Create 3Dception Global & Environment Object");
  49. toggleScriptExecOrder = GUILayout.Toggle (toggleScriptExecOrder, "Set Execution Order");
  50. if(GUILayout.Button("Setup Scene"))
  51. {
  52. if (toggleGlobalObject)
  53. {
  54. createGlobalObject();
  55. }
  56. if (toggleScriptExecOrder)
  57. {
  58. setScriptExecOrderForAll();
  59. }
  60. }
  61. EditorGUILayout.Space ();
  62. EditorGUILayout.Space ();
  63. GUILayout.Label ("3Dception — Diagnostics", EditorStyles.boldLabel);
  64. EditorGUILayout.LabelField ("Click on 'Run Diagnostics' if you have upgraded Unity or 3Dception to a new version to check if everything is okay.", EditorStyles.wordWrappedLabel);
  65. if(GUILayout.Button("Run Diagnostics"))
  66. {
  67. checkPluginStructure();
  68. checkVersionMatch();
  69. }
  70. EditorGUILayout.HelpBox (windows32Status + "\n" +
  71. windows64Status + "\n" +
  72. osxStatus + "\n" +
  73. iosStatus + "\n" +
  74. androidStatus + "\n" +
  75. linux32Status + "\n" +
  76. linux64Status + "\n" +
  77. versionStatus
  78. , MessageType.None);
  79. }
  80. void checkPluginStructure()
  81. {
  82. string unityVersion = Application.unityVersion;
  83. bool isVersion5_2_OrLater = false;
  84. if (unityVersion.StartsWith("5") && !(unityVersion.StartsWith("5.1")))
  85. {
  86. isVersion5_2_OrLater = true;
  87. }
  88. if (isVersion5_2_OrLater)
  89. {
  90. checkExists("Assets/TBE_3Dception/Plugins/x86/AudioPlugin3Dception.dll", "Windows 32", out windows32Status);
  91. checkExists("Assets/TBE_3Dception/Plugins/x86_64/AudioPlugin3Dception.dll", "Windows 64", out windows64Status);
  92. checkExists("Assets/TBE_3Dception/Plugins/x86/libAudioPlugin3Dception.so", "Linux 32", out linux32Status);
  93. checkExists("Assets/TBE_3Dception/Plugins/x86_64/libAudioPlugin3Dception.so", "Linux 64", out linux64Status);
  94. checkExists("Assets/TBE_3Dception/Plugins/AudioPlugin3Dception.bundle/Contents/MacOS/AudioPlugin3Dception", "OSX", out osxStatus);
  95. checkExists("Assets/TBE_3Dception/Plugins/iOS/libAudioPlugin3Dception_iOS.a", "iOS", out iosStatus);
  96. checkExists("Assets/TBE_3Dception/Plugins/Android/armeabi-v7a/libAudioPlugin3Dception.so", "Android", out androidStatus);
  97. }
  98. else
  99. {
  100. androidStatus = "This 3Dception package is for use with Unity 5.2 and onwards. Please use a later version of Unity.";
  101. }
  102. }
  103. void tryDelete(string path)
  104. {
  105. bool deleted = FileUtil.DeleteFileOrDirectory(path);
  106. if (deleted) {
  107. Debug.Log ("3Dception Diagnostics: Deleted " + path);
  108. }
  109. else
  110. {
  111. //TODO: check if plugin has been deleted successfully or not
  112. }
  113. }
  114. void checkExists(string path, string platform, out string uiMessage)
  115. {
  116. if (File.Exists (path))
  117. {
  118. uiMessage = platform + ": Plugin Available";
  119. }
  120. else
  121. {
  122. uiMessage = platform + ": Plugin Unavailable";
  123. }
  124. }
  125. void checkVersionMatch()
  126. {
  127. string coreVersionString = TBE.Native.Engine.getVersionMajor () + "." + TBE.Native.Engine.getVersionMinor () + "." + TBE.Native.Engine.getVersionPatch ();
  128. if (coreVersionString.Equals (TBE.Constants.EXPECTED_CORE_VERSION))
  129. {
  130. versionStatus = "3Dception version is correct, all good!";
  131. }
  132. else
  133. {
  134. versionStatus = "3Dception version is incorrect, restart Unity and re-import the package";
  135. }
  136. }
  137. public static void createGlobalObject()
  138. {
  139. GameObject tbeGlobal = GameObject.Find ("3Dception Global");
  140. if (tbeGlobal != null)
  141. {
  142. DestroyImmediate (tbeGlobal);
  143. }
  144. if (tbeGlobal == null)
  145. {
  146. // Create 3Dception Global object with components
  147. tbeGlobal = new GameObject("3Dception Global");
  148. tbeGlobal.AddComponent<TBE.Components.TBE_Initialise>();
  149. tbeGlobal.AddComponent<TBE.Components.TBE_InitialiseRoomModelling>();
  150. tbeGlobal.AddComponent<TBE.Components.TBE_Environment>();
  151. }
  152. }
  153. void setScriptExecOrderForAll()
  154. {
  155. setScriptExecutionOrder(typeof(TBE.Components.TBE_Initialise).Name, -400);
  156. setScriptExecutionOrder(typeof(TBE.Components.TBE_InitialiseRoomModelling).Name, -300);
  157. setScriptExecutionOrder(typeof(TBE.Components.TBE_Environment).Name, -250);
  158. setScriptExecutionOrder(typeof(TBE.Components.TBE_RoomProperties).Name, -200);
  159. }
  160. void setScriptExecutionOrder(string className, int order)
  161. {
  162. foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
  163. {
  164. if (monoScript.name == className)
  165. {
  166. MonoImporter.SetExecutionOrder(monoScript, order);
  167. break;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }