Example #1
0
        public override Vector2 TileWorldPosition(LightTile tile)
        {
            Vector2 tilemapOffset = properties.transform.position;

            // Tile Offset
            Vector2 tileOffset = new Vector2(tile.gridPosition.x, tile.gridPosition.y);

            tileOffset.x += properties.cellAnchor.x;
            tileOffset.y += properties.cellAnchor.y;

            tileOffset.x += properties.cellGap.x * tile.gridPosition.x;
            tileOffset.y += properties.cellGap.y * tile.gridPosition.y;

            // Tile Position
            Vector2 tilePosition = tilemapOffset;

            tilePosition.x += tileOffset.x * 0.5f;
            tilePosition.x += tileOffset.y * -0.5f;
            tilePosition.x *= properties.cellSize.x;

            tilePosition.y += tileOffset.x * 0.5f * properties.cellSize.y;
            tilePosition.y += tileOffset.y * 0.5f * properties.cellSize.y;

            if (ZasY)
            {
                tilePosition.y += tile.gridPosition.z * 0.25f;
            }

            tilePosition.x *= properties.transform.lossyScale.x;
            tilePosition.y *= properties.transform.lossyScale.y;

            return(tilePosition);
        }
Example #2
0
        static public void MaskSprite(LightTile tile, LayerSetting layerSetting, Material material, LightTilemapCollider2D tilemap, float lightSizeSquared)
        {
            virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

            if (virtualSpriteRenderer.sprite == null)
            {
                return;
            }

            LightTilemapCollider.Base tilemapBase = tilemap.GetCurrentTilemap();

            Vector2 tilePosition = tile.GetWorldPosition(tilemapBase) - ShadowEngine.light.transform2D.position;

            material.color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1);             // 1?

            material.mainTexture = virtualSpriteRenderer.sprite.texture;

            Vector2 scale = tile.worldScale * tile.scale;

            GLExtended.SetColor(Color.white);

            tilePosition += ShadowEngine.drawOffset;

            Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale, tile.worldRotation);

            material.mainTexture = null;
        }
Example #3
0
        private static void DrawTile(Pass pass)
        {
            #if UNITY_2017_4_OR_NEWER
            LightTile tile = (LightTile)pass.sortPass.sortObject.lightObject;
            LightTilemapCollider2D tilemap = pass.sortPass.sortObject.tilemap;

            bool masksDisabled   = tilemap.MasksDisabled();
            bool shadowsDisabled = tilemap.ShadowsDisabled();

            if (pass.sortPass.sortObject.tilemap.shadowLayer == pass.layerID && pass.drawShadows && shadowsDisabled == false)
            {
                ShadowEngine.GetMaterial().SetPass(0);

                GL.Begin(GL.TRIANGLES);

                Shadow.Tile.Draw(pass.light, tile, tilemap);

                GL.End();
            }

            // sprite mask - but what about shape mask?
            if (tilemap.maskLayer == pass.layerID && pass.drawMask && masksDisabled == false)
            {
                Tile.MaskSprite(tile, pass.layer, pass.materialWhite, tilemap, pass.lightSizeSquared);
            }
             #endif
        }
Example #4
0
        public override Vector2 TileWorldPosition(LightTile tile)
        {
            Transform transform = Properties.transform;

            float rotation = transform.eulerAngles.z * Mathf.Deg2Rad;

            Vector2 resultPosition = transform.position;

            Vector2 tilePosition = new Vector2(tile.gridPosition.x, tile.gridPosition.y);

            tilePosition.x *= Properties.cellSize.x;
            tilePosition.y *= Properties.cellSize.y;

            tilePosition.x += Properties.cellAnchor.x * Properties.cellSize.x;
            tilePosition.y += Properties.cellAnchor.y * Properties.cellSize.y;

            tilePosition.x *= transform.lossyScale.x;
            tilePosition.y *= transform.lossyScale.y;

            // Rotation
            float tileDirection = Mathf.Atan2(tilePosition.y, tilePosition.x) + rotation;
            float length        = Mathf.Sqrt(tilePosition.x * tilePosition.x + tilePosition.y * tilePosition.y);

            tilePosition.x = Mathf.Cos(tileDirection) * length;
            tilePosition.y = Mathf.Sin(tileDirection) * length;

            resultPosition += tilePosition;

            return(resultPosition);
        }
Example #5
0
 public Light()
 {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
     LandTileText.Text  = LandTile.ToString();
     LightTileText.Text = LightTile.ToString();
 }
