This guide explains how to create a Unity package using the Facebook SDK as an example. Follow these steps to create your own package.
- Import the Facebook SDK
.unitypackage
into your Unity project. - After importing, collect all the created folders and files (including meta files).
- Move these folders and files to a directory outside your Unity project. For example, create a folder named
FacebookSDK
on your drive and move them there.
Create a package.json
file in the FacebookSDK
folder with the following content:
{
"name": "com.facebook",
"version": "17.0.1",
"displayName": "Facebook SDK",
"keywords": [
"Facebook",
"SDK"
],
"author": {
"name": "Facebook",
"url": "https://developers.facebook.com/docs/unity/downloads/"
},
"description": "Facebook SDK (custom created package by @davitmk)",
"unity": "2021.1",
"dependencies": {
"com.google.external-dependency-manager": "1.2.181"
}
}
- Open any Unity project.
- Open any script in the Unity project.
- Call the following method in the script to create a .tgz file:
UnityEditor.PackageManager.Client.Pack("C:/FacebookSDK", "C:/FacebookSDK");
- Export the .tgz file content into a package folder next to it
Option 1: Open Unity Package Manager > Add package from git URL :
https://github.com/Davidnovarro/Unity-Packages.git?path=/Facebook/17.0.1/package
Option 2: Modify the manifest.json
to import the local .tgz as a package by adding the following line file:
"com.facebook": "file:../Assets/Packages/com.facebook.tgz"
⚠️ Warning: Unity ignores link.xml
files located in the Packages folder, which are used to preserve assembly files.
#if UNITY_EDITOR
using System.IO;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.UnityLinker;
namespace Facebook.Unity.PostProcess
{
public class PreservePackageXmLinkFile : IUnityLinkerProcessor
{
int IOrderedCallback.callbackOrder => 0;
string IUnityLinkerProcessor.GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data) => Path.GetFullPath("Packages/com.facebook/link.xml");
}
}
#endif