跳转至

Unreal Engine 4

本指南解释了安装 Hive SDK 后需要执行的任务。

设置自动旋转屏幕功能

在将屏幕方向设置为横屏和竖屏时,需要以下设置。

安卓

对于 Android 应用程序构建,如果您想将屏幕方向设置为横向和纵向,并确保自动旋转功能正常工作,您需要修改以下代码。

<

  1. 导航到 /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.template
  2. 添加 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,而支持横屏和竖屏的游戏返回 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 supporting both landscape and portrait
  return UIInterfaceOrientationMaskAll;
}

设置 Swift 兼容性 (iOS)

在iOS开发环境中,为了确保Unreal Engine 4与Swift语言的兼容性,请在以下文件中添加带有'Add'注释的行(从AddAdd End)。

<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);
}

引擎/源代码/程序/UnrealBuildTool/平台/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
////////////////////////////////////////////////////////////////

设置 FmallocAnsi (iOS)

为了确保Unreal Engine iOS与C++标准模板库的兼容性,您需要按如下方式配置FMallocAnsi。将以下代码添加到您的应用项目的{YourProject}.Target.cs文件中。

public class YourProjectTarget : TargetRules
{
    public YourProjectTarget(TargetInfo Target) : base(Target)
    {  
        // Force ANSI allocator for the app client
        if(Target.Platform == UnrealTargetPlatform.IOS)
        {
            GlobalDefinitions.Add("FORCE_ANSI_ALLOCATOR=1");
        }
    }
}