private void CheckVersion(Tiled2Unity.ImportBehaviour importComponent, Tiled2Unity.ImportTiled2Unity importTiled2Unity)
        {
            try
            {
                // Get the version from our Tiled2Unity.export.txt library data file
                TextAsset textAsset = importTiled2Unity.GetTiled2UnityTextAsset();
                XDocument xml       = XDocument.Parse(textAsset.text);
                string    importerTiled2UnityVersion = xml.Element("Tiled2UnityImporter").Element("Header").Attribute("version").Value;

                if (importComponent.ExporterTiled2UnityVersion != importerTiled2UnityVersion)
                {
                    importComponent.RecordWarning("Imported Tiled2Unity file '{0}' was exported with version {1}. We are expecting version {2}", importComponent.Tiled2UnityXmlPath, importComponent.ExporterTiled2UnityVersion, importerTiled2UnityVersion);
                }
            }
            catch (Exception e)
            {
                importComponent.RecordError("Failed to read Tiled2Unity import version from '{0}': {1}", importComponent.Tiled2UnityXmlPath, e.Message);
            }
        }
예제 #2
0
        // Called when Unity detects the *.tiled2unity.xml file needs to be (re)imported
        public void ImportBegin(string xmlPath, Tiled2Unity.ImportTiled2Unity importTiled2Unity)
        {
            // Create a (tempoary) gameobject in the scene hierarchy that can manage state of the import process
            GameObject t2uImporter = new GameObject("__tiled2unity_importer");

#if !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_2 && !UNITY_4_3
            t2uImporter.gameObject.transform.SetAsFirstSibling();
#endif
            // Add the ImportBehaviour component. This will track the state of the importer and get everything to happen in the right order.
            var importComponent = t2uImporter.AddComponent <Tiled2Unity.ImportBehaviour>();

            // Load the XML and start the importing process
            if (LoadTiled2UnityXml(importComponent, xmlPath))
            {
                CheckVersion(importComponent, importTiled2Unity);

                // Start the import process by importing all our textures
                ImportAllTextures(importComponent);
            }
        }