Geen omschrijving
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.

AppleCapabilities.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #if UNITY_TVOS || UNITY_IOS || UNITY_VISIONOS
  2. using System;
  3. using System.IO;
  4. using UnityEditor.Build;
  5. using UnityEditor.Build.Reporting;
  6. using UnityEditor.iOS.Xcode;
  7. using UnityEngine;
  8. namespace UnityEditor.Purchasing
  9. {
  10. class AppleCapabilities : IPostprocessBuildWithReport
  11. {
  12. const string k_StorekitFramework = "StoreKit.framework";
  13. public int callbackOrder => 0;
  14. public void OnPostprocessBuild(BuildReport report)
  15. {
  16. if (report.summary.platform == BuildTarget.tvOS || report.summary.platform == BuildTarget.iOS
  17. #if UNITY_VISIONOS
  18. || report.summary.platform == BuildTarget.VisionOS
  19. #endif
  20. )
  21. {
  22. OnPostprocessBuild(report.summary.platform, report.summary.outputPath);
  23. }
  24. }
  25. static void OnPostprocessBuild(BuildTarget buildTarget, string path)
  26. {
  27. OnPostprocessBuildForApple(path);
  28. }
  29. static void OnPostprocessBuildForApple(string path)
  30. {
  31. #if UNITY_IOS || UNITY_TVOS
  32. var projPath = PBXProject.GetPBXProjectPath(path);
  33. #elif UNITY_VISIONOS
  34. var projPath = Path.Combine(path, "Unity-VisionOS.xcodeproj/project.pbxproj");
  35. #endif
  36. var proj = new PBXProject();
  37. proj.ReadFromFile(projPath);
  38. AddStoreKitFramework(proj, projPath);
  39. AddInAppPurchasingCapability(projPath, proj);
  40. }
  41. static void AddInAppPurchasingCapability(string projPath, PBXProject proj)
  42. {
  43. var manager = new ProjectCapabilityManager(
  44. projPath,
  45. null,
  46. targetGuid: proj.GetUnityMainTargetGuid()
  47. );
  48. manager.AddInAppPurchase();
  49. manager.WriteToFile();
  50. }
  51. static void AddStoreKitFramework(PBXProject proj, string projPath)
  52. {
  53. foreach (var targetGuid in new[] { proj.GetUnityMainTargetGuid(), proj.GetUnityFrameworkTargetGuid() })
  54. {
  55. proj.AddFrameworkToProject(targetGuid, k_StorekitFramework, false);
  56. System.IO.File.WriteAllText(projPath, proj.WriteToString());
  57. }
  58. }
  59. }
  60. }
  61. #endif