private UnityEngine.Material CreateMaterialFromXml(XElement xml, Tiled2Unity.ImportBehaviour importComponent) { // Does this material support alpha color key? bool useColorKey = xml.Attribute("alphaColorKey") != null; bool usesDepthShader = ImportUtils.GetAttributeAsBoolean(xml, "usesDepthShaders", false); // Determine which shader we sould be using string shaderName = "Tiled2Unity/"; // Are we using depth shaders? if (usesDepthShader) { shaderName += "Depth"; } else { shaderName += "Default"; } // Are we using color key shaders? Color keyColor = Color.black; if (useColorKey) { keyColor = ImportUtils.GetAttributeAsColor(xml, "alphaColorKey"); shaderName += " Color Key"; } // Try creating the material with the right shader. Fall back to the built-in Sprites/Default shader if there's a problem. UnityEngine.Material material = null; try { material = new UnityEngine.Material(UnityEngine.Shader.Find(shaderName)); } catch (Exception e) { importComponent.RecordError("Error creating material with shader '{0}'. {1}", shaderName, e.Message); } if (material == null) { importComponent.RecordWarning("Using default sprite shader for material"); material = new UnityEngine.Material(UnityEngine.Shader.Find("Sprites/Default")); } if (useColorKey) { material.SetColor("_AlphaColorKey", keyColor); } return(material); }
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); } }