我正在嘗試從本地路徑進行簡單的匯入。不知道我在哪里搞砸了。我不是最強的編碼員,所以任何見解都值得贊賞。下面是我的嘗試。
[MenuItem("ImportMenu/ImportAsset")]
static void ImportAssetOnlyImportsSingleAsset()
{
// My asset package file name
string fileName = "MyAsset.unitypackage";
// Project Asset folder path to save file to
var assetsPath = Application.dataPath "/" fileName;
Debug.Log($"Application.dataPath: {Application.dataPath}");
// Where my asset package is located
var filePath = "D:/Local_Projects/Packages/MyAsset";
// Import asset
AssetDatabase.ImportAsset(filePath);
//Debug.Log("Imported: " importedAssets);
}
uj5u.com熱心網友回復:
AssetDatabase只能從專案根目錄的檔案中加載。這些是資產或包。如果您的專案不直接在Local_Projects其中,它將無法正常作業。
從檔案
所有路徑都相對于專案檔案夾,例如:“Assets/MyTextures/hello.png”
你可以做的就是把這個包的內容復制到專案的目錄下。
File.Copy(fileToCopy, destinationFile); // or File.Move(...)
AssetDatabase.ImportAsset(destinationFile);
// Do something with this asset
// Optionaly
File.Remove(destinationFile);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/409450.html
標籤:
