// We have many independent requests on the ImportBehaviour so we can't take for granted it has been created yet. // However, if it has been created then use it. public static ImportBehaviour FindOrCreateImportBehaviour(string xmlPath) { string importName = ImportBehaviour.GetFilenameWithoutTiled2UnityExtension(xmlPath); // Try to find foreach (ImportBehaviour status in UnityEngine.Object.FindObjectsOfType <ImportBehaviour>()) { if (String.Compare(status.ImportName, importName, true) == 0) { return(status); } } // Couldn't find, so create. GameObject gameObject = new GameObject("__temp_tiled2unity_import"); #if !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_2 && !UNITY_4_3 gameObject.transform.SetAsFirstSibling(); #endif ImportBehaviour importStatus = gameObject.AddComponent <ImportBehaviour>(); importStatus.ImportName = importName; // Opening the XDocument itself can be expensive so start the progress bar just before we start importStatus.StartProgressBar(xmlPath); importStatus.XmlDocument = XDocument.Load(xmlPath); importStatus.numberOfElements = importStatus.XmlDocument.Element("Tiled2Unity").Elements().Count(); importStatus.IncrementProgressBar(xmlPath); return(importStatus); }