No Description
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.

TMPro_TexturePostProcessor.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace TMPro.EditorUtilities
  5. {
  6. /// <summary>
  7. /// Asset post processor used to handle text assets changes.
  8. /// This includes tracking of changes to textures used by sprite assets as well as font assets potentially getting updated outside of the Unity editor.
  9. /// </summary>
  10. internal class TMPro_TexturePostProcessor : AssetPostprocessor
  11. {
  12. private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  13. {
  14. foreach (var asset in importedAssets)
  15. {
  16. // Return if imported asset path is outside of the project.
  17. if (asset.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase) == false)
  18. continue;
  19. Type assetType = AssetDatabase.GetMainAssetTypeAtPath(asset);
  20. if (assetType == typeof(TMP_FontAsset))
  21. {
  22. TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(asset, typeof(TMP_FontAsset)) as TMP_FontAsset;
  23. // Only refresh font asset definition if font asset was previously initialized.
  24. if (fontAsset != null && fontAsset.m_CharacterLookupDictionary != null)
  25. TMP_EditorResourceManager.RegisterFontAssetForDefinitionRefresh(fontAsset);
  26. }
  27. if (assetType == typeof(Texture2D))
  28. {
  29. Texture2D tex = AssetDatabase.LoadAssetAtPath(asset, typeof(Texture2D)) as Texture2D;
  30. if (tex == null)
  31. continue;
  32. TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex);
  33. Resources.UnloadAsset(tex);
  34. }
  35. }
  36. }
  37. }
  38. }