Example #6
0
        static public void Sprite(Light2D light, LightTilemapCollider2D id, Material material, LayerSetting layerSetting)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();
            Vector2 scale    = tilemap.TileWorldScale();
            float   rotation = id.transform.eulerAngles.z;

            int count = tilemap.chunkManager.GetTiles(light.GetWorldRect());

            Texture2D currentTexture = null;
            Color     currentColor   = Color.black;

            GL.Begin(GL.QUADS);

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemap.chunkManager.display[i];

                if (tile.GetOriginalSprite() == null)
                {
                    return;
                }

                Vector2 tilePosition = tile.GetWorldPosition(tilemap);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

                if (virtualSpriteRenderer.sprite.texture == null)
                {
                    continue;
                }

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1?

                if (currentTexture != virtualSpriteRenderer.sprite.texture || currentColor != color)
                {
                    currentTexture = virtualSpriteRenderer.sprite.texture;
                    currentColor   = color;

                    material.mainTexture = currentTexture;
                    material.color       = currentColor;

                    material.SetPass(0);
                }

                Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale * tile.scale, rotation + tile.rotation);
            }

            GL.End();

            material.mainTexture = null;
        }
Example #7
0
        static public void Draw(Light2D light, LightTile tile, LightTilemapCollider2D tilemap)
        {
            LightTilemapCollider.Base tilemapCollider = tilemap.GetCurrentTilemap();

            List <Polygon2> polygons = tile.GetWorldPolygons(tilemapCollider);

            ShadowEngine.Draw(polygons, 0, 0);
        }
Example #8
0
        public async Task <IActionResult> Save(LightTile tile)
        {
            if (ModelState.IsValid)
            {
                return(await SaveBaseTile(ConfigStore, tile));
            }

            return(View("Add", tile));
        }
        public async Task <IActionResult> Save(LightTile tile)
        {
            if (ModelState.IsValid)
            {
                return(await SaveBaseTile(ConfigStore, tile));
            }

            ViewBag.Entities = (await EntityClient.GetEntities("light")).OrderBy(e => e).Select(e => new SelectListItem(e, e));
            return(View("Add", tile));
        }
Example #10
0
            public static void Draw(Camera camera, LightTilemapRoom2D id, Material material)
            {
                Vector2 cameraPosition = -camera.transform.position;

                float cameraRadius = CameraTransform.GetRadius(camera);

                LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap();

                material.mainTexture = null;

                Texture2D currentTexture = null;

                GL.Begin(GL.QUADS);

                int count = tilemapCollider.chunkManager.GetTiles(CameraTransform.GetWorldRect(camera));

                for (int i = 0; i < count; i++)
                {
                    LightTile tile = tilemapCollider.chunkManager.display[i];
                    if (tile.GetOriginalSprite() == null)
                    {
                        continue;
                    }

                    Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider);

                    tilePosition += cameraPosition;

                    if (tile.NotInRange(tilePosition, cameraRadius))
                    {
                        continue;
                    }

                    spriteRenderer.sprite = tile.GetOriginalSprite();

                    if (spriteRenderer.sprite.texture == null)
                    {
                        continue;
                    }

                    if (currentTexture != spriteRenderer.sprite.texture)
                    {
                        currentTexture       = spriteRenderer.sprite.texture;
                        material.mainTexture = currentTexture;

                        material.SetPass(0);
                    }

                    Universal.Sprite.FullRect.Simple.DrawPass(tile.spriteMeshObject, spriteRenderer, tilePosition, tile.worldScale, tile.worldRotation);
                }

                GL.End();

                material.mainTexture = null;
            }
Example #11
0
        static public void MaskShape(Light2D light, LightTilemapCollider2D id, LayerSetting layerSetting)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();

            bool isGrid = !tilemap.IsPhysicsShape();

            Vector2 scale = tilemap.TileWorldScale();

            float rotation = id.transform.eulerAngles.z;

            MeshObject tileMesh = null;

            if (isGrid)
            {
                tileMesh = LightTile.GetStaticMesh(tilemap);
            }

            int count = tilemap.chunkManager.GetTiles(light.GetWorldRect());

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemap.chunkManager.display[i];

                Vector2 tilePosition = tilemap.TileWorldPosition(tile);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                if (isGrid == false)
                {
                    tileMesh = null;
                    tileMesh = tile.GetDynamicMesh();
                }

                if (tileMesh == null)
                {
                    continue;
                }

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1?

                GL.Color(color);

                GLExtended.DrawMeshPass(tileMesh, tilePosition, scale, rotation + tile.rotation);
            }

            GL.Color(Color.white);
        }
