private void ImportAllMeshes(Tiled2Unity.ImportBehaviour importComponent)
        {
            foreach (var xmlMesh in importComponent.XmlDocument.Root.Elements("ImportMesh"))
            {
                // We're going to create/write a file that contains our mesh data as a Wavefront Obj file
                // The actual mesh will be imported from this Obj file
                string file = ImportUtils.GetAttributeAsString(xmlMesh, "filename");
                string data = xmlMesh.Value;

                // Keep track of mesh we're going to import
                if (!importComponent.ImportWait_Meshes.Contains(file))
                {
                    importComponent.ImportWait_Meshes.Add(file);
                }

                // The data is in base64 format. We need it as a raw string.
                string raw = ImportUtils.Base64ToString(data);

                // Save and import the asset
                string pathToMesh = GetMeshAssetPath(file);
                ImportUtils.ReadyToWrite(pathToMesh);
                File.WriteAllText(pathToMesh, raw, Encoding.UTF8);
                importComponent.ImportTiled2UnityAsset(pathToMesh);
            }

            // If we have no meshes to import then go to next stage
            if (importComponent.ImportWait_Meshes.Count() == 0)
            {
                ImportAllPrefabs(importComponent, null);
            }
        }
예제 #2
0
        private void ImportMeshesFromXml(XDocument xml)
        {
            var meshData = xml.Root.Elements("ImportMesh");

            foreach (var mesh in meshData)
            {
                // We're going to create/write a file that contains our mesh data as a Wavefront Obj file
                // The actual mesh will be imported from this Obj file

                string fname = mesh.Attribute("filename").Value;
                string data  = mesh.Value;

                // The data is in base64 format. We need it as a raw string.
                string raw = ImportUtils.Base64ToString(data);

                // Save and import the asset
                string pathToMesh = GetMeshAssetPath(fname);
                ImportUtils.ReadyToWrite(pathToMesh);
                File.WriteAllText(pathToMesh, raw, Encoding.UTF8);
                AssetDatabase.ImportAsset(pathToMesh, ImportAssetOptions.ForceSynchronousImport);
            }
        }