A common way to reference third-party libraries in Unity is to useAssembly Definition Files(程序集定义文件)
.
This is a mechanism provided by Unity that allows you to create your own assembly to reference and use third-party libraries in Unity projects. Here are some simple steps:
- In the Unity Editor, right-click on your Assets folder and select
Create
>Assembly Definition
. - Give the assembly definition file a name, such as
MyLibrary
. - Create a folder named
Plugins
in Unity and put the DLL file of the third-party library into it. - Right-click the newly created assembly definition file and select
Properties
. - In the list in the
General
section, click the button to add a citation.References
+
- Select the DLL file to be referenced and click
Add
. - Make sure the assembly definition file's
Auto Referenced
option is checked to ensure that Unity automatically references the dependency when building. - Click
Apply
to save changes.
Now, you can use the using
keyword in the script of the Unity project to reference the third-party library and use the types and functions in it.
Note that some third-party libraries may require additional setup or operations for correct use. Additionally, some third-party libraries may require platform-specific setup and import. Please read carefully the documentation of the third-party library you are using and follow its instructions.