public void Update() { Vector2 position = transform.transform.position; if (movedPosition != position) { movedPosition = position; moved = true; } else { moved = false; } if (moved) { foreach (LightingSource2D id in LightingSource2D.GetList()) { if (Vector2.Distance(id.transform.position, position) < meshDistance + id.lightSize) { id.update = true; LightingBuffer2D.GetBuffer(id.GetTextureSize(), id).lightSource = id; } } } }
public void Update() { movement.Update(this); if (movement.moved) { shape.ResetWorld(); float distance = shape.GetFrustumDistance(transform); foreach (LightingSource2D id in LightingSource2D.GetList()) { bool draw = DrawOrNot(id); if (draw == false) { continue; } if (Vector2.Distance(id.transform.position, transform.position) < distance + id.lightSize) { id.movement.ForceUpdate(); } } } }
private void OnSceneGUI(SceneView view) { if (drawSceneView == false) { return; } foreach (LightingSource2D id in LightingSource2D.GetList()) { if (id.buffer == null) { continue; } if (id.isActiveAndEnabled == false) { continue; } if (id.buffer.bufferCamera == null) { continue; } if (id.buffer.material) { Color lightColor = id.lightColor; lightColor.a = id.lightAlpha / 4; id.buffer.material.SetColor("_TintColor", lightColor); Graphics.DrawMesh(GetRenderMesh(), Matrix4x4.TRS(id.transform.position, Quaternion.Euler(0, 0, 0), id.transform.lossyScale * id.lightSize), id.buffer.material, 0); } } }
public void Update() { Vector2 position = transform.position; Vector2 scale = transform.lossyScale; float rotation = transform.rotation.eulerAngles.z; moved = false; if (movedPosition != position) { movedPosition = position; moved = true; } if (movedScale != scale) { movedScale = scale; moved = true; } if (movedRotation != rotation) { movedRotation = rotation; moved = true; } if (maskType == MaskType.Sprite) { if (spriteRenderer != null && lightSprite != spriteRenderer.sprite) { lightSprite = spriteRenderer.sprite; moved = true; } } if (maskType == MaskType.SpriteCustomPhysicsShape || colliderType == ColliderType.SpriteCustomPhysicsShape) { if (spriteRenderer != null && lightSprite != spriteRenderer.sprite) { lightSprite = spriteRenderer.sprite; moved = true; shapePolygons = null; shapeMesh = null; GetShapePolygons(); } } if (moved) { float distance = GetCullingDistance(); foreach (LightingSource2D id in LightingSource2D.GetList()) { if (Vector2.Distance(id.transform.position, position) < distance + id.lightSize) { id.update = true; } } } }
// Lighting Buffers void DrawLightingBuffers(float z) { foreach (LightingSource2D id in LightingSource2D.GetList()) { if (id.buffer == null) { continue; } if (id.isActiveAndEnabled == false) { continue; } if (id.buffer.bufferCamera == null) { continue; } if (id.InCamera() == false) { continue; } Vector3 pos = id.transform.position - Camera.main.transform.position; float size = id.buffer.bufferCamera.orthographicSize; Color lightColor = id.lightColor; lightColor.a = id.lightAlpha / 2; id.buffer.material.SetColor("_TintColor", lightColor); Max2D.DrawImage(id.buffer.material, new Vector2D(pos), new Vector2D(size, size), z); } }
public void OnDisable() { list.Remove(this); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.movement.ForceUpdate(); } }
public void OnDisable() { list.Remove(this); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.update = true; } }
public void OnEnable() { list.Add(this); Initialize(); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.movement.ForceUpdate(); } }
public void OnEnable() { list.Add(this); Initialize(); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.update = true; } }
override public void OnInspectorGUI() { LightingTilemapCollider2D script = target as LightingTilemapCollider2D; script.mapType = (LightingTilemapCollider2D.MapType)EditorGUILayout.EnumPopup("Tilemap Type", script.mapType); script.colliderType = (LightingTilemapCollider2D.ColliderType)EditorGUILayout.EnumPopup("Collision Type", script.colliderType); script.lightingCollisionLayer = (LightingLayer)EditorGUILayout.EnumPopup("Collision Layer", script.lightingCollisionLayer); script.maskType = (LightingTilemapCollider2D.MaskType)EditorGUILayout.EnumPopup("Mask Type", script.maskType); if (script.maskType != LightingTilemapCollider2D.MaskType.None) { script.lightingMaskLayer = (LightingLayer)EditorGUILayout.EnumPopup("Mask Layer", script.lightingMaskLayer); script.maskMode = (LightingMaskMode)EditorGUILayout.EnumPopup("Mask Mode", script.maskMode); } else { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Mask Layer", script.lightingMaskLayer); EditorGUILayout.EnumPopup("Mask Mode", script.maskMode); EditorGUI.EndDisabledGroup(); } script.dayHeight = EditorGUILayout.Toggle("Day Height", script.dayHeight); if (script.dayHeight) { script.height = EditorGUILayout.FloatField("Height", script.height); } //script.ambientOcclusion = EditorGUILayout.Toggle("Ambient Occlusion", script.ambientOcclusion); //if (script.ambientOcclusion) { // script.occlusionSize = EditorGUILayout.FloatField("Occlussion Size", script.occlusionSize); //} if (GUILayout.Button("Update Collisions")) { script.Initialize(); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.movement.ForceUpdate(); } LightingMainBuffer2D.ForceUpdate(); } if (GUI.changed && EditorApplication.isPlaying == false) { EditorUtility.SetDirty(target); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } }
public void OnDisable() { list.Remove(this); float distance = shape.GetFrustumDistance(transform); foreach (LightingSource2D id in LightingSource2D.GetList()) { if (Vector2.Distance(id.transform.position, transform.position) < distance + id.lightSize) { id.movement.ForceUpdate(); } } }
public void OnDisable() { list.Remove(this); Vector2 position = movedPosition; float distance = GetCullingDistance(); foreach (LightingSource2D id in LightingSource2D.GetList()) { if (Vector2.Distance(id.transform.position, position) < distance + id.lightSize) { id.update = true; } } }
// Lighting Buffers void DrawLightingBuffers(float z) { Camera camera = LightingManager2D.Get().GetCamera(); Vector2D pos2D = Vector2D.Zero(); Vector2D size2D = Vector2D.Zero(); foreach (LightingSource2D id in LightingSource2D.GetList()) { if (id.buffer == null) { continue; } if (id.isActiveAndEnabled == false) { continue; } if (id.buffer.bufferCamera == null) { continue; } if (id.InCamera() == false) { continue; } Vector3 pos = id.transform.position - camera.transform.position; pos2D.x = pos.x; pos2D.y = pos.y; float size = id.buffer.bufferCamera.orthographicSize; size2D.x = size; size2D.y = size; Color lightColor = id.lightColor; lightColor.a = id.lightAlpha / 2; id.buffer.GetMaterial().SetColor("_TintColor", lightColor); Max2D.DrawImage(id.buffer.GetMaterial(), pos2D, size2D, z); } }
/* * void DrawLightingBuffers(float z) { * * }*/ /* Draw Lights In Scene View * Polygon2D rect = Polygon2D.CreateFromRect(new Vector2(1, 1)); * Mesh mesh = rect.CreateMesh(new Vector2(2, 2), Vector2.zero); * * * foreach (LightingBuffer2D id in FBOManager.GetList()) { * if (id.lightSource == null) { * continue; * } * * if (id.lightSource.isActiveAndEnabled == false) { * continue; * } * * Draw(id, mesh); * } */ /* * private void Draw(LightingBuffer2D id, Mesh mesh) { * if (mesh && id.material) { * Color lightColor = id.lightSource.lightColor; * lightColor.a = id.lightSource.lightAlpha / 4; * id.material.SetColor ("_TintColor", lightColor); * * Graphics.DrawMesh(mesh, Matrix4x4.TRS(id.lightSource.transform.position, id.lightSource.transform.rotation, id.lightSource.transform.lossyScale * id.lightSource.lightSize), id.material, 0); * } * } */ void DrawAdditiveLights() { foreach (LightingSource2D id in LightingSource2D.GetList()) { if (id.buffer == null) { continue; } if (id.isActiveAndEnabled == false) { continue; } if (id.buffer.bufferCamera == null) { continue; } if (id.InCamera() == false) { continue; } if (id.additive == false) { continue; } if (id.buffer.additiveMaterial) { Color lightColor = id.lightColor; lightColor.a = 0.5f; lightColor.r *= id.additive_alpha; lightColor.g *= id.additive_alpha; lightColor.b *= id.additive_alpha; id.buffer.additiveMaterial.SetColor("_TintColor", lightColor); Graphics.DrawMesh(GetRenderMesh(), Matrix4x4.TRS(id.transform.position, Quaternion.Euler(0, 0, 0), id.transform.lossyScale * id.lightSize), id.buffer.additiveMaterial, 0); } } }
void DrawAdditiveLights() { foreach (LightingSource2D id in LightingSource2D.GetList()) { if (id.buffer == null) { continue; } if (id.isActiveAndEnabled == false) { continue; } if (id.buffer.bufferCamera == null) { continue; } if (id.InCamera() == false) { continue; } if (id.additive == false) { continue; } if (id.buffer.GetAdditiveMaterial()) { LightingMeshRenderer lightingMesh = MeshRendererManager.Pull(id); lightingMesh.UpdateAsLightSource(id); } } }
static public void OnGUI() { if (timer == null) { LightingDebug.timer = TimerHelper.Create(); } if (timer.GetMillisecs() > 1000) { ShowLightBufferUpdates = LightBufferUpdates; LightBufferUpdates = 0; ShowLightMainBufferUpdates = LightMainBufferUpdates; LightMainBufferUpdates = 0; ShowLightMainCameraUpdates = LightMainCameraUpdates; LightMainCameraUpdates = 0; timer = TimerHelper.Create(); } if (SpriteRenderersDrawn > 0) { ShowSpriteRenderersDrawn = SpriteRenderersDrawn; SpriteRenderersDrawn = 0; } int count = 0; foreach (LightingSource2D light in LightingSource2D.GetList()) { if (light.InCamera() == false) { continue; } count++; } GUI.Label(new Rect(10, 10, 500, 20), "Lights in Camera: " + count + "/" + LightingSource2D.GetList().Count); GUI.Label(new Rect(10, 30, 500, 20), "Free Buffers: " + FBOManager.GetFreeCount() + "/" + FBOManager.GetList().Count); GUI.Label(new Rect(10, 50, 500, 20), "Light Buffer Updates: " + ShowLightBufferUpdates); GUI.Label(new Rect(10, 70, 500, 20), "Total Light Updates: " + totalLightUpdates); GUI.Label(new Rect(10, 90, 500, 20), "========================="); GUI.Label(new Rect(10, 110, 500, 20), "Mask Generations: " + maskGenerations); GUI.Label(new Rect(10, 130, 500, 20), "Shadow Generations: " + shadowGenerations); GUI.Label(new Rect(10, 150, 500, 20), "Penumbra Generations: " + penumbraGenerations); GUI.Label(new Rect(10, 170, 500, 20), "Objects Culled: " + culled); GUI.Label(new Rect(10, 190, 500, 20), "========================="); GUI.Label(new Rect(10, 210, 500, 20), "Sprite Renderers Drawn: " + ShowSpriteRenderersDrawn); GUI.Label(new Rect(10, 230, 500, 20), "========================="); GUI.Label(new Rect(10, 250, 500, 20), "Light Main Buffer Updates: " + ShowLightMainBufferUpdates); GUI.Label(new Rect(10, 270, 500, 20), "Light Main Camera Updates: " + ShowLightMainCameraUpdates); GUI.Label(new Rect(10, 290, 500, 20), "========================="); Texture texture = LightingMainBuffer2D.Get().bufferCamera.activeTexture; if (texture != null) { GUI.Label(new Rect(10, 310, 500, 20), "Main Buffer Resolution: " + texture.width + "x" + texture.height); } else { GUI.Label(new Rect(10, 330, 500, 20), "Main Buffer Resolution: NULL"); } GUI.Label(new Rect(10, 350, 500, 20), "Glow Particles Generated: " + BlurManager.dictionary.Count); GUIStyle style = new GUIStyle(); style.alignment = TextAnchor.LowerRight; style.normal.textColor = Color.white; style.fontSize = 13; #if UNITY_2018_1_OR_NEWER Object[] tilemaps = Object.FindObjectsOfType(typeof(LightingTilemapCollider2D)); #endif Object[] lights = Object.FindObjectsOfType(typeof(LightingSource2D)); Object[] colliders = Object.FindObjectsOfType(typeof(LightingCollider2D)); Object[] sprites = Object.FindObjectsOfType(typeof(LightingSpriteRenderer2D)); #if UNITY_2018_1_OR_NEWER GUI.Label(new Rect(0, -10, Screen.width - 10, Screen.height), "Tilemap Collider Count: " + tilemaps.Length, style); #endif GUI.Label(new Rect(0, -30, Screen.width - 10, Screen.height), "Lights Count: " + lights.Length, style); GUI.Label(new Rect(0, -50, Screen.width - 10, Screen.height), "Colliders Count: " + colliders.Length, style); GUI.Label(new Rect(0, -70, Screen.width - 10, Screen.height), "Sprites Count: " + sprites.Length, style); }
static public void OnGUI() { if (lights == null) { lights = Object.FindObjectsOfType(typeof(LightingSource2D)); colliders = Object.FindObjectsOfType(typeof(LightingCollider2D)); sprites = Object.FindObjectsOfType(typeof(LightingSpriteRenderer2D)); tilemaps = Object.FindObjectsOfType(typeof(LightingTilemapCollider2D)); } if (timer == null) { LightingDebug.timer = TimerHelper.Create(); } if (timer.GetMillisecs() > 1000) { SecondUpdate(); } ShowUpdate(); int count = 0; foreach (LightingSource2D light in LightingSource2D.GetList()) { if (light.InCamera() == false) { continue; } count++; } LightingManager2D manager2D = LightingManager2D.Get(); int y = 10; GUI.Label(new Rect(10, y, 500, 20), "Camera Size: " + manager2D.mainBuffer.cameraSize); y += 10; GUI.Label(new Rect(10, y, 500, 20), "New Render Textures: " + NewRenderTextures); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Lights in Camera: " + count + "/" + LightingSource2D.GetList().Count); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Free Buffers: " + FBOManager.GetFreeCount() + "/" + FBOManager.GetList().Count); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Light Buffer Updates: " + ShowLightBufferUpdates); // In Frame y += 10; GUI.Label(new Rect(10, y, 500, 20), "Total Light Updates: " + totalLightUpdates); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Mask Generations: " + show_maskGenerations); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Shadow Generations: " + show_shadowGenerations); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Objects Culled: " + show_culled); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Shadow Collider World Generations C: " + ShadowColliderTotalGenerationsWorld_collider + " (re: " + ShadowColliderTotalGenerationsWorld_collider_re + ") Pair: " + LightingDebug.ShadowColliderTotalGenerationsWorld_collider_pair); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Shadow Collider Local Generations C: " + ShadowColliderTotalGenerationsLocal_collider); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Shadow Collider World Generations S: " + ShadowColliderTotalGenerationsWorld_shape + " (re: " + ShadowColliderTotalGenerationsWorld_shape_re + ") Pair: " + LightingDebug.ShadowColliderTotalGenerationsWorld_shape_pair); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Shadow Collider Local Generations S: " + ShadowColliderTotalGenerationsLocal_shape); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Total Object SHAPE Generations: " + totalObjectMaskShapeGenerations); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Total Object MESH Generations : " + totalObjectMaskMeshGenerations); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Convex Hull Generations: " + ShowConvexHullGenerations); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Sprite Renderers Drawn: " + ShowSpriteRenderersDrawn); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Light Main Buffer Updates: " + ShowLightMainBufferUpdates); y += 10; GUI.Label(new Rect(10, y, 500, 20), "Light Main Camera Updates: " + ShowLightMainCameraUpdates); y += 10; GUI.Label(new Rect(10, y, 500, 20), "========================="); y += 10; Texture texture = LightingMainBuffer2D.Get().bufferCamera.activeTexture; if (texture != null) { GUI.Label(new Rect(10, y, 500, 20), "Main Buffer Resolution: " + texture.width + "x" + texture.height); } else { GUI.Label(new Rect(10, y, 500, 20), "Main Buffer Resolution: NULL"); } y += 10; GUI.Label(new Rect(10, y, 500, 20), "Glow Particles Generated: " + BlurManager.dictionary.Count); RightBottomPanel(); }