public void ConvertImages() { // directories string aNamePrefab = "photo.prefab"; string aName = string.Format("{0:yyyyMMdd_HHmmss}", DateTime.Now); string aDirectory = "Assets/kolmich/KGFMapSystem/photocache/" + aName + "/"; string aDirectoryTextures = aDirectory + "textures/"; string aDirectoryMaterials = aDirectory + "materials/"; string aDirectoryPrefabs = aDirectory + "prefabs/"; Directory.CreateDirectory(aDirectoryTextures); Directory.CreateDirectory(aDirectoryMaterials); Directory.CreateDirectory(aDirectoryPrefabs); KGFMapSystem.KGFPhotoData [] aData = itsTarget.GetPhotoData(); for (int i = 0; i < aData.Length; i++) { // texture string aFilePathTexture = aDirectoryTextures + i + ".png"; byte[] bt = aData[i].itsTexture.EncodeToPNG(); File.WriteAllBytes(aFilePathTexture, bt); AssetDatabase.ImportAsset(aFilePathTexture); TextureImporter anImporter = TextureImporter.GetAtPath(aFilePathTexture) as TextureImporter; anImporter.wrapMode = TextureWrapMode.Clamp; AssetDatabase.ImportAsset(aFilePathTexture); // material aData[i].itsTexture = AssetDatabase.LoadAssetAtPath(aFilePathTexture, typeof(Texture2D)) as Texture2D; aData[i].itsPhotoPlaneMaterial.mainTexture = aData[i].itsTexture; // AssetDatabase.CreateAsset((Texture2D)(aData[i].itsTexture),"Assets/t"+i+".png"); AssetDatabase.CreateAsset(aData[i].itsPhotoPlaneMaterial, aDirectoryMaterials + i + ".mat"); } // prefab UnityEngine.Object aPrefab = PrefabUtility.CreatePrefab(aDirectoryPrefabs + aNamePrefab, itsTarget.GetPhotoParent(), ReplacePrefabOptions.ConnectToPrefab); // Mesh Mesh aMesh = null; for (int i = 0; i < aData.Length; i++) { if (aMesh == null) { // save first mesh we find to prefab aMesh = aData[i].itsPhotoPlane.GetComponent <MeshFilter>().sharedMesh; aMesh.name = "SimplePlaneMesh"; AssetDatabase.AddObjectToAsset(aMesh, aDirectoryPrefabs + aNamePrefab); AssetDatabase.ImportAsset(aDirectoryPrefabs + aNamePrefab); // get link of mesh in prefab aMesh = AssetDatabase.LoadAssetAtPath(aDirectoryPrefabs + aNamePrefab, typeof(Mesh)) as Mesh; } else { // set all other meshfilters to use the mesh in the prefab aData[i].itsPhotoPlane.GetComponent <MeshFilter>().sharedMesh = aMesh; } } // save changes to prefab PrefabUtility.ReplacePrefab(itsTarget.GetPhotoParent(), aPrefab, ReplacePrefabOptions.ConnectToPrefab); }