I'm currently working on an editor script that will ease my transition between freemium and paid versions of my game.I would like to manually import the .unitypackage file that gets imported when I click the import button under Services -> In-App Purchasing.
I am aware of the function AssetDatabase.ImportAsset(path)
but I need the path of the package first.
Thanks in advance!
When you enable IAP and click Import, the following will happen:
1.Unity will generate a random file name with
2.A full path will be constructed like this:
3.Unity will then add .unitypackage to the end of that random file name.
Now, you have something like:
4.IAP package will then be downloaded and stored to path from #3.
Illustration of what it looks like:
5.The file is then copied to
It is saved with the file name generated from #2. No .unitypackage at the end like #3.
6.After that, Unity imports it with
AssetDatabase.ImportPackage
notAssetDatabase.ImportAsset(path,false)
as mentioned in your question.Now you can see where Unity IAP package is located but there are just few problems in what you are trying to do:
1.For the IAP package to be present, the import button from the Services Tab must be clicked. I am sure you want this to be automated.
2.The file name is not static therefore making the path hard to retrieve. As you can see from the image above, there are other files in this folder too. We don't know which one is the AIP Package.
3.When you re-start Unity, the temp folder will be deleted. So the downloaded IAP package will be lost.
The best way to get the Unity IAP package is to download it directly from Unity's server then save it to your preferred location. The code below will download the IAP package and store it at:
<ProjectName>/UnityEngine.Cloud.Purchasing.unitypackage
It will also import it and then, enable it. For AIP to work, Analytics must be enabled too. This code will also do that.I tried to hide the AIP
url
so that it won't be abused and Unity won't have change it.If you want to remake this into something else, the two most important functions to look at are
downloadAndInstallAIP()
anddeleteAndDisableAIP()
.AIPDownloader Code: