TMP_PostBuildProcessHandler.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.Callbacks;
  4. using System.IO;
  5. namespace TMPro
  6. {
  7. public class TMP_PostBuildProcessHandler
  8. {
  9. [PostProcessBuildAttribute(10000)]
  10. public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
  11. {
  12. // Check if TMP Essential Resource are present in user project.
  13. if (target == BuildTarget.iOS && File.Exists(GetEssentialProjectResourcesPath() + "/Resources/TMP Settings.asset") && TMP_Settings.enableEmojiSupport)
  14. {
  15. string file = Path.Combine(pathToBuiltProject, "Classes/UI/Keyboard.mm");
  16. string content = File.ReadAllText(file);
  17. content = content.Replace("FILTER_EMOJIS_IOS_KEYBOARD 1", "FILTER_EMOJIS_IOS_KEYBOARD 0");
  18. File.WriteAllText(file, content);
  19. }
  20. }
  21. private static string GetEssentialProjectResourcesPath()
  22. {
  23. // Find the potential location of the TextMesh Pro folder in the user project.
  24. string projectPath = Path.GetFullPath("Assets/..");
  25. if (Directory.Exists(projectPath))
  26. {
  27. // Search for default location of TMP Essential Resources
  28. if (Directory.Exists(projectPath + "/Assets/TextMesh Pro/Resources"))
  29. {
  30. return "Assets/TextMesh Pro";
  31. }
  32. // Search for potential alternative locations in the user project
  33. string[] matchingPaths = Directory.GetDirectories(projectPath, "TextMesh Pro", SearchOption.AllDirectories);
  34. projectPath = ValidateLocation(matchingPaths, projectPath);
  35. if (projectPath != null) return projectPath;
  36. }
  37. return null;
  38. }
  39. private static string ValidateLocation(string[] paths, string projectPath)
  40. {
  41. for (int i = 0; i < paths.Length; i++)
  42. {
  43. // Check if any of the matching directories contain a GUISkins directory.
  44. if (Directory.Exists(paths[i] + "/Resources"))
  45. {
  46. string folderPath = paths[i].Replace(projectPath, "");
  47. folderPath = folderPath.TrimStart('\\', '/');
  48. return folderPath;
  49. }
  50. }
  51. return null;
  52. }
  53. }
  54. }