# Unity

{% hint style="info" %}
Hackle Unity SDK는 Android SDK, iOS SDK 를 기반으로 작동합니다. 아래 OS를 지원합니다.

* Android API 16 (4.1 Jelly Bean) 이상
* iOS 10 이상
  {% endhint %}

{% hint style="danger" %}
Unity SDK는 Desktop이나 Editor를 지원하지 않습니다.
{% endhint %}

## SDK 설치

Unity Package Manager를 통해 SDK 설치가 필요합니다.

[여기](https://github.com/hackle-io/unity-sdk/raw/master/hackle-unity-sdk-1.9.1.unitypackage)를 클릭하여, SDK를 다운로드 받습니다.

Unity에서 `Assets > Import Package > Custom Package`를 클릭합니다.\
다운받은 package를 선택하고, import 하면 설치가 완료됩니다.

![](https://2738466581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLHRZjjknm5KdNgPtDsbl%2Fuploads%2Fgit-blob-d93181ab6db02167ae6f728a719e38914b0dd119%2F21e8f2b-_2022-04-18_00.01.03_c489bbe305fded8d.png?alt=media)

#### Android ProGuard / R8

ProGuard, R8을 사용하는 경우, aar 아티팩트에 난독화 규칙이 자동으로 포함됩니다. 이 경우가 아니라면 아래 규칙을 포함시켜야 합니다.

```
-keep class io.hackle.android.** { *; }
-keep class io.hackle.sdk.** { *; }
```

{% hint style="info" %}
SDK 설치 후 앱 재설치

Unity SDK는 Android, iOS SDK가 포함되어 있습니다.\
기존에 테스트 중이던 앱을 새롭게 빌드해야 연동이 완료됩니다.
{% endhint %}

#### 업데이트 시 유의사항

![](https://2738466581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLHRZjjknm5KdNgPtDsbl%2Fuploads%2Fgit-blob-c593311b715db61cd0784ab6cd8133f1d93b6d1e%2F5235fed-_2022-10-31_20.43.51_5e726536fb346d22.png?alt=media)

업데이트를 하시는 경우, 기존 import 된 라이브러리 중 위의 선택된 라이브러리 삭제 후 다시 import 작업을 진행해야합니다.

* hackle-android-sdk-x.x.x
* hackle-android-unity-wrapper-x.x.x
* hackle-sdk-common-x.x.x
* hackle-sdk-core-x.x.x
* ios-arm64\_armv7
* ios-arm64\_i386\_x86\_64-simulator

#### Android SDK 의존성 관리

Android에서는 아래와 같은 의존성 라이브러리를 가지고 있습니다.\
Unity SDK가 Android 환경에서 동작을 하지 않는 경우 아래 라이브러리가 존재하는지 확인이 필요합니다.

* hackle-android-sdk-2.12.0
* hackle-android-unity-wrapper-1.5.0
* hackle-sdk-common-2.9.0
* hackle-sdk-core-2.9.0
* core-common
* gson
* kotlin-stdlib
* lifecycle-common
* lifecycle-extensions
* lifecycle-process
* lifecycle-runtime
* okhttp
* okio

## SDK 초기화

SDK를 사용하기 위해서 반드시 `Hackle`을 초기화 해야 합니다. `Hackle`을 초기화 하기 위해 SDK 키가 필요합니다.

* `Hackle`은 SDK의 기능을 사용하기 위한 메소드들을 제공하는 클래스입니다.
* `Initialize()` 메소드에 **SDK 키**를 전달하여 초기화하고, 초기화 완료 시까지 기다리기 위해 await를 합니다.
* SDK 키는 핵클 서비스의 대시보드 안에 위치한 [SDK 연동 정보](https://dashboard.hackle.io/config/sdk-setting)에서 확인하실 수 있습니다.

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HackleInit : MonoBehaviour
{
    async void Awake () {
        await Hackle.Initialize(YOUR_APP_SDK_KEY);
    }
}
```

### 초기화 설정정보

설정정보를 포함하여 SDK를 초기화 할 수 있습니다.

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HackleInit : MonoBehaviour
{
    async void Awake () {
      HackleConfig config = new HackleConfig.Builder()
        .Build();
      await Hackle.Initialize("YOUR_APP_SDK_KEY", config: config);
    }
}
```

#### 모든 설정 옵션

<table><thead><tr><th width="174.73828125">설정</th><th width="296.46484375">기능</th><th>기본값</th><th width="108.28125">지원 버전</th></tr></thead><tbody><tr><td>ExposureEventDedupIntervalMillis<sup>*</sup></td><td>동일한 사용자가 연속으로 발생시킨 동일한 A/B 테스트, 기능플래그 분배결과에 대한 노출 이벤트를 제거합니다.</td><td>60000 (1분)</td><td>1.7.0+</td></tr><tr><td>Debug</td><td>모든 기능에 대한 로그를 콘솔에 출력하고, 이벤트를 즉시 전송합니다.</td><td>false</td><td>1.7.0+</td></tr><tr><td>PollingIntervalMillis</td><td><p>대시보드에서 설정한 정보를 주기적으로<br>업데이트 할 수 있습니다.</p><p>최솟값 : 60000 (60초)</p></td><td>-1<br>(주기적으로 업데이트하지 않음)</td><td>1.7.0+</td></tr></tbody></table>

> <sup>\*</sup> 1.9.0 이후부터 앱 종료 후 재시작 시에도 지원합니다.)

### 인스턴스 가져오기

초기화 이후 아래 코드를 통해 `Hackle` 인스턴스를 가져올 수 있습니다.

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Hackle hackle = Hackle.GetInstance();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/unity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
