기본 Unity 활동을 확장하려면 자신만의 커스텀 활동을 만들고 이를 애플리케이션의 엔트리 포인트로 설정합니다.이를 위한 절차는 다음과 같습니다.
UnityPlayerActivity
클래스를 확장하는 새 활동을 생성합니다.activity
를 애플리케이션의 엔트리 포인트로 설정합니다.그 다음에는 활동에서 커스텀 활동을 구현하여 Unity와 Android 간의 상호 작용을 제어할 수 있습니다.
새 활동을 생성하려면:
.java
) 또는 Kotlin (.kt
) 파일을 생성합니다.UnityPlayerActivity
를 연장하는 클래스를 생성합니다.다음 코드 샘플은 여러 함수를 오버라이드하는 활동의 예를 보여줍니다.
package com.company.product;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;
public class OverrideExample extends UnityPlayerActivity {
protected void onCreate(Bundle savedInstanceState) {
// Calls UnityPlayerActivity.onCreate()
super.onCreate(savedInstanceState);
// Prints debug message to Logcat
Log.d("OverrideActivity", "onCreate called!");
}
public void onBackPressed()
{
// Instead of calling UnityPlayerActivity.onBackPressed(), this example ignores the back button event
// super.onBackPressed();
}
}
Unity Android 애플리케이션에 커스텀 활동을 사용하려면 해당 활동을 포함할 플러그인을 만들어야 합니다.활동은 Java 또는 Kotlin으로 작성되므로 다음 타입의 플러그인 중 하나를 사용해야 합니다.
단일 프로젝트에 대한 커스텀 활동을 만들려면 Java 및 Kotlin 소스 플러그인을 사용하십시오.소스 플러그인을 만들려면 소스 파일을 프로젝트의 Assets 폴더에 직접 배치하십시오.
여러 프로젝트에서 활동을 재사용하거나 다른 사람에게 배포하려면 Android 아카이브(AAR) 또는 JAR 플러그인을 사용하십시오.하나의 AAR 또는 JAR 플러그인 파일을 관리하면 여러 프로젝트에서 기능을 더 쉽게 제공할 수 있습니다.
플러그인을 개발하는 동안에는 Android 라이브러리 프로젝트를 사용하고 구현을 완료하거나 여러 프로젝트에서 사용하거나 다른 사람에게 배포하려는 경우 Android 아카이브 플러그인으로 컴파일하십시오.
플러그인을 만든 후 활동 파일을 추가합니다.
활동을 만들고 플러그인에 추가한 후에는 이를 애플리케이션 엔트리 포인트로 설정할 수 있습니다.이렇게 하려면 Android 매니페스트를 오버라이드하고 활동 요소의 name
속성을 자신의 커스텀 활동의 클래스명으로 설정하십시오.
다음 Android 매니페스트 예제가 이 방법을 보여줍니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.product">
<application android:icon="@drawable/app_icon" android:label="@string/app_name">
<activity android:name="com.YourPackage.name.OverrideExample"
android:theme="@style/UnityThemeSelector"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.