// This must be called in order for rotation and position offset to by applied
        public void RenderPoints(SuperTile tile, GridOrientation orientation, Vector2 gridSize)
        {
            if (orientation == GridOrientation.Isometric)
            {
                m_Position = IsometricTransform(m_Position, tile, gridSize);
                m_Position.x += gridSize.x * 0.5f;

                for (int i = 0; i < m_Points.Length; i++)
                {
                    m_Points[i] = IsometricTransform(m_Points[i], tile, gridSize);
                }

                // Also, we are forced to use polygon colliders for isometric projection
                if (m_CollisionShapeType == CollisionShapeType.Ellipse || m_CollisionShapeType == CollisionShapeType.Rectangle)
                {
                    m_CollisionShapeType = CollisionShapeType.Polygon;
                }
            }

            // Burn rotation into our points
            ApplyRotationToPoints();

            // Burn translation into our points
            m_Points = m_Points.Select(p => p + m_Position).ToArray();

            // Transform all points so that they wrt the bottom-left of the tile
            // This should make calculations later easier since Tiled treats the bottom-left corner of a tile as the local origin
            m_Points = m_Points.Select(p => LocalTransform(p, tile)).ToArray();
            m_Position = LocalTransform(m_Position, tile);
        }
Example #2
0
        private Vector2 IsometricTransform(Vector2 pt, SuperTile tile, Vector2 gridSize)
        {
            float cx = pt.x / tile.m_Width;
            float cy = pt.y / tile.m_Height;

            float x = (cx - cy) * gridSize.x;
            float y = (cx + cy) * gridSize.y;

            return(new Vector2(x, y));
        }
        public static bool GetPropertyValueAsBool(this SuperTile tile, string propName, bool defaultValue)
        {
            CustomProperty property;

            if (TryGetProperty(tile, propName, out property))
            {
                return(property.GetValueAsBool());
            }

            return(defaultValue);
        }
        public static float GetPropertyValueAsFloat(this SuperTile tile, string propName, float defaultValue)
        {
            CustomProperty property;

            if (TryGetProperty(tile, propName, out property))
            {
                return(property.GetValueAsFloat());
            }

            return(defaultValue);
        }
        public static T GetPropertyValueAsEnum <T>(this SuperTile tile, string propName, T defaultValue)
        {
            CustomProperty property;

            if (TryGetProperty(tile, propName, out property))
            {
                return(property.GetValueAsEnum <T>());
            }

            return(defaultValue);
        }
        public static Color GetPropertyValueAsColor(this SuperTile tile, string propName, Color defaultValue)
        {
            CustomProperty property;

            if (TryGetProperty(tile, propName, out property))
            {
                return(property.GetValueAsColor());
            }

            return(defaultValue);
        }
        private Vector2 IsometricTransform(Vector2 pt, SuperTile tile,Vector2 gridSize)
        {
            float cx = pt.x / gridSize.y;
            float cy = pt.y / gridSize.y;

            float x = (cx - cy) * gridSize.x * 0.5f;
            float y = (cx + cy) * gridSize.y * 0.5f;

            y += (tile.m_Height - gridSize.y) * 0.5f;

            return new Vector2(x, y);
        }
        public static bool TryGetProperty(this SuperTile tile, string propName, out CustomProperty property)
        {
            property = null;

            if (tile == null)
            {
                return(false);
            }

            if (tile.m_CustomProperties == null)
            {
                return(false);
            }

            if (tile.m_CustomProperties.TryGetProperty(propName, out property))
            {
                return(true);
            }

            return(false);
        }
Example #9
0
        // This must be called in order for rotation and position offset to by applied
        public void RenderPoints(SuperTile tile, MapOrientation orientation, Vector2 gridSize)
        {
            if (orientation == MapOrientation.Isometric)
            {
                m_Position    = IsometricTransform(m_Position, tile, gridSize);
                m_Position.x += gridSize.x * 0.5f;
                m_Position.y += tile.m_Height - gridSize.y;

                for (int i = 0; i < m_Points.Length; i++)
                {
                    m_Points[i] = IsometricTransform(m_Points[i], tile, gridSize);
                }

                // Also, we are forced to use polygon colliders for isometric projection
                if (m_CollisionShapeType == CollisionShapeType.Ellipse || m_CollisionShapeType == CollisionShapeType.Rectangle)
                {
                    m_CollisionShapeType = CollisionShapeType.Polygon;
                }
            }

            ApplyRotationToPoints();
            m_Points = m_Points.Select(p => p + m_Position).ToArray();
        }
 private Vector2 LocalTransform(Vector2 pt, SuperTile tile)
 {
     return new Vector2(pt.x, tile.m_Height - pt.y);
 }
 public static Color GetPropertyValueAsColor(this SuperTile tile, string propName)
 {
     return(GetPropertyValueAsColor(tile, propName, Color.clear));
 }
 public static float GetPropertyValueAsFloat(this SuperTile tile, string propName)
 {
     return(GetPropertyValueAsFloat(tile, propName, 0));
 }
 public static bool GetPropertyValueAsBool(this SuperTile tile, string propName)
 {
     return(GetPropertyValueAsBool(tile, propName, false));
 }
 public static string GetPropertyValueAsString(this SuperTile tile, string propName)
 {
     return(GetPropertyValueAsString(tile, propName, string.Empty));
 }
 public static T GetPropertyValueAsEnum <T>(this SuperTile tile, string propName)
 {
     return(GetPropertyValueAsEnum(tile, propName, default(T)));
 }