我一直試圖在編輯器腳本中實現一個簡單的Resources.Load調用,但它仍繼續返回null,儘管我嘗試了許多不同的方法。Resources.Load在編輯器腳本中返回null
目的
用戶增加.JPG的一個文件夾中的項目,在這種情況下資產/資源/ 360Photos
後處理腳本檢測該文件,適用立方體貼圖進口設置到它
腳本將創建一個天空盒/立方體貼圖材質並應用紋理t ○材料
我已擊中越來越紋理對象它已經經過後處理的作爲一個立方體貼圖,以及如何將被應用到空中包廂/立方體貼圖陰影的_Tex屬性的路障材質,因爲我似乎甚至無法加載與我導入並處理到立方體貼圖的紋理相關的資源。
是否有可能在Unity編輯器腳本中使用Resources.Load(特別是AssetPostProcessor)還是我試圖執行僅在運行時可用的功能?
如果有人可以查看我的代碼,並查看我提供的Unity截圖,那將非常感激。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Postprocess360Photo : AssetPostprocessor {
void OnPostprocessTexture(Texture2D texture)
{
string lowerCaseAssetPath = assetPath.ToLower();
bool isIn360PhotoDirectory = lowerCaseAssetPath.IndexOf ("360photos") != -1;
if (isIn360PhotoDirectory)
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.textureType = TextureImporterType.Default;
textureImporter.textureShape = TextureImporterShape.TextureCube;
textureImporter.generateCubemap = TextureImporterGenerateCubemap.Cylindrical;
textureImporter.sRGBTexture = true;
textureImporter.alphaSource = TextureImporterAlphaSource.FromInput;
textureImporter.alphaIsTransparency = true;
textureImporter.npotScale = TextureImporterNPOTScale.ToSmaller;
textureImporter.isReadable = true;
textureImporter.mipmapEnabled = false;
textureImporter.wrapMode = TextureWrapMode.Clamp;
textureImporter.filterMode = FilterMode.Bilinear;
}
AssetDatabase.ImportAsset (assetPath);
CreateMaterial();
}
void CreateMaterial()
{
Cubemap cubemap = (Cubemap)Resources.Load ("360Photos/FrontDriveway");
Debug.Log (cubemap);
}
}
請參閱圖像的層次結構,並返回null值的控制檯驗證: -
使用Unity 5.5.0f3是否有幫助。
可以嘗試'立方體貼圖立方體貼圖= Resources.Load(「360Photos/FrontDriveway」)作爲立方體貼圖;'而在檢查檢查你的資源「紋理類型」爲「立方體貼圖」 – Chong
嗨@Chong,感謝您的答覆。 我按照你所說的嘗試了代碼,但仍然沒有結果。檢查器紋理類型中不再有類型「Cubemap」,我認爲他們改變了Unity 5.5,並且類型爲默認值,具有立方體的紋理形狀。 如果需要,請參閱圖像鏈接: - http://imgur.com/a/A4aYj – AndrewMMG
FrontDriveway文件的格式/擴展名是什麼?另外,這是您現在在項目中使用的確切代碼嗎? – Programmer