private void ImportAllMaterials(Tiled2Unity.ImportBehaviour importComponent) { // Create a material for each texture that has been imported foreach (var xmlTexture in importComponent.XmlDocument.Root.Elements("ImportTexture")) { bool isResource = ImportUtils.GetAttributeAsBoolean(xmlTexture, "isResource", false); string textureFile = ImportUtils.GetAttributeAsString(xmlTexture, "filename"); string materialPath = MakeMaterialAssetPath(textureFile, isResource); string materialFile = System.IO.Path.GetFileName(materialPath); // Keep track that we importing this material if (!importComponent.ImportWait_Materials.Contains(materialFile)) { importComponent.ImportWait_Materials.Add(materialFile); } // Create the material UnityEngine.Material material = CreateMaterialFromXml(xmlTexture, importComponent); // Assign the texture to the material { string textureAsset = GetTextureAssetPath(textureFile); AssignTextureAssetToMaterial(material, materialFile, textureAsset, importComponent); } ImportUtils.ReadyToWrite(materialPath); ImportUtils.CreateOrReplaceAsset(material, materialPath); importComponent.ImportTiled2UnityAsset(materialPath); } // Create a material for each internal texture foreach (var xmlInternal in importComponent.XmlDocument.Root.Elements("InternalTexture")) { bool isResource = ImportUtils.GetAttributeAsBoolean(xmlInternal, "isResource", false); string textureAsset = ImportUtils.GetAttributeAsString(xmlInternal, "assetPath"); string textureFile = System.IO.Path.GetFileName(textureAsset); string materialPath = MakeMaterialAssetPath(textureFile, isResource); string materialFile = System.IO.Path.GetFileName(materialPath); // Keep track that we importing this material if (!importComponent.ImportWait_Materials.Contains(materialFile)) { importComponent.ImportWait_Materials.Add(materialFile); } // Create the material and assign the texture UnityEngine.Material material = CreateMaterialFromXml(xmlInternal, importComponent); AssignTextureAssetToMaterial(material, materialFile, textureAsset, importComponent); ImportUtils.ReadyToWrite(materialPath); ImportUtils.CreateOrReplaceAsset(material, materialPath); importComponent.ImportTiled2UnityAsset(materialPath); } // If we have no materials to import then go to next stage (meshes) if (importComponent.ImportWait_Materials.Count() == 0) { ImportAllMeshes(importComponent); } }
private void ImportAllMaterials(Tiled2Unity.ImportBehaviour importComponent) { // Create a material for each texture that has been imported foreach (var xmlTexture in importComponent.XmlDocument.Root.Elements("ImportTexture")) { bool isResource = ImportUtils.GetAttributeAsBoolean(xmlTexture, "isResource", false); string textureFile = ImportUtils.GetAttributeAsString(xmlTexture, "filename"); string materialPath = MakeMaterialAssetPath(textureFile, isResource); string materialFile = System.IO.Path.GetFileName(materialPath); // Keep track that we importing this material if (!importComponent.ImportWait_Materials.Contains(materialFile, StringComparer.OrdinalIgnoreCase)) { importComponent.ImportWait_Materials.Add(materialFile); } // Create the material UnityEngine.Material material = CreateMaterialFromXml(xmlTexture, importComponent); // Assign the texture to the material { string textureAsset = GetTextureAssetPath(textureFile); AssignTextureAssetToMaterial(material, materialFile, textureAsset, importComponent); } ImportUtils.ReadyToWrite(materialPath); ImportUtils.CreateOrReplaceAsset(material, materialPath); importComponent.ImportTiled2UnityAsset(materialPath); } // Create a material for each internal texture foreach (var xmlInternal in importComponent.XmlDocument.Root.Elements("InternalTexture")) { bool isResource = ImportUtils.GetAttributeAsBoolean(xmlInternal, "isResource", false); string textureAsset = ImportUtils.GetAttributeAsString(xmlInternal, "assetPath"); string textureFile = System.IO.Path.GetFileName(textureAsset); string materialPath = MakeMaterialAssetPath(textureFile, isResource); // "Internal textures" may have a unique material name that goes with it string uniqueMaterialName = ImportUtils.GetAttributeAsString(xmlInternal, "materialName", ""); if (!String.IsNullOrEmpty(uniqueMaterialName)) { materialPath = String.Format("{0}/{1}{2}", Path.GetDirectoryName(materialPath), uniqueMaterialName, Path.GetExtension(materialPath)); materialPath = materialPath.Replace(System.IO.Path.DirectorySeparatorChar, '/'); } string materialFile = System.IO.Path.GetFileName(materialPath); // Keep track that we are importing this material if (!importComponent.ImportWait_Materials.Contains(materialFile, StringComparer.OrdinalIgnoreCase)) { importComponent.ImportWait_Materials.Add(materialFile); } // Create the material and assign the texture UnityEngine.Material material = CreateMaterialFromXml(xmlInternal, importComponent); AssignTextureAssetToMaterial(material, materialFile, textureAsset, importComponent); ImportUtils.ReadyToWrite(materialPath); ImportUtils.CreateOrReplaceAsset(material, materialPath); importComponent.ImportTiled2UnityAsset(materialPath); } // If we have no materials to import then go to next stage (meshes) if (importComponent.ImportWait_Materials.Count() == 0) { ImportAllMeshes(importComponent); } }