CreateDunGenSettings.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEditor;
  2. namespace DunGen.Editor
  3. {
  4. public sealed class CreateDunGenSettings : AssetPostprocessor
  5. {
  6. #if UNITY_2021_2_OR_NEWER
  7. static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
  8. {
  9. // Ignore if we're importing the DunGenSettings asset to avoid an infinite loop
  10. foreach (var path in importedAssets)
  11. {
  12. var assetType = AssetDatabase.GetMainAssetTypeAtPath(path);
  13. if (assetType == typeof(DunGenSettings))
  14. return;
  15. }
  16. DunGenSettings.FindOrCreateInstanceAsset();
  17. }
  18. #else
  19. static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  20. {
  21. // Ignore if we're importing the DunGenSettings asset to avoid an infinite loop
  22. foreach (var path in importedAssets)
  23. {
  24. var assetType = AssetDatabase.GetMainAssetTypeAtPath(path);
  25. if (assetType == typeof(DunGenSettings))
  26. return;
  27. }
  28. DunGenSettings.FindOrCreateInstanceAsset();
  29. }
  30. #endif
  31. }
  32. }