跳转至

Unreal Engine 4

本指南说明安装 Hive SDK 后需要执行的任务。

设置自动旋转屏幕功能

当屏幕方向设置为同时支持横屏和竖屏时,需要进行以下设置。

Android

对于 Android 应用构建,如果将屏幕方向设置为同时支持横屏和竖屏,则需要进行以下代码修改,才能使自动旋转屏幕功能正常工作。

  1. 前往 /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.template
  2. 添加 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,同时支持横屏和竖屏的游戏返回 landscapeportrait

将以下代码添加到 /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 项及添加方法如下。请仅添加应用使用的功能对应的项,这些功能也必须在 provisioning profile 中作为 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] section 中添加 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 是否已应用到应用。

codesign -d --entitlements :- {构建后的 .app 路径}

应用 HIVEAppDelegate (iOS)

从 Hive SDK v4 26.4.1 开始,HIVEAppDelegate swizzling 会在 Hive SDK 插件内部自动执行。应用启动时插件会自动处理,因此无需在应用代码中进行额外操作。

删除 v4 26.4.1 之前版本的既有集成代码

如果正在使用早于 Hive SDK v4 26.4.1 的版本,请在更新时删除之前的修改。

  1. 删除手动调用 HIVEAppDelegate 的代码:参考旧指南中的“应用 HIVEAppDelegate (iOS)”步骤,从项目中删除应用初始化时添加的代码块。
  2. 删除 Deep Link 委托订阅代码:参考旧指南中的“为 Deep Link 设置添加 Promotion 代码 (iOS)”步骤,删除添加到 GameInstance 等类中的订阅和处理程序代码。
    • 处理程序内部逻辑可能根据所使用的接口,以 Promotion::processURI(...)FHivePromotion::ProcessURI(...) 的形式实现。
  3. 删除 Blueprint bootstrap trigger 调用:删除应用中自定义并在 Blueprint 中调用的所有 trigger 函数(例如 RemoveOpenURLDelegate())及其对应的调用节点。

    如果上述应用内委托订阅已正确删除,直接应用到自定义引擎中的既有 openURL 相关修改代码(IOSAppDelegate.hIOSAppDelegate.cpp)不会影响引擎行为。因此,可以保留该代码,无需删除或回滚。