Example #12
0
        public void InitializeGrid()
        {
            mapTiles.Clear();

            for (int x = tilemap.MinGridX; x <= tilemap.MaxGridX; x++)
            {
                for (int y = tilemap.MinGridY; y <= tilemap.MaxGridY; y++)
                {
                    Tile tileSTE     = tilemap.GetTile(x, y);
                    uint tileDataSTE = tilemap.GetTileData(x, y);
                    uint dataSTE     = Tileset.GetTileFlagsFromTileData(tileDataSTE);

                    if (tileSTE == null)
                    {
                        continue;
                    }

                    LightTile tile = new LightTile();
                    tile.gridPosition = new Vector3Int(x, y, 0);
                    tile.uv           = tileSTE.uv;

                    bool flipX = (dataSTE & k_TileFlag_FlipH) != 0;
                    bool flipY = (dataSTE & k_TileFlag_FlipV) != 0;

                    Vector2 scale = Vector2.one;
                    if (flipX)
                    {
                        scale.x = -1;
                    }

                    if (flipY)
                    {
                        scale.y = -1;
                    }

                    tile.scale = scale;

                    bool dynamic = this.shadowTypeSTE == SuperTilemapEditorSupport.TilemapCollider2D.ShadowType.TileCollider;

                    if (dynamic)
                    {
                        List <Polygon2> polygons = TileColliderDataToPolygons(tileSTE.collData, tile.scale);

                        if (polygons.Count > 0)
                        {
                            tile.SetLocalPolygons(polygons);
                        }
                    }

                    mapTiles.Add(tile);
                }
            }
        }
Example #13
0
        public override Vector2 TileWorldPosition(LightTile tile)
        {
            Vector2 position = tilemap2D.CellToWorld(tile.gridPosition);

            float rotation = properties.cellAnchor.Atan2() + tilemap2D.transform.eulerAngles.z * Mathf.Deg2Rad;
            float sizeX    = properties.cellAnchor.x;
            float sizeY    = properties.cellAnchor.y;

            float distance = Mathf.Sqrt(sizeX * sizeX + sizeY * sizeY);

            // +++ Include Cell Size

            position = position.Push(rotation, distance);

            return(position);
        }
Example #14
0
        public void Add(LightTilemapCollider2D tilemap, LightTile tile2D, float value)
        {
            if (count < list.Length)
            {
                list[count].value = value;

                list[count].type        = SortObject.Type.Tile;
                list[count].lightObject = tile2D;
                list[count].tilemap     = tilemap;

                count++;
            }
            else
            {
                Debug.LogError("Tile Depth Overhead!");
            }
        }
Example #15
0
        public override Vector2 TileWorldPosition(LightTile tile)
        {
            Vector2 resultPosition = properties.transform.position;

            Vector2 tilePosition = new Vector2(tile.gridPosition.x + tile.gridPosition.y / 2, tile.gridPosition.y);

            tilePosition.x += properties.cellAnchor.x;
            tilePosition.y += properties.cellAnchor.y;

            tilePosition.x = tilePosition.x + tilePosition.y * -0.5f;
            tilePosition.y = tilePosition.y * 0.75f;

            tilePosition.x *= properties.transform.lossyScale.x;
            tilePosition.y *= properties.transform.lossyScale.y;

            resultPosition += tilePosition;

            return(resultPosition);
        }
Example #16
0
            static public void Sprite(Light2D light, LightTilemapCollider2D id, Material material)
            {
                Vector2 lightPosition = -light.transform.position;

                LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap();

                if (id.superTilemapEditor.tilemap != null)
                {
                    if (id.superTilemapEditor.tilemap.Tileset != null)
                    {
                        material.mainTexture = id.superTilemapEditor.tilemap.Tileset.AtlasTexture;
                    }
                }

                material.SetPass(0);
                GL.Begin(GL.QUADS);

                int count = tilemapCollider.chunkManager.GetTiles(light.GetWorldRect());

                for (int i = 0; i < count; i++)
                {
                    LightTile tile = tilemapCollider.chunkManager.display[i];

                    tile.UpdateTransform(tilemapCollider);

                    Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider);
                    tilePosition += lightPosition;

                    if (tile.NotInRange(tilePosition, light.size))
                    {
                        continue;
                    }

                    Vector2 scale = tile.worldScale * 0.5f * tile.scale;

                    Rendering.Universal.Texture.DrawPassSTE(tilePosition, scale, tile.uv, tile.worldRotation, 0);
                }

                GL.End();

                material.mainTexture = null;
            }
