Unreal Engine 4
このガイドでは、Hive SDKをインストールした後に実行するタスクについて説明します。
自動回転画面機能の設定¶
画面の向きを横向きと縦向きの両方に設定する場合、以下の設定が必要です。
アンドロイド¶
Androidアプリのビルドの場合、画面の向きを横向きと縦向きの両方に設定し、自動回転機能が正しく動作するようにするには、以下のコードを修正する必要があります。
- /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.templateに移動します。
HiveActivity.onConfigurationChaged()
APIを追加します。@Override public void onConfigurationChanged(Configuration newConfig) { HiveActivity.onConfigurationChanged(this, newConfig); // 追加 super.onConfigurationChanged(newConfig); // 向きを進める 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 supporting both landscape and portrait
return UIInterfaceOrientationMaskAll;
}
Swiftの互換性を設定する(iOS)¶
iOS開発環境では、Unreal Engine 4とSwift言語の互換性を確保するために、以下のファイルに'Add'
コメントでマークされた行を追加します(Add
からAdd End
まで)。
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";
HIVEAppDelegateを適用する (iOS)¶
iOS開発環境では、Swizzlingを使用してAppDelegateを修正し、Hive SDKを使用します。アプリの開始時の初期化ステップで次のコードを追加してください。
////////////////////////////////////////////////////////////////
// Add IOSAppDelegate.h header
#if PLATFORM_IOS
#include "Runtime/ApplicationCore/Public/iOS/IOSAppDelegate.h"
#endif
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// AppDelegate additional code
#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
////////////////////////////////////////////////////////////////
ディープリンク設定のためのプロモーションコードの追加 (iOS)¶
iOS開発環境では、アプリがシャットダウン状態のときにディープリンク操作の前提条件としてプロモーションコードを適用する必要があります。
プロモーションコードは、FHiveAuthV4::Setup(const FHiveAuthV4OnSetupDelegate& Delegate)
を呼び出した後に、Hive SDKに深いリンクとして呼ばれるスキームを渡すために必要です。
ゲームインスタンスの初期化時に、次のようにプロモーションコードを追加してください。
//HIVEV4TesterPlatformGameInstance.cpp
#if PLATFORM_IOS
#include "Runtime/ApplicationCore/Public/iOS/IOSAppDelegate.h"
#endif
void UHIVEV4TesterPlatformGameInstance::Init()
{
#if PLATFORM_IOS
FIOSCoreDelegates::OnOpenURLwithOptions.AddUObject(this, &UHIVEV4TesterPlatformGameInstance::ApplicationOpenURL);
#endif
}
void UHIVEV4TesterPlatformGameInstance::ApplicationOpenURL(UIApplication* application, NSURL* url, NSDictionary* options)
{
#if PLATFORM_IOS
// Process the URL with HIVE SDK
Promotion::processURI(std::string([[url absoluteString] UTF8String]));
#endif
}
FmallocAnsiの設定 (iOS)¶
Unreal Engine iOSとC++標準テンプレートライブラリの互換性を確保するために、FMallocAnsiを次のように構成する必要があります。次のコードをアプリプロジェクトの{YourProject}.Target.csファイルに追加してください。