SceneSaveCallback.cs 908 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. namespace AmplifyShaderEditor
  4. {
  5. // Catch when scene is saved (Ctr+S) and also save ase shader
  6. public class SceneSaveCallback : UnityEditor.AssetModificationProcessor
  7. {
  8. private const string UnityStr = ".unity";
  9. static string[] OnWillSaveAssets( string[] paths )
  10. {
  11. if( !Preferences.User.UpdateOnSceneSave )
  12. return paths;
  13. bool canSave = false;
  14. if ( paths.Length == 0 )
  15. {
  16. canSave = true;
  17. }
  18. else
  19. {
  20. for ( int i = 0; i < paths.Length; i++ )
  21. {
  22. // Only save shader when saving scenes
  23. if ( !string.IsNullOrEmpty( paths[ i ] ) && paths[ i ].Contains( UnityStr ) )
  24. {
  25. canSave = true;
  26. break;
  27. }
  28. }
  29. }
  30. if ( canSave && UIUtils.CurrentWindow )
  31. UIUtils.CurrentWindow.SetCtrlSCallback( false );
  32. return paths;
  33. }
  34. }
  35. }