Example #17
0
        private void InitializeGrid()
        {
            mapTiles.Clear();

            tilemap2D = properties.tilemap;
            ITilemap tilemap = GetITilemap(tilemap2D);

            foreach (Vector3Int position in tilemap2D.cellBounds.allPositionsWithin)
            {
                TileData tileData = new TileData();

                TileBase tilebase = tilemap2D.GetTile(position);

                if (tilebase != null)
                {
                    tilebase.GetTileData(position, tilemap, ref tileData);

                    LightTile lightTile = new LightTile();

                    lightTile.gridPosition = position;

                    if (shadowOptimization)
                    {
                        bool left  = GetTile(position + new Vector3Int(1, 0, 0));
                        bool up    = GetTile(position + new Vector3Int(0, 1, 0));
                        bool right = GetTile(position + new Vector3Int(-1, 0, 0));
                        bool down  = GetTile(position + new Vector3Int(0, -1, 0));

                        lightTile.occluded = left && right && up && down;
                    }

                    lightTile.rotation = tilemap2D.GetTransformMatrix(position).rotation.eulerAngles.z;

                    lightTile.SetOriginalSprite(tileData.sprite);
                    lightTile.GetPhysicsShapePolygons();

                    lightTile.colliderType = tileData.colliderType;

                    mapTiles.Add(lightTile);
                }
            }
        }
Example #18
0
        public override void Initialize()
        {
            base.Initialize();

            if (UpdateProperties() == false)
            {
                return;
            }

            mapTiles.Clear();

            tilemap2D = properties.tilemap;

            ITilemap tilemap = (ITilemap)FormatterServices.GetUninitializedObject(typeof(ITilemap));

            typeof(ITilemap).GetField("m_Tilemap", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(tilemap, tilemap2D);

            foreach (Vector3Int position in tilemap2D.cellBounds.allPositionsWithin)
            {
                TileData tileData = new TileData();

                TileBase tilebase = tilemap2D.GetTile(position);

                if (tilebase != null)
                {
                    tilebase.GetTileData(position, tilemap, ref tileData);

                    LightTile lightTile = new LightTile();
                    lightTile.gridPosition = new Vector3Int(position.x, position.y, position.z);

                    lightTile.scale = tilemap.GetTransformMatrix(position).lossyScale;

                    lightTile.SetOriginalSprite(tileData.sprite);
                    lightTile.GetPhysicsShapePolygons();

                    mapTiles.Add(lightTile);
                }
            }

            chunkManager.Update(mapTiles, this);
        }
Example #19
0
        static public void Draw(Light2D light, LightTilemapCollider2D id, float lightSizeSquared)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap();

            int count = tilemapCollider.chunkManager.GetTiles(light.GetWorldRect());

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemapCollider.chunkManager.display[i];

                switch (id.shadowTileType)
                {
                case ShadowTileType.AllTiles:
                    break;

                case ShadowTileType.ColliderOnly:
                    if (tile.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None)
                    {
                        continue;
                    }
                    break;
                }

                List <Polygon2> polygons     = tile.GetWorldPolygons(tilemapCollider);
                Vector2         tilePosition = tile.GetWorldPosition(tilemapCollider);

                if (tile.NotInRange(lightPosition + tilePosition, light.size))
                {
                    continue;
                }

                ShadowEngine.Draw(polygons, 0, 0);
            }
        }
Example #20
0
    private void LoadLightTiles()
    {
        foreach (Transform child in transform)
        {
            LightTile lightTile = child.gameObject.GetComponent <LightTile>();
            if (lightTile != null)
            {
                if (!lightTiles.ContainsKey(child.transform.position))
                {
                    lightTiles.Add(child.transform.position, lightTile);
                }
                else
                {
                    Destroy(child.gameObject);
                }
            }
            else
            {
                Logger.LogError("No LightTile component found!", Category.Lighting);
            }
        }

        CalculateBounds();
    }
Example #21
0
        public static List <LightCollision2D> RemoveHiddenCollisions(List <LightCollision2D> collisions, Light2D light, EventPreset eventPreset)
        {
            float  lightSizeSquared = Mathf.Sqrt(light.size * light.size + light.size * light.size);
            double rotLeft, rotRight;

            Polygon2D testPolygon   = GetPolygon();
            Vector2   lightPosition = -light.transform.position;
            int       next;

            for (int iid = 0; iid < eventPreset.layerSetting.list.Length; iid++)
            {
                int layerId = eventPreset.layerSetting.list[iid].layerID;

                List <LightTilemapCollider2D> tilemapColliderList = LightTilemapCollider2D.GetCollisionList(layerId);

                foreach (LightTilemapCollider2D id in tilemapColliderList)
                {
                    LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap();

                    int count = tilemapCollider.chunkManager.GetTiles(light.GetWorldRect());

                    for (int t = 0; t < count; t++)
                    {
                        LightTile tile = tilemapCollider.chunkManager.display[t];

                        switch (id.shadowTileType)
                        {
                        case ShadowTileType.AllTiles:
                            break;

                        case ShadowTileType.ColliderOnly:
                            if (tile.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None)
                            {
                                continue;
                            }
                            break;
                        }

                        List <Polygon2> polygons = tile.GetWorldPolygons(tilemapCollider);

                        if (polygons.Count < 1)
                        {
                            continue;
                        }

                        Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider) + lightPosition;

                        if (tile.NotInRange(tilePosition, light.size))
                        {
                            continue;
                        }

                        removePointsColliding.Clear();
                        removeCollisions.Clear();

                        for (int i = 0; i < polygons.Count; i++)
                        {
                            Vector2[] pointsList  = polygons[i].points;
                            int       pointsCount = pointsList.Length;

                            for (int x = 0; x < pointsCount; x++)
                            {
                                next = (x + 1) % pointsCount;

                                Vector2 left  = pointsList[x];
                                Vector2 right = pointsList[next];

                                edgeLeft.x = left.x + lightPosition.x;
                                edgeLeft.y = left.y + lightPosition.y;

                                edgeRight.x = right.x + lightPosition.x;
                                edgeRight.y = right.y + lightPosition.y;

                                rotLeft  = System.Math.Atan2(edgeLeft.y, edgeLeft.x);
                                rotRight = System.Math.Atan2(edgeRight.y, edgeRight.x);

                                projectionLeft.x = edgeLeft.x + System.Math.Cos(rotLeft) * lightSizeSquared;
                                projectionLeft.y = edgeLeft.y + System.Math.Sin(rotLeft) * lightSizeSquared;

                                projectionRight.x = edgeRight.x + System.Math.Cos(rotRight) * lightSizeSquared;
                                projectionRight.y = edgeRight.y + System.Math.Sin(rotRight) * lightSizeSquared;

                                testPolygon.pointsList[0].x = projectionLeft.x;
                                testPolygon.pointsList[0].y = projectionLeft.y;

                                testPolygon.pointsList[1].x = projectionRight.x;
                                testPolygon.pointsList[1].y = projectionRight.y;

                                testPolygon.pointsList[2].x = edgeRight.x;
                                testPolygon.pointsList[2].y = edgeRight.y;

                                testPolygon.pointsList[3].x = edgeLeft.x;
                                testPolygon.pointsList[3].y = edgeLeft.y;

                                foreach (LightCollision2D col in collisions)
                                {
                                    if (col.collider == id)
                                    {
                                        continue;
                                    }

                                    foreach (Vector2 point in col.points)
                                    {
                                        if (testPolygon.PointInPoly(point))
                                        {
                                            removePointsColliding.Add(point);
                                        }
                                    }

                                    foreach (Vector2 point in removePointsColliding)
                                    {
                                        col.points.Remove(point);
                                    }

                                    removePointsColliding.Clear();

                                    if (col.points.Count < 1)
                                    {
                                        removeCollisions.Add(col);
                                    }
                                }

                                foreach (LightCollision2D col in removeCollisions)
                                {
                                    collisions.Remove(col);
                                }

                                removeCollisions.Clear();
                            }
                        }
                    }
                }
            }

            return(collisions);
        }
Example #22
0
        public override float TileWorldRotation(LightTile tile)
        {
            float worldRotation = tilemap2D.transform.eulerAngles.z;

            return(worldRotation);
        }
Example #23
0
 public virtual float TileWorldRotation(LightTile tile)
 {
     return(0);
 }
Example #24
0
 // Tile World Properties
 public virtual Vector2 TileWorldPosition(LightTile tile)
 {
     return(Vector2.zero);
 }