예제 #1
0
        private void HandleTiledAttributes(GameObject gameObject, XElement goXml, Tiled2Unity.ImportBehaviour importComponent)
        {
            // Add the TiledMap component
            TiledMap map = gameObject.AddComponent <TiledMap>();

            try
            {
                map.Orientation       = ImportUtils.GetAttributeAsEnum <TiledMap.MapOrientation>(goXml, "orientation");
                map.StaggerAxis       = ImportUtils.GetAttributeAsEnum <TiledMap.MapStaggerAxis>(goXml, "staggerAxis");
                map.StaggerIndex      = ImportUtils.GetAttributeAsEnum <TiledMap.MapStaggerIndex>(goXml, "staggerIndex");
                map.HexSideLength     = ImportUtils.GetAttributeAsInt(goXml, "hexSideLength");
                map.NumLayers         = ImportUtils.GetAttributeAsInt(goXml, "numLayers");
                map.NumTilesWide      = ImportUtils.GetAttributeAsInt(goXml, "numTilesWide");
                map.NumTilesHigh      = ImportUtils.GetAttributeAsInt(goXml, "numTilesHigh");
                map.TileWidth         = ImportUtils.GetAttributeAsInt(goXml, "tileWidth");
                map.TileHeight        = ImportUtils.GetAttributeAsInt(goXml, "tileHeight");
                map.ExportScale       = ImportUtils.GetAttributeAsFloat(goXml, "exportScale");
                map.MapWidthInPixels  = ImportUtils.GetAttributeAsInt(goXml, "mapWidthInPixels");
                map.MapHeightInPixels = ImportUtils.GetAttributeAsInt(goXml, "mapHeightInPixels");
                map.BackgroundColor   = ImportUtils.GetAttributeAsColor(goXml, "backgroundColor", Color.black);
            }
            catch
            {
                importComponent.RecordWarning("Couldn't add TiledMap component. Are you using an old version of Tiled2Unity in your Unity project?");
                GameObject.DestroyImmediate(map);
            }
        }
 private void CheckSettings(Tiled2Unity.ImportBehaviour importComponent)
 {
     // Check anti-aliasing
     if (QualitySettings.antiAliasing != 0)
     {
         importComponent.RecordWarning("Anti-aliasing is enabled and may cause seams. See Edit->Project Settings->Quality to disable.");
     }
 }
        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);
            }
        }