AppCallbacks 클래스를 사용하여 메인 애플리케이션을 Unity 엔진에 연결할 수 있습니다.
AppCallbacks 클래스 사용 방법App.xaml.cpp 파일App::App()
{
    InitializeComponent();
    SetupOrientation();
    m_AppCallbacks = ref new AppCallbacks();
}
void App::OnLaunched(LaunchActivatedEventArgs^ e)
{
    m_SplashScreen = e->SplashScreen;
    InitializeUnity(e->Arguments);
}
void App::InitializeUnity(String^ args)
{
    ApplicationView::GetForCurrentView()->SuppressSystemOverlays = true;
    m_AppCallbacks->SetAppArguments(args);
    auto rootFrame = safe_cast<Frame^>(Window::Current->Content);
    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == nullptr && !m_AppCallbacks->IsInitialized())
    {
        rootFrame = ref new Frame();
        Window::Current->Content = rootFrame;
# if !UNITY_HOLOGRAPHIC
        Window::Current->Activate();
# endif
        rootFrame->Navigate(TypeName(MainPage::typeid ));
    }
    Window::Current->Activate();
}
MainPage.xaml.cpp 파일MainPage::MainPage()
{
    m_SplashScreenRemovalEventToken.Value = 0;
    m_OnResizeRegistrationToken.Value = 0;
    InitializeComponent();
    NavigationCacheMode = ::NavigationCacheMode::Required;
    auto appCallbacks = AppCallbacks::Instance;
    bool isWindowsHolographic = false;
# if UNITY_HOLOGRAPHIC
    // If application was exported as Holographic check if the device actually supports it
    // Otherwise, we treat this as a normal XAML application
    isWindowsHolographic = AppCallbacks::IsMixedRealitySupported();
# endif
    if (isWindowsHolographic)
    {
        appCallbacks->InitializeViewManager(Window::Current->CoreWindow);
    }
    else
    {
        m_SplashScreenRemovalEventToken = appCallbacks->RenderingStarted += ref new RenderingStartedHandler(this, &MainPage::RemoveSplashScreen);
        appCallbacks->SetSwapChainPanel(m_DXSwapChainPanel);
        // Subscribes to all needed system events
        appCallbacks->SetCoreWindowEvents(Window::Current->CoreWindow);
        // This is the main initialization function for Unity
        // Initializes engine graphics, DirectX, and gamepad and joystick input
        // Loads IL2CPP and all engine subsystems except graphics
        appCallbacks->InitializeD3DXAML();
        // At this point, when Unity finishes loading the first level, it enters the main loop.
        m_SplashScreen = safe_cast<App^>(App::Current)->GetSplashScreen();
        auto dispatcher = CoreWindow::GetForCurrentThread()->Dispatcher;
        ThreadPool::RunAsync(ref new WorkItemHandler([this, dispatcher](IAsyncAction^)
        {
            GetSplashBackgroundColor(dispatcher);
        }));
        OnResize();
        m_OnResizeRegistrationToken = Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler([this](Object^, WindowSizeChangedEventArgs^)
        {
            OnResize();
        });
    }
}
Unity는 대용량 앱을 로드할 때 UI가 응답하지 않을 수 있으므로 UI 스레드에서 앱을 실행하지 않습니다.UI 스레드에 대한 자세한 내용은 UI 스레드 응답성 유지에 대한 Microsoft의 문서를 참조하십시오.
m_AppCallbacks = ref new AppCallbacks();를 사용하여 AppCallbacks 클래스를 생성하면 Unity는 App Thread라는 새 스레드를 생성합니다.애플리케이션이 5초 후에 응답하지 않으면 Windows App Certification Kit 테스트를 통과하지 못한다는 Microsoft의 제한 사항으로 인해 Unity는 이 새 스레드를 생성합니다.자세한 내용은 Windows App Certification Kit에 대한 Microsoft의 문서를 참조하십시오.
참고:InvokeOnAppThread 함수에서 호출되지 않는 한 App.xaml.cpp 및 MainPage.xaml.cpp 파일에 있는 코드는 항상 UI 스레드에서 실행됩니다.
커스텀 커맨드 라인 인자를 문자열 배열로 AppCallbacks 생성자에 전달할 수 있습니다.자세한 내용은 UWP 커맨드 라인 인자를 참조하십시오.
| 기능 | 설명 | 
|---|---|
appCallbacks->InitializeD3DXAML(); | 
	DirectX 11 기기를 초기화하고 첫 번째 레벨을 로드합니다. | 
appCallbacks->SetCoreWindowEvents(Window::Current->CoreWindow); | 
	Unity의 코어 창을 설정합니다.Unity는 다음 시스템 이벤트를 구독합니다. - VisibilityChanged - Closed - PointerCursor - SizeChanged - Activated - CharacterReceived - PointerPressed - PointerReleased - PointerMoved - PointerCaptureLost - PointerWheelChanged - AcceleratorKeyActivated  | 
appCallbacks->SetSwapChainPanel(m_DXSwapChainPanel); | 
	DirectX 11의 렌더 타겟으로 사용되는 XAML 컨트롤을 Unity에 전달합니다. | 
void GetSwapChainPanel() | 
	SetSwapChainPanel 메서드를 통해 설정할 수 있는 SwapChainPanel 오브젝트를 반환합니다. | 
void Initialized() | 
	엔진이 메인 게임 루프를 실행할 수 있을 만큼 초기화되었는지를 반환합니다. | 
void InitializeD3DWindow() | 
	D3D 애플리케이션의 엔진 그래픽스, DirectX, 게임패드 및 조이스틱 입력을 초기화합니다. | 
void Instance() | 
	이전에 생성한 AppCallbacks 오브젝트의 싱글톤 인스턴스를 검색합니다. | 
void InvokeOnAppThread(AppCallbackItem item, bool waitUntilDone) | 
	애플리케이션 스레드의 델리게이트를 호출합니다.이 함수는 UI 스레드에서 스크립트 함수를 실행하고 싶은 경우 유용합니다. | 
void InvokeOnUIThread(AppCallbackItem item, bool waitUntilDone) | 
	UI 스레드의 델리게이트를 호출합니다.이 함수는 스크립트에서 XAML 전용 API를 호출하고 싶은 경우 유용합니다. | 
bool IsInitialized() | 
	애플리케이션의 첫 번째 레벨이 완전히 로드되면 true를 반환합니다. | 
void RenderingStarted() | 
	Unity가 첫 번째 프레임을 렌더링한 후 시작합니다. | 
void Run() | 
	D3D 애플리케이션이 메인 루프에 진입할 수 있도록 활성화합니다. | 
bool RunningOnAppThread() | 
	현재 애플리케이션 스레드에서 실행 중인 경우 true를 반환합니다. | 
bool RunningOnUIThread() | 
	현재 UI 스레드에서 실행 중인 경우 true를 반환합니다. | 
void SetAppArguments(string arg) / string GetAppArguments()
 | 
	애플리케이션 인자를 설정한 다음, UnityEngine.WSA.Application.arguments에서 액세스할 수 있습니다. | 
void SetCoreApplicationViewEvents() | 
	CoreApplicationView::Activated 이벤트를 구독하고 그래픽스를 제외한 모든 엔진 보조 시스템과 IL2CPP 스크립팅 백엔드를 로드합니다. | 
bool UnityGetInput() | 
	Unity가 수신하는 입력을 처리하는 경우 true를 반환합니다. | 
void UnitySetInput(bool enabled) | 
	입력 처리를 활성화하거나 비활성화합니다. | 
bool UnityPause(int pause) | 
	1을 전달하면 Unity를 일시정지하고 0을 전달하면 일시정지를 해제합니다.이 함수는 게임을 일시적으로 정지하고 싶은 경우 유용합니다. |