跳轉至

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)不會影響引擎行為。因此,可以保留該程式碼,無需刪除或回滾。