Cloud Storage: Firebase (optional)
For a comprehensive guide on integrating Firebase with Unity, developers are encouraged to consult the official Firebase documentation. What follows in this tutorial is a concise overview tailored to our specific use case.
Create a Firebase Project
Visit the Firebase Console.
Click on "Add Project" and follow the prompts to fill in the project information.
Click "Create Project".
Add an App
On the project overview page, click "Add App" and select the appropriate platform (e.g., Android).
Follow the prompts to enter the app's package name and other information.
Download and save the configuration file (
google-services.json
) and place it in theAssets
folder.
Install the SDK
Download Firebase Unity SDK
Import
FirebaseStorage.unitypackage
into Unity.
Add Storage
Go to
Build > Storage
Click Get Started and set up cloud storage
The highlighted part in the following image is the folder location where we will upload the anchor file.
Upload/download files
We've developed a dedicated FirebaseStorageManager
class to facilitate file upload and download functionalities. For detailed implementation, you can refer to the official documentation.
It's important to note that whether you're uploading or downloading, the storagePath
should include the specific filename, not just the directory. This specification is also highlighted in the documentation.
Therefore, We set the file path obtained from the previous step as storageBasePath
and later concatenate it with the filename to form the complete path for upload/download.
Common Issues
After installing Firebase, building software in Unity may fail. This is a known issue with Android and requires adding
launcherTemplate.gradle
in Unity, then adding the following content:
Possible error may occur:
In this case, you need to update the Google Play Service of the mobile phone.