Version: 2022.1
言語: 日本語
Introducing Java and Kotlin source plug-ins
Call Java and Kotlin plug-in code from C# scripts

Create a Java or Kotlin source plug-in

This page explains how to indicate to Unity to create a plug-in from a Java (.java) or Kotlin (.kt) source file.

  1. In the Assets folder, place your Java (.java) or Kotlin (.kt) source file.
    Tip: It’s best practice to create a sub-folder to contain your Java and Kotlin source files.
  2. Select the source file and view it in the Inspector window.
  3. In the Inspector, under the Select Platforms for plugin section, enable Android.
  4. 適用 を選択します。

Note: You can place the source files in any folder in your Project, except in special use locations such as StreamingAssets. If you place files in these locations, the Unity Editor doesn’t display the plug-in inspector.

Edit Java or Kotlin files in an exported Android Studio project

By default when you export a Unity project for Android, Unity copies any Java/Kotlin files over to the Android Studio project. If you edit these files in Android Studio, the changes are not reflected in the original files in the Unity project. If you export the Unity project again, the export process will overwrite your changes in Android Studio.

To resolve this, Unity provides the Symlink Sources Build Setting. If you select this Build Setting, Unity creates a symbolic link in the Android Studio project to Java/Kotlin files in the Unity project, instead of copying files over. This means that if you edit the files from Android Studio, the edit affects the files in the original Unity project.

Additional resource

Introducing Java and Kotlin source plug-ins
Call Java and Kotlin plug-in code from C# scripts
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961