EntitlementsPostProcess.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.Callbacks;
  4. using UnityEditor.iOS.Xcode;
  5. using System.Collections;
  6. using System.IO;
  7. public class EntitlementsPostProcess : ScriptableObject
  8. {
  9. public DefaultAsset m_entitlementsFile;
  10. [PostProcessBuild]
  11. public static void OnPostProcess(BuildTarget buildTarget, string buildPath)
  12. {
  13. if (buildTarget != BuildTarget.iOS)
  14. {
  15. return;
  16. }
  17. var dummy = ScriptableObject.CreateInstance<EntitlementsPostProcess>();
  18. var file = dummy.m_entitlementsFile;
  19. ScriptableObject.DestroyImmediate(dummy);
  20. if (file == null)
  21. {
  22. return;
  23. }
  24. var proj_path = PBXProject.GetPBXProjectPath(buildPath);
  25. var proj = new PBXProject();
  26. proj.ReadFromFile(proj_path);
  27. // target_name = "Unity-iPhone"
  28. var target_name = PBXProject.GetUnityTargetName();
  29. var target_guid = proj.TargetGuidByName(target_name);
  30. var src = AssetDatabase.GetAssetPath(file);
  31. var file_name = Path.GetFileName(src);
  32. var dst = buildPath + "/" + target_name + "/" + file_name;
  33. FileUtil.CopyFileOrDirectory(src, dst);
  34. proj.AddFile(target_name + "/" + file_name, file_name);
  35. proj.AddBuildProperty(target_guid, "CODE_SIGN_ENTITLEMENTS", target_name + "/" + file_name);
  36. proj.WriteToFile(proj_path);
  37. }
  38. }