Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

WinRTPatcher.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. namespace UnityEditor.Purchasing
  5. {
  6. internal class WinRTPatcher
  7. {
  8. private const string k_OutputPath = "Assets/Scripts/UnityPurchasing/generated";
  9. private const string k_WorkaroundFileName = "WindowsRuntimeWorkaround.cs";
  10. private const string k_WorkaroundTemplateFileName = "WindowsRuntimeWorkaround.cs.template";
  11. internal static void PatchWinRTBuild()
  12. {
  13. #if UNITY_2020
  14. if (!DoesWorkaroundClassExist())
  15. {
  16. try
  17. {
  18. BuildWorkaroundClass();
  19. }
  20. catch (Exception patchException)
  21. {
  22. Debug.LogWarning(patchException.StackTrace);
  23. }
  24. }
  25. AssetDatabase.Refresh();
  26. #endif
  27. }
  28. private static bool DoesWorkaroundClassExist()
  29. {
  30. return File.Exists(GetFullPathForWorkaroundClass());
  31. }
  32. private static string GetFullPathForWorkaroundClass()
  33. {
  34. return Path.Combine(k_OutputPath, k_WorkaroundFileName);
  35. }
  36. private static void BuildWorkaroundClass()
  37. {
  38. var templateText = LoadTemplateText();
  39. if (templateText != null)
  40. {
  41. GeneratePatchFile(templateText);
  42. }
  43. }
  44. private static string LoadTemplateText()
  45. {
  46. var templateGUID = FindTemplateGUID(k_WorkaroundFileName);
  47. string templateText = null;
  48. if (templateGUID != null)
  49. {
  50. var templateAbsolutePath = Path.Combine(Path.GetDirectoryName(Application.dataPath), AssetDatabase.GUIDToAssetPath(templateGUID));
  51. templateText = File.ReadAllText(templateAbsolutePath);
  52. }
  53. else
  54. {
  55. Debug.LogError($"Could not find template \"{k_WorkaroundTemplateFileName}\".");
  56. }
  57. return templateText;
  58. }
  59. private static string FindTemplateGUID(string templateFilename)
  60. {
  61. var assetGUIDs = AssetDatabase.FindAssets(k_WorkaroundFileName);
  62. return (assetGUIDs.Length > 0) ? assetGUIDs[0] : null;
  63. }
  64. private static void GeneratePatchFile(string templateText)
  65. {
  66. Directory.CreateDirectory(k_OutputPath);
  67. File.WriteAllText(GetFullPathForWorkaroundClass(), templateText);
  68. }
  69. }
  70. }