Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void AddObjectLayerComponentsTo(GameObject gameObject, XElement goXml)
        {
            var xml = goXml.Element("ObjectLayer");

            if (xml != null)
            {
                Tiled2Unity.ObjectLayer objectLayer = gameObject.AddComponent <Tiled2Unity.ObjectLayer>();
                objectLayer.Color = ImportUtils.GetAttributeAsColor(xml, "color", Color.black);
                SetLayerComponentProperties(objectLayer, xml);
            }
        }
        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);
        }