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.

172 lines
5.1 KiB

  1. using UnityEditor;
  2. using UnityEngine;
  3. using System;
  4. using System.Collections;
  5. using UnityEngine.Networking;
  6. namespace AmplifyShaderEditor
  7. {
  8. [InitializeOnLoad]
  9. public class InvalidDataChecker
  10. {
  11. private static string[] m_invalidData = { "674ea7bed6b1cd94b8057074298096db", //"/Samples",
  12. "2738539936eacef409be91f148b2a4a0", //"/Resources",
  13. "c880e50f07f2be9499d414ac6f9f3a7a", //"/Templates",
  14. "563f992b9989cf547ac59bf748442c17"};//"/Textures"};
  15. //private static string m_ASEFolderPath;
  16. private static string m_invalidDataCollected = string.Empty;
  17. static InvalidDataChecker()
  18. {
  19. bool foundInvalidData = false;
  20. //m_ASEFolderPath = AssetDatabase.GUIDToAssetPath( IOUtils.ASEFolderGUID );
  21. int count = 0;
  22. for ( int i = 0; i < m_invalidData.Length; i++ )
  23. {
  24. //m_invalidData[ i ] = m_ASEFolderPath + m_invalidData[ i ];
  25. m_invalidData[ i ] = AssetDatabase.GUIDToAssetPath( m_invalidData[ i ] );
  26. if ( AssetDatabase.IsValidFolder( m_invalidData[ i ] ) )
  27. {
  28. foundInvalidData = true;
  29. m_invalidDataCollected += m_invalidData[ i ]+"\n";
  30. count += 1;
  31. }
  32. }
  33. if ( count < 5 )
  34. {
  35. for ( ; count < 5; count++ )
  36. {
  37. m_invalidDataCollected += "\n";
  38. }
  39. }
  40. if ( foundInvalidData )
  41. {
  42. InvalidDataPopUp window = ( InvalidDataPopUp ) EditorWindow.GetWindow( typeof( InvalidDataPopUp ), true, "Found Invalid Data" );
  43. window.minSize = new Vector2( 502, 265 );
  44. window.maxSize = new Vector2( 502, 265 );
  45. window.Show();
  46. }
  47. EditorApplication.update += Update;
  48. }
  49. static void Update()
  50. {
  51. EditorApplication.update -= Update;
  52. if( !EditorApplication.isPlayingOrWillChangePlaymode )
  53. {
  54. Preferences.ShowOption show = Preferences.ShowOption.Never;
  55. if( !EditorPrefs.HasKey( Preferences.PrefStartUp ) )
  56. {
  57. show = Preferences.ShowOption.Always;
  58. EditorPrefs.SetInt( Preferences.PrefStartUp, 0 );
  59. }
  60. else
  61. {
  62. if( Time.realtimeSinceStartup < 10 )
  63. {
  64. show = (Preferences.ShowOption) EditorPrefs.GetInt( Preferences.PrefStartUp, 0 );
  65. // check version here
  66. if( show == Preferences.ShowOption.OnNewVersion )
  67. {
  68. ASEStartScreen.StartBackgroundTask( StartRequest( ASEStartScreen.ChangelogURL, () =>
  69. {
  70. var changeLog = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
  71. if( changeLog != null )
  72. {
  73. if( changeLog.Version > VersionInfo.FullNumber )
  74. ASEStartScreen.Init();
  75. }
  76. } ) );
  77. }
  78. }
  79. }
  80. if( show == Preferences.ShowOption.Always )
  81. ASEStartScreen.Init();
  82. }
  83. }
  84. static UnityWebRequest www;
  85. static IEnumerator StartRequest( string url, Action success = null )
  86. {
  87. using( www = UnityWebRequest.Get( url ) )
  88. {
  89. #if UNITY_2017_2_OR_NEWER
  90. yield return www.SendWebRequest();
  91. #else
  92. yield return www.Send();
  93. #endif
  94. while( www.isDone == false )
  95. yield return null;
  96. if( success != null )
  97. success();
  98. }
  99. }
  100. public static void CleanInvalidData()
  101. {
  102. for ( int i = 0; i < m_invalidData.Length; i++ )
  103. {
  104. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] ) )
  105. {
  106. Debug.Log( "Removed invalid " + m_invalidData[ i ] );
  107. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] + ".meta" ) )
  108. {
  109. Debug.Log( "Removed invalid " + m_invalidData[ i ] + ".meta" );
  110. }
  111. }
  112. }
  113. AssetDatabase.Refresh();
  114. }
  115. public static string InvalidDataCollected { get { return m_invalidDataCollected; } }
  116. }
  117. public class InvalidDataPopUp : EditorWindow
  118. {
  119. private readonly GUIContent m_buttonContent = new GUIContent( "Remove Invalid Data" );
  120. private Vector2 m_scrollPosition = Vector2.zero;
  121. public void OnGUI()
  122. {
  123. GUILayout.BeginVertical();
  124. {
  125. GUIStyle labelStyle = new GUIStyle( EditorStyles.label );
  126. labelStyle.alignment = TextAnchor.MiddleCenter;
  127. labelStyle.wordWrap = true;
  128. GUILayout.Label( "\nAmplify Shader Editor " + VersionInfo.StaticToString(), labelStyle, GUILayout.ExpandWidth( true ) );
  129. GUILayout.Space( 5 );
  130. GUILayout.Label( "Invalid/Legacy Data was found on your previous ASE folder which needs to be removed in order for it to work correctly." , labelStyle, GUILayout.ExpandWidth( true ) );
  131. GUILayout.Space( 5 );
  132. GUILayout.Label( "Below are the detected files/folders which require to be removed.", labelStyle, GUILayout.ExpandWidth( true ) );
  133. GUILayout.Space( 5 );
  134. m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition ,GUILayout.Height(85));
  135. GUILayout.TextArea( InvalidDataChecker.InvalidDataCollected );
  136. GUILayout.EndScrollView();
  137. GUILayout.Label( "VERY IMPORTANT: If you have assets of yours inside these folders you need to move them to another location before hitting the button below or they will be PERMANENTLY DELETED", labelStyle, GUILayout.ExpandWidth( true ) );
  138. GUILayout.Space( 5 );
  139. GUILayout.BeginHorizontal();
  140. {
  141. GUILayout.Space( 151 );
  142. if ( GUILayout.Button( m_buttonContent, GUILayout.Width( 200 ) ) )
  143. {
  144. InvalidDataChecker.CleanInvalidData();
  145. Close();
  146. }
  147. }
  148. GUILayout.EndHorizontal();
  149. }
  150. GUILayout.EndVertical();
  151. }
  152. }
  153. }