private void ImportTexturesFromXml(XDocument xml) { var texData = xml.Root.Elements("ImportTexture"); foreach (var tex in texData) { string name = tex.Attribute("filename").Value; string data = tex.Value; // The data is gzip compressed base64 string. We need the raw bytes. //byte[] bytes = ImportUtils.GzipBase64ToBytes(data); byte[] bytes = ImportUtils.Base64ToBytes(data); // Save and import the texture asset { string pathToSave = ImportUtils.GetTexturePath(name); ImportUtils.ReadyToWrite(pathToSave); File.WriteAllBytes(pathToSave, bytes); AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport); } // Create a material if needed in prepartion for the texture being successfully imported { string materialPath = ImportUtils.GetMaterialPath(name); Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material; if (material == null) { // We need to create the material afterall // Use our custom shader material = new Material(Shader.Find("Tiled/TextureTintSnap")); ImportUtils.ReadyToWrite(materialPath); AssetDatabase.CreateAsset(material, materialPath); } } } }