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; }
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; }
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; }
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; }
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); } }
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); }