Unreal Engine 4
Hive SDKをインストールした後に実行する作業について説明します。
画面の自動回転機能の設定¶
画面方向をランドスケープとポートレートの両方に設定する場合は、以下の設定が必要です。
Android¶
Androidアプリビルドで画面方向をランドスケープとポートレートの両方に設定する場合、画面の自動回転機能を正常に動作させるには、以下のコード変更が必要です。
- /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.templateに移動します。
HiveActivity.onConfigurationChanged()APIを追加します。@Override public void onConfigurationChanged(Configuration newConfig) { HiveActivity.onConfigurationChanged(this, newConfig); // Add super.onConfigurationChanged(newConfig); // forward the orientation boolean bPortrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT; nativeOnConfigurationChanged(bPortrait); }
iOS¶
iOSで双方向の画面回転を正常に動作させるには、Unreal EngineのIOSAppDelegate.cppファイルに、画面回転関連メソッドapplication(\_:supportedInterfaceOrientationsFor:)を実装します。このメソッドは、ゲームに適用するUIInterfaceOrientationMask値を返します。ランドスケープ専用ゲームはlandscape、ポートレート専用ゲームはportrait、ランドスケープとポートレートの両方をサポートするゲームはlandscapeとportraitの両方を返します。
/Engine/Source/Runtime/ApplicationCore/Private/IOS/IOSAppDelegate.cppに以下のコードを追加します。
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// TODO: Landscape-only game
return UIInterfaceOrientationMaskLandscape;
// TODO: Portrait-only game
return UIInterfaceOrientationMaskPortrait;
// TODO: Game that supports both landscape and portrait
return UIInterfaceOrientationMaskAll;
}
Swift互換性の設定(iOS)¶
iOS開発環境では、Unreal Engine 4とSwift言語の互換性のために、以下のファイルで'Add'コメントが付いた行またはブロックを追加してください。
Engine/Source/Programs/UnrealBuildTool/ProjectFiles/Xcode/XcodeProject.cs
{
Content.Append("\t\t\t\t\"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]\" = " + IOS_BUNDLE + ";" + ProjectFileGenerator.NewLine);
}
// Add
if (ProjectFile != null)
{
Content.Append("\t\t\t\tSWIFT_VERSION = 5.0;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tSWIFT_OBJC_BRIDGING_HEADER = \"" + GamePath + "/dummy-Bridging-Header.h\";" + ProjectFileGenerator.NewLine);
}
// Add End
}
if (TVOSRunTimeVersion != null)
{
if (XcodeProjectFileGenerator.bGeneratingRunIOSProject)
{
Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
Content.Append("\t\t\t\tINFOPLIST_FILE = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tCODE_SIGN_ENTITLEMENTS = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}
Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=macosx*]\" = \"" + MacInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
if (IOSRunTimeVersion != null)
{
Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=iphoneos*]\" = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\t\"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]\" = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}
Engine/Source/Programs/UnrealBuildTool/Platform/IOS/IOSToolChain.cs
Result += " -Xlinker \\\"" + Path.GetDirectoryName(OutputFile.AbsolutePath) + "\\\"";
}
Result += " -Xlinker -rpath -Xlinker /usr/lib/swift"; // Add
Result += " -dead_strip";
Result += " -m" + GetXcodeMinVersionParam() + "=" + ProjectSettings.RuntimeVersion;
Result += " -Wl";
Entitlementsの設定(iOS)¶
Unreal Engineはビルド時にUnrealBuildToolを通じて署名用のentitlementsファイルを動的に作成します。必要なentitlement項目は以下のように追加します。
- プロジェクト設定から追加:一部の共通entitlement項目は、Unreal EditorのProject Settingsメニューで直接有効化できます。
- エンジンソースの修正による追加:Project Settingsでサポートされないその他の項目は、以下のUnrealBuildToolエンジンソースファイル内のentitlements生成コードを直接修正して追加する必要があります。
- 修正対象ファイル:Engine/Source/Programs/UnrealBuildTool/Platform/IOS/IOSExport.cs
Hive SDK機能ごとに必要なentitlement項目と追加方法は以下のとおりです。アプリで使用する機能(プロビジョニングプロファイルで有効化されたcapability)に対応する項目のみを追加してください。各項目の詳細については、Apple公式ドキュメントを参照してください。
| 使用する機能 | 必要なentitlement | 追加方法 |
|---|---|---|
| Remote Push | aps-environment | Project Settings > Platforms > iOSのOnline項目でEnable Remote Notifications Supportをチェック |
| Appleログイン(IdP) | com.apple.developer.applesignin | Config/DefaultEngine.iniの[/Script/IOSRuntimeSettings.IOSRuntimeSettings]セクションにbEnableSignInWithAppleSupport=Trueを追加 |
| Universal Link(Deep Link・招待リンク) | com.apple.developer.associated-domains | IOSExport.csを修正。ドメイン設定はUniversal Linkの設定を参照 |
| Game Centerログイン(IdP) | com.apple.developer.game-center | IOSExport.csを修正 |
| 年齢申告(AgeRangeモジュール) | com.apple.developer.declared-age-range | IOSExport.csを修正。詳細はApp Storeコンプライアンスを参照 |
IOSExport.csを修正する場合は、以下の位置の'Add'と'Add End'の間に必要な項目を追加してください。
Text.AppendLine( "<dict>");
Text.AppendLine( "\t<key>get-task-allow</key>");
Text.AppendLine(string.Format( "\t<{0}/>", bForDistribution ? "false": "true"));
// Add - Add the required entitlement entries. The following is a Game Center example.
Text.AppendLine("\t<key>com.apple.developer.game-center</key>");
Text.AppendLine("\t<true/>");
// Add End
if (bCloudKitSupported) {
if (iCloudContainerIdentifiersXML != "")
Note
IOSExport.csファイルの修正はUnrealBuildTool(UBT)のソースコード変更に該当します。エンジン全体を再ビルドする必要はありません。次回のプロジェクトビルド時にUBTが自動的にコンパイルされ、変更内容が即時に反映されます。
ビルド後、entitlementsがアプリに適用されているか以下のように確認してください。
HIVEAppDelegateの適用(iOS)¶
Hive SDK v4 26.4.1以降では、HIVEAppDelegate swizzlingがHive SDKプラグイン内部で自動的に実行されます。アプリ起動時にプラグインが自動で処理するため、アプリコードで追加作業を行う必要はありません。
v4 26.4.1より前のバージョン向け既存連携コードの削除
Hive SDK v4 26.4.1より前のバージョンを使用している場合は、更新時に以前の修正を削除してください。
-
HIVEAppDelegate手動呼び出しコードの削除:以前のガイドの「HIVEAppDelegateの適用(iOS)」手順を参照し、アプリ初期化時に追加した以下のようなコードブロックをプロジェクトから削除してください。
#if PLATFORM_IOS UIApplication * dummyApplication = [UIApplication sharedApplication]; Class clzHIVEAppDelegate = NSClassFromString(@"HIVEAppDelegate"); SEL selApplicationDidFinishLaunchingWithOptions = NSSelectorFromString(@"application:didFinishLaunchingWithOptions:"); if( clzHIVEAppDelegate != nil && [clzHIVEAppDelegate respondsToSelector:selApplicationDidFinishLaunchingWithOptions] ) { NSMethodSignature *method = [clzHIVEAppDelegate methodSignatureForSelector:selApplicationDidFinishLaunchingWithOptions]; if (method != nil) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method]; [invocation setSelector:selApplicationDidFinishLaunchingWithOptions]; [invocation setTarget:clzHIVEAppDelegate]; [invocation setArgument:(void*)&dummyApplication atIndex:2]; NSDictionary *localLaunchOptions = [IOSAppDelegate GetDelegate].launchOptions; if( localLaunchOptions != nil ) { [invocation setArgument:(void*)&localLaunchOptions atIndex:3]; } [invocation invoke]; } } #endif -
Deep Linkデリゲート購読コードの削除:以前のガイドの「Deep Link設定のためのプロモーションコード追加(iOS)」手順を参照し、
GameInstanceなどに追加した以下のような購読およびハンドラーコードを削除してください。-
ハンドラー内部のロジックは、使用しているインターフェースに応じて
Promotion::processURI(...)またはFHivePromotion::ProcessURI(...)として実装されている場合があります。// Subscription code (GameInstance::Init, etc.) - remove FIOSCoreDelegates::OnOpenURLwithOptions.AddUObject(this, &UMyGameInstance::ApplicationOpenURL); // Handler - remove (including the declaration in the header) void UMyGameInstance::ApplicationOpenURL(UIApplication* application, NSURL* url, NSDictionary* options) { Promotion::processURI(std::string([[url absoluteString] UTF8String])); }
-
-
Blueprintのブートストラップトリガー呼び出しの削除:アプリで独自に定義しBlueprintから呼び出していたトリガー関数(例:
RemoveOpenURLDelegate())と該当する呼び出しノードをすべて削除してください。上記のアプリ内デリゲート購読が正常に削除されていれば、カスタムエンジンに直接適用した既存のopenURL関連修正コード(
IOSAppDelegate.h、IOSAppDelegate.cpp)はエンジン動作に影響しません。そのため、そのコードは削除またはロールバックせず、そのまま維持しても問題ありません。