LoginSignup
14
10

More than 5 years have passed since last update.

Unity5のポストプロセスでxcode code signingの変更を行うサンプル

Last updated at Posted at 2016-04-16

「Unityのビルドポストプロセス時に、どの署名を使うかXCodeのプロジェクトファイル設定を変更する」
というだけのシンプルなサンプルソースがネット上に転がってなかったので書いてみました。

PBXProjectクラスではフレームワークの追加とかプロジェクトファイルにできることならなんでも出来ますが、そのへんの応用例は他のブログなどを参照していただければ。

Assets/Editor/PostBuildProcess.cs

using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public class PostBuildProcess
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if( buildTarget==BuildTarget.iOS )
        {
            ProcessForiOS( path );
        }
    }

    private static void ProcessForiOS(string path)
    {
        string projPath = PBXProject.GetPBXProjectPath( path );
        PBXProject proj = new PBXProject ();
        proj.ReadFromFile( projPath );

        string target           = proj.TargetGuidByName( PBXProject.GetUnityTargetName() );
        string debugConfig      = proj.BuildConfigByName( target, "Debug" );
        string releaseConfig    = proj.BuildConfigByName( target, "Release" );

        proj.SetBuildPropertyForConfig( debugConfig, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", "iPhone Developer" );
        proj.SetBuildPropertyForConfig( releaseConfig, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", "iPhone Distribution: XXXXXX" );

        proj.WriteToFile( projPath );
    }
}

2016/05/19
プロジェクトファイル名などの文字列がマジックワードになっていたのですが、関数で取得できることに気が付いたのでリファクタリングしています。

path + "/Unity-iPhone.xcodeproj/project.pbxproj";

PBXProject.GetPBXProjectPath( path );

proj.BuildConfigByName( target, "Release" );

proj.TargetGuidByName( PBXProject.GetUnityTargetName() );

14
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10