Пример #1
0
        private bool SortNewLayerFromSource(SuperLayer source, SuperLayer target)
        {
            if (source == null)
            {
                return(false);
            }

            // Use an explicit property to set the sorting layer
            CustomProperty property;

            if (source.gameObject.TryGetCustomPropertySafe("unity:sortingLayerName", out property))
            {
                // When using an explicit custom property for sorting layer then we make sure the out property name is a recognized sorting layer
                if (!m_SortingLayers.ContainsKey(property.m_Value))
                {
                    m_SortingLayers.Add(property.m_Value, 0);
                }

                return(SortWithName(target, property.m_Value));
            }

            // Test if there is a match based on source layer name
            if (m_SortingLayers.ContainsKey(source.m_TiledName))
            {
                return(SortWithName(target, source.m_TiledName));
            }

            return(false);
        }
        public static void SetWorldPosition(this SuperLayer layer, SuperMap map, SuperImportContext context)
        {
            // Accumlate positions up the tree
            Vector3 position_w = new Vector3();

            foreach (var parent in layer.gameObject.GetComponentsInParent <SuperLayer>())
            {
                position_w   += (Vector3)context.MakePoint(parent.m_OffsetX, parent.m_OffsetY);
                position_w.z += parent.gameObject.GetSuperPropertyValueFloat(StringConstants.Unity_ZPosition, 0);
            }

            // Add an additional offset if our tileset is present. These coordinates have already been transformed.
            if (layer is SuperTileLayer || layer.GetComponent <Tilemap>() != null || layer.GetComponent <SuperTilesAsObjectsTilemap>() != null)
            {
                position_w += context.TilemapOffset;
            }

            layer.transform.position = position_w;

            // This sucks but we have to correct for isometric orientation for image layers
            if (layer is SuperImageLayer && map.m_Orientation == MapOrientation.Isometric)
            {
                float dx = context.MakeScalar(map.m_Height * map.m_TileHeight);
                layer.transform.Translate(-dx, 0, 0);
            }
        }
Пример #3
0
        private void ProcessMapLayers(GameObject goParent, XElement xMap)
        {
            // Note that this method is re-entrant due to group layers
            foreach (XElement xNode in xMap.Elements())
            {
                if (!xNode.GetAttributeAs <bool>("visible", true))
                {
                    continue;
                }

                LayerIgnoreMode ignoreMode = xNode.GetPropertyAttributeAs(StringConstants.Unity_Ignore, SuperImportContext.LayerIgnoreMode);
                if (ignoreMode == LayerIgnoreMode.True)
                {
                    continue;
                }

                using (SuperImportContext.BeginLayerIgnoreMode(ignoreMode))
                {
                    SuperLayer layer = null;

                    if (xNode.Name == "layer")
                    {
                        layer = ProcessTileLayer(goParent, xNode);
                    }
                    else if (xNode.Name == "group")
                    {
                        layer = ProcessGroupLayer(goParent, xNode);
                    }
                    else if (xNode.Name == "objectgroup")
                    {
                        layer = ProcessObjectLayer(goParent, xNode);
                    }
                    else if (xNode.Name == "imagelayer")
                    {
                        layer = ProcessImageLayer(goParent, xNode);
                    }

                    if (layer != null)
                    {
                        CustomProperty zprop;
                        if (layer.gameObject.TryGetCustomPropertySafe(StringConstants.Unity_ZPosition, out zprop))
                        {
                            float zpos = zprop.GetValueAsFloat();
                            layer.gameObject.transform.Translate(0, 0, zpos);
                        }
                    }
                }
            }
        }
Пример #4
0
        private bool SortWithName(SuperLayer layer, string name)
        {
            Assert.IsNotNull(layer);
            Assert.IsTrue(m_SortingLayers.ContainsKey(name));

            var order = m_SortingLayers[name];

            layer.m_SortingLayerName = name;
            layer.m_SortingOrder     = order;

            // Increment for next use
            m_SortingLayers[name] = order + 1;

            return(true);
        }
Пример #5
0
        public void SortNewLayer(SuperLayer layer)
        {
            // Determine sorting layer using our own data
            bool sorted = SortNewLayerFromSource(layer, layer);

            if (!sorted)
            {
                // Determine sorting layer using parent data
                sorted = SortNewLayerFromSource(layer.GetComponentInAncestor <SuperLayer>(), layer);
            }

            if (!sorted)
            {
                // Just sort with the default sorting layer
                SortWithName(layer, DefaultLayerName);
            }
        }
        public static void SetWorldPosition(this SuperLayer layer, SuperImportContext context)
        {
            // Accumlate positions up the tree
            Vector3 position_w = new Vector3();

            foreach (var parent in layer.gameObject.GetComponentsInParent <SuperLayer>())
            {
                position_w   += (Vector3)context.MakePoint(parent.m_OffsetX, parent.m_OffsetY);
                position_w.z += parent.gameObject.GetSuperPropertyValueFloat(StringConstants.Unity_ZPosition, 0);
            }

            // Add an additional offset if our tileset is present. These coordinates have already been transformed.
            if (layer is SuperTileLayer || layer.GetComponent <Tilemap>() != null || layer.GetComponent <SuperTilesAsObjectsTilemap>() != null)
            {
                position_w += context.TilemapOffset;
            }

            layer.transform.position = position_w;
        }