# AppCallbacks 클래스 레퍼런스

> Call the AppCallbacks class in your UWP application.

`AppCallbacks` 클래스를 사용하여 메인 애플리케이션을 Unity 엔진에 연결할 수 있습니다.

## 예: `AppCallbacks` 클래스 사용 방법##example:-how-to-use-the-appcallbacks-class

### `App.xaml.cpp` 파일##app.xaml.cpp-file

```
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.xaml.cpp-file

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

## 앱 스레드 생성##create-an-app-thread

대형 앱을 로드할 때 UI가 응답하지 않을 수 있으므로 Unity는 UI 스레드에서 앱을 실행하지 않습니다. UI 스레드에 대한 자세한 내용은 [UI 스레드 응답 유지](https://learn.microsoft.com/en-gb/windows/uwp/debug-test-perf/keep-the-ui-thread-responsive)에 대한 Microsoft 기술 자료를 참조하십시오.

`m_AppCallbacks = ref new AppCallbacks();`를 사용하여 `AppCallbacks` 클래스를 생성하면 Unity는 `App Thread`라는 새 스레드를 생성합니다. Unity는 Microsoft의 제한 사항으로 인해 이 새로운 스레드를 생성합니다. 5초 후에 애플리케이션이 응답하지 않으면 Windows 앱 인증 키트 테스트를 통과하지 못합니다. 자세한 내용은 [Windows 앱 인증 키트](https://learn.microsoft.com/en-us/windows/uwp/debug-test-perf/windows-app-certification-kit)에 대한 Microsoft 기술 자료를 참조하십시오.

**참고:** `App.xaml.cpp` 및 `MainPage.xaml.cpp` 파일에 있는 코드는 `InvokeOnAppThread` 함수에서 호출되지 않는 한 항상 UI 스레드에서 실행됩니다.

## 커맨드 라인 인자##command-line-arguments

커스텀 커맨드 라인 인자를 문자열 배열로 AppCallbacks 생성자에 전달할 수 있습니다. 자세한 내용은 [UWP 커맨드 라인 인자](https://docs.unity3d.com/2023.1/Documentation/Manual/windowsstore-commandlinearguments.html)를 참조하십시오.

## AppCallbacks 함수##appcallbacks-functions

| **함수**                                                             | **설명**                                                                                                                                                                                                                                              |
| ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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](/engine/6000.0/script-reference/unity-engine-wsa/application/arguments.md)에서 액세스할 수 있습니다.                                                                                                |
| `void SetCoreApplicationViewEvents()`                              | CoreApplicationView::Activated 이벤트를 구독하고 그래픽스를 제외한 모든 엔진 보조 시스템과 IL2CPP 스크립팅 백엔드를 로드합니다.                                                                                                                                                            |
| `bool UnityGetInput()`                                             | Unity가 수신하는 입력을 처리하는 경우 true를 반환합니다.                                                                                                                                                                                                                |
| `void UnitySetInput(bool enabled)`                                 | 입력 처리를 활성화하거나 비활성화합니다.                                                                                                                                                                                                                              |
| `bool UnityPause(int pause)`                                       | 1을 통과하면 Unity를 일시 정지하고 0을 통과하면 일시 정지를 해제합니다. 이 함수는 게임을 일시적으로 정지하려는 경우에 유용합니다.                                                                                                                                                                       |

## 추가 리소스##additional-resources

* [UI 스레드 응답 유지에 대한 Microsoft 기술 자료](https://learn.microsoft.com/en-gb/windows/uwp/debug-test-perf/keep-the-ui-thread-responsive)
* [UWP 커맨드 라인 인자](/engine/6000.0/manual/platform-specific/windows-store/uwp-developing/windowsstore-commandlinearguments.md)
* [커맨드 라인 인자](/engine/6000.0/manual/unity-editor/editor-features/command-line-arguments/player.md)
