舉例:
// 設定貼圖檔案的圖片壓縮格式 textureImporter.textureFormat = TextureImporterFormat.PVRTC_RGBA4; // 設定了Import Settings之後再使用AssetDatabase.ImportAsset進行asset的更新 AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate );
參考資料
// 設定貼圖檔案的圖片壓縮格式 textureImporter.textureFormat = TextureImporterFormat.PVRTC_RGBA4; // 設定了Import Settings之後再使用AssetDatabase.ImportAsset進行asset的更新 AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate );
// create material
Material newMaterial = new Material( Shader.Find("Diffuse"));
// assign shader
newMaterial.shader = sourceMaterial.shader;
// copy properties from existing material
newMaterial.CopyPropertiesFromMaterial(sourceMaterial);
// create texture from asset(asset path)
Texture texture = (Texture)AssetDatabase.LoadAssetAtPath( textureRelativePath, typeof(Texture));
// assign texture to material
newMaterial.SetTexture("_MainTex", texture);
// create material asset
AssetDatabase.CreateAsset(newMaterial, newMaterialAssetRelativePath);
// assign material to gameObject
AssignMaterial( gameObject, newMaterial );