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.

110 lines
3.6 KiB

  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace AmplifyShaderEditor
  4. {
  5. [InitializeOnLoad]
  6. public class InvalidDataChecker
  7. {
  8. private static string[] m_invalidData = { "674ea7bed6b1cd94b8057074298096db", //"/Samples",
  9. "2738539936eacef409be91f148b2a4a0", //"/Resources",
  10. "c880e50f07f2be9499d414ac6f9f3a7a", //"/Templates",
  11. "563f992b9989cf547ac59bf748442c17"};//"/Textures"};
  12. //private static string m_ASEFolderPath;
  13. private static string m_invalidDataCollected = string.Empty;
  14. static InvalidDataChecker()
  15. {
  16. bool foundInvalidData = false;
  17. //m_ASEFolderPath = AssetDatabase.GUIDToAssetPath( IOUtils.ASEFolderGUID );
  18. int count = 0;
  19. for ( int i = 0; i < m_invalidData.Length; i++ )
  20. {
  21. //m_invalidData[ i ] = m_ASEFolderPath + m_invalidData[ i ];
  22. m_invalidData[ i ] = AssetDatabase.GUIDToAssetPath( m_invalidData[ i ] );
  23. if ( AssetDatabase.IsValidFolder( m_invalidData[ i ] ) )
  24. {
  25. foundInvalidData = true;
  26. m_invalidDataCollected += m_invalidData[ i ]+"\n";
  27. count += 1;
  28. }
  29. }
  30. if ( count < 5 )
  31. {
  32. for ( ; count < 5; count++ )
  33. {
  34. m_invalidDataCollected += "\n";
  35. }
  36. }
  37. if ( foundInvalidData )
  38. {
  39. InvalidDataPopUp window = ( InvalidDataPopUp ) EditorWindow.GetWindow( typeof( InvalidDataPopUp ), true, "Found Invalid Data" );
  40. window.minSize = new Vector2( 502, 265 );
  41. window.maxSize = new Vector2( 502, 265 );
  42. window.Show();
  43. }
  44. }
  45. public static void CleanInvalidData()
  46. {
  47. for ( int i = 0; i < m_invalidData.Length; i++ )
  48. {
  49. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] ) )
  50. {
  51. Debug.Log( "Removed invalid " + m_invalidData[ i ] );
  52. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] + ".meta" ) )
  53. {
  54. Debug.Log( "Removed invalid " + m_invalidData[ i ] + ".meta" );
  55. }
  56. }
  57. }
  58. AssetDatabase.Refresh();
  59. }
  60. public static string InvalidDataCollected { get { return m_invalidDataCollected; } }
  61. }
  62. public class InvalidDataPopUp : EditorWindow
  63. {
  64. private readonly GUIContent m_buttonContent = new GUIContent( "Remove Invalid Data" );
  65. private Vector2 m_scrollPosition = Vector2.zero;
  66. public void OnGUI()
  67. {
  68. GUILayout.BeginVertical();
  69. {
  70. GUIStyle labelStyle = new GUIStyle( EditorStyles.label );
  71. labelStyle.alignment = TextAnchor.MiddleCenter;
  72. labelStyle.wordWrap = true;
  73. GUILayout.Label( "\nAmplify Shader Editor " + VersionInfo.StaticToString(), labelStyle, GUILayout.ExpandWidth( true ) );
  74. GUILayout.Space( 5 );
  75. 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 ) );
  76. GUILayout.Space( 5 );
  77. GUILayout.Label( "Below are the detected files/folders which require to be removed.", labelStyle, GUILayout.ExpandWidth( true ) );
  78. GUILayout.Space( 5 );
  79. m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition ,GUILayout.Height(85));
  80. GUILayout.TextArea( InvalidDataChecker.InvalidDataCollected );
  81. GUILayout.EndScrollView();
  82. 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 ) );
  83. GUILayout.Space( 5 );
  84. GUILayout.BeginHorizontal();
  85. {
  86. GUILayout.Space( 151 );
  87. if ( GUILayout.Button( m_buttonContent, GUILayout.Width( 200 ) ) )
  88. {
  89. InvalidDataChecker.CleanInvalidData();
  90. Close();
  91. }
  92. }
  93. GUILayout.EndHorizontal();
  94. }
  95. GUILayout.EndVertical();
  96. }
  97. }
  98. }