예제 #1
0
        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 = GetTextureAssetPath(name);
                    ImportUtils.ReadyToWrite(pathToSave);
                    File.WriteAllBytes(pathToSave, bytes);
                    AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
                }

                // Create a material in prepartion for the texture being successfully imported
                {
                    // We need to recreate the material every time because the Tiled Map may have changed
                    string   materialPath = GetMaterialAssetPath(name);
                    Material material     = CreateMaterialFromXml(tex);
                    ImportUtils.ReadyToWrite(materialPath);
                    ImportUtils.CreateOrReplaceAsset(material, materialPath);
                }
            }
        }
예제 #2
0
        private void ImportAllTextures(Tiled2Unity.ImportBehaviour importComponent)
        {
            // Textures need to be imported before we can create or import materials
            foreach (var xmlImportTexture in importComponent.XmlDocument.Root.Elements("ImportTexture"))
            {
                string filename = ImportUtils.GetAttributeAsString(xmlImportTexture, "filename");
                string data     = xmlImportTexture.Value;
                byte[] bytes    = ImportUtils.Base64ToBytes(data);

                // Keep track that we are importing this texture
                if (!importComponent.ImportWait_Textures.Contains(filename, StringComparer.OrdinalIgnoreCase))
                {
                    importComponent.ImportWait_Textures.Add(filename);
                }

                // Start the import process for this texture
                string pathToSave = GetTextureAssetPath(filename);
                ImportUtils.ReadyToWrite(pathToSave);
                File.WriteAllBytes(pathToSave, bytes);
                importComponent.ImportTiled2UnityAsset(pathToSave);
            }

            // If we have no textures too import then go to next stage (materials)
            if (importComponent.ImportWait_Textures.Count() == 0)
            {
                ImportAllMaterials(importComponent);
            }
        }
예제 #3
0
        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 = GetTextureAssetPath(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 (NOTICE: Only if this is not a normal map)
                if (!name.Contains(ImportTiled2Unity.TiledNormalMapFileIdentification))
                {
                    string   materialPath = GetMaterialAssetPath(name);
                    Material material     = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
                    if (material == null)
                    {
                        // We need to create the material afterall
                        // Use our custom shader
                        if (ImportTiled2Unity.ProcessingNormalMaps)
                        {
                            material = new Material(Shader.Find("Tiled/TextureTintSnapNormal"));
                        }
                        else
                        {
                            material = new Material(Shader.Find("Tiled/TextureTintSnap"));
                        }
                        ImportUtils.ReadyToWrite(materialPath);
                        AssetDatabase.CreateAsset(material, materialPath);
                    }
                }
            }
        }
예제 #4
0
        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 = GetTextureAssetPath(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 = GetMaterialAssetPath(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 = CreateMaterialFromXml(tex);
                        ImportUtils.ReadyToWrite(materialPath);
                        AssetDatabase.CreateAsset(material, materialPath);
                    }
                }
            }
        }