TMPro_TexturePostProcessor.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections;
  5. namespace TMPro.EditorUtilities
  6. {
  7. public class TMPro_TexturePostProcessor : AssetPostprocessor
  8. {
  9. void OnPostprocessTexture(Texture2D texture)
  10. {
  11. Texture2D tex = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;
  12. // Send Event Sub Objects
  13. if (tex != null)
  14. TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex);
  15. }
  16. }
  17. /// <summary>
  18. /// Asset post processor used to handle font assets getting updated outside of the Unity editor.
  19. /// </summary>
  20. class FontAssetPostProcessor : AssetPostprocessor
  21. {
  22. private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  23. {
  24. foreach (var asset in importedAssets)
  25. {
  26. if (AssetDatabase.GetMainAssetTypeAtPath(asset) == typeof(TMP_FontAsset))
  27. {
  28. TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(asset, typeof(TMP_FontAsset)) as TMP_FontAsset;
  29. if (fontAsset != null)
  30. TMP_EditorResourceManager.RegisterFontAssetForDefinitionRefresh(fontAsset);
  31. }
  32. }
  33. }
  34. }
  35. //public class TMPro_PackageImportPostProcessor : AssetPostprocessor
  36. //{
  37. // static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  38. // {
  39. // for (int i = 0; i < importedAssets.Length; i++)
  40. // {
  41. // if (importedAssets[i].Contains("TextMesh Pro/Resources/TMP Settings.asset"))
  42. // {
  43. // Debug.Log("New TMP Settings file was just imported.");
  44. // // TMP Settings file was just re-imported.
  45. // // Check if project already contains
  46. // }
  47. // if (importedAssets[i].Contains("com.unity.TextMeshPro/Examples"))
  48. // {
  49. // //Debug.Log("New TMP Examples folder was just imported.");
  50. // }
  51. // //Debug.Log("[" + importedAssets[i] + "] was just imported.");
  52. // }
  53. // //for (int i = 0; i < deletedAssets.Length; i++)
  54. // //{
  55. // // if (deletedAssets[i] == "Assets/TextMesh Pro")
  56. // // {
  57. // // //Debug.Log("Asset [" + deletedAssets[i] + "] has been deleted.");
  58. // // string currentBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  59. // // //Check for and inject TMP_PRESENT
  60. // // if (currentBuildSettings.Contains("TMP_PRESENT;"))
  61. // // {
  62. // // currentBuildSettings = currentBuildSettings.Replace("TMP_PRESENT;", "");
  63. // // PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currentBuildSettings);
  64. // // }
  65. // // else if (currentBuildSettings.Contains("TMP_PRESENT"))
  66. // // {
  67. // // currentBuildSettings = currentBuildSettings.Replace("TMP_PRESENT", "");
  68. // // PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currentBuildSettings);
  69. // // }
  70. // // }
  71. // //}
  72. // }
  73. //}
  74. }