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; } } } }
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(); } } } }
// Management static public LightingBuffer2D AddBuffer(int textureSize, LightingSource2D light) { LightingManager2D manager = LightingManager2D.Get(); if (manager.fixedLightBufferSize) { textureSize = LightingManager2D.GetTextureSize(manager.fixedLightTextureSize); } FBOManager fboManager = LightingManager2D.Get().fboManager; if (fboManager == null) { Debug.LogError("Lighting Manager Instance is Out-Dated."); Debug.LogError("Try Re-Initializing 'Lighting Manager 2D' Component"); return(null); } GameObject buffer = new GameObject(); buffer.name = "Buffer " + GetCount(); buffer.transform.parent = LightingManager2D.Get().fboManager.transform; buffer.layer = LightingManager2D.lightingLayer; LightingBuffer2D lightingBuffer = buffer.AddComponent <LightingBuffer2D> (); lightingBuffer.Initiate(textureSize); lightingBuffer.lightSource = light; // Unnecessary? lightingBuffer.free = false; lightingBuffer.bufferCamera.orthographicSize = light.lightSize; return(lightingBuffer); }
// 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 bool DrawOrNot(LightingSource2D id) { for (int i = 0; i < id.layerCount; i++) { switch (id.layerSetting[i].type) { case LightingLayerType.Default: if (i == (int)lightingCollisionLayer || i == (int)lightingMaskLayer) { return(true); } break; case LightingLayerType.MaskOnly: if (i == (int)lightingMaskLayer) { return(true); } break; case LightingLayerType.ShadowOnly: if (i == (int)lightingCollisionLayer) { return(true); } break; } } return(false); }
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.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 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.update = true; } }
public void OnEnable() { list.Add(this); Initialize(); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.movement.ForceUpdate(); } }
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 Update(LightingSource2D source) { Transform transform = source.transform; if (updatePosition != transform.position) { updatePosition = transform.position; update = true; } if (updateRotation != transform.rotation.eulerAngles.z) { updateRotation = transform.rotation.eulerAngles.z; update = true; } if (updateSize != source.lightSize) { updateSize = source.lightSize; update = true; } if (updateColor.Equals(source.lightColor) == false) { updateColor = source.lightColor; } if (updateAlpha != source.lightAlpha) { updateAlpha = source.lightAlpha; } if (move == true) { if (updatePosition != movePosition) { updatePosition = movePosition; transform.position = movePosition; update = true; } move = false; } }
override public void OnInspectorGUI() { LightingSource2D script = target as LightingSource2D; script.color = EditorGUILayout.ColorField("Color", script.color); script.lightSize = EditorGUILayout.FloatField("Size", script.lightSize); script.textureSize = (LightingSource2D.TextureSize)EditorGUILayout.EnumPopup("Buffer Size", script.textureSize); script.lightSprite = (LightingSource2D.LightSprite)EditorGUILayout.EnumPopup("Light Sprite", script.lightSprite); if (script.lightSprite == LightingSource2D.LightSprite.Custom) { script.sprite = (Sprite)EditorGUILayout.ObjectField("Sprite", script.sprite, typeof(Sprite), true); } script.rotationEnabled = EditorGUILayout.Toggle("Enable Rotation", script.rotationEnabled); }
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; } } }
public override bool OnInteract(PlayerController player) { if (lightSource == null) { lightSource = GetComponent <LightingSource2D>(); } if (lightSource == null) { Debug.LogError("Lamp Lightsource2D not found!"); return(false); } lightSource.enabled = !lightSource.enabled; return(true); }
static public LightingBuffer2D GetBuffer(int textureSize, LightingSource2D lightSource) { foreach (LightingBuffer2D id in LightingBuffer2D.GetList()) { if ((id.lightSource == lightSource || id.lightSource == null) && id.textureSize == textureSize) { id.lightSource = lightSource; lightSource.update = true; id.bufferCamera.enabled = true; //id.gameObject.SetActive (true); return(id); } } return(AddBuffer(textureSize)); }
// 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); } } }
public void UpdateAsLightSource(LightingSource2D id) { transform.position = id.transform.position; // transform.rotation = id.transform.rotation; // only if rotation enabled transform.localScale = new Vector3(id.lightSize, id.lightSize, 1); transform.rotation = Quaternion.Euler(0, 0, 0); if (id.buffer != null && meshRenderer != null) { Color lightColor = id.lightColor; lightColor.a = id.additive_alpha; id.buffer.GetAdditiveMaterial().SetColor("_TintColor", lightColor); meshRenderer.sortingOrder = id.sortingOrder; meshRenderer.sortingLayerName = id.sortingLayer; meshRenderer.material = id.buffer.GetAdditiveMaterial(); meshRenderer.enabled = true; } }
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 LightingBuffer2D PullBuffer(int textureSize, LightingSource2D lightSource) { LightingManager2D manager = LightingManager2D.Get(); if (manager.fixedLightBufferSize) { textureSize = LightingManager2D.GetTextureSize(manager.fixedLightTextureSize); } foreach (LightingBuffer2D id in LightingBuffer2D.GetList()) { if (id.free == true && id.textureSize == textureSize) { id.bufferCamera.orthographicSize = lightSource.lightSize; lightSource.update = true; id.lightSource = lightSource; // Unnecessary? id.free = false; //id.gameObject.SetActive (true); return(id); } } return(AddBuffer(textureSize, lightSource)); }
void Start() { lightSource = GetComponent <LightingSource2D>(); lightAlpha = lightSource.lightAlpha; timer = TimerHelper.Create(); }
override public void OnInspectorGUI() { LightingSource2D script = target as LightingSource2D; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Preset", LightingManager2D.Get().preset); EditorGUI.EndDisabledGroup(); Color newColor = EditorGUILayout.ColorField("Color", script.lightColor); if (script.lightColor.Equals(newColor) == false) { newColor.a = 1f; script.lightColor = newColor; LightingMainBuffer2D.ForceUpdate(); } float newAlpha = EditorGUILayout.Slider("Alhpa", script.lightAlpha, 0, 1); if (script.lightAlpha != newAlpha) { script.lightAlpha = newAlpha; LightingMainBuffer2D.ForceUpdate(); } float newLightSize = EditorGUILayout.FloatField("Size", script.lightSize); if (newLightSize != script.lightSize) { script.lightSize = newLightSize; LightingMainBuffer2D.ForceUpdate(); } script.textureSize = (LightingSource2D.TextureSize)EditorGUILayout.EnumPopup("Buffer Size", script.textureSize); script.lightSprite = (LightingSource2D.LightSprite)EditorGUILayout.EnumPopup("Light Sprite", script.lightSprite); if (script.lightSprite == LightingSource2D.LightSprite.Custom) { Sprite newSprite = (Sprite)EditorGUILayout.ObjectField("Sprite", script.sprite, typeof(Sprite), true); if (newSprite != script.sprite) { script.sprite = newSprite; script.SetMaterial(); LightingMainBuffer2D.ForceUpdate(); } } else { if (script.sprite != LightingSource2D.GetDefaultSprite()) { script.sprite = LightingSource2D.GetDefaultSprite(); script.SetMaterial(); LightingMainBuffer2D.ForceUpdate(); } } script.rotationEnabled = EditorGUILayout.Toggle("Enable Rotation", script.rotationEnabled); }
public void LateUpdate() { if (owner == null) { return; } string type = owner.GetType().ToString(); switch (type) { case "LightingSource2D": LightingSource2D source = (LightingSource2D)owner; if (source) { if (source.additive == false) { meshRenderer.enabled = false; owner = null; free = true; return; } if (source.enabled == false || source.gameObject.active == false) { owner = null; free = true; meshRenderer.enabled = false; } else { meshRenderer.enabled = true; } } break; case "LightingSpriteRenderer2D": LightingSpriteRenderer2D source2 = (LightingSpriteRenderer2D)owner; if (source2) { if (source2.applyAdditive == false) { meshRenderer.enabled = false; owner = null; free = true; return; } if (source2.enabled == false || source2.gameObject.active == false) { owner = null; free = true; meshRenderer.enabled = false; } else { meshRenderer.enabled = true; } } break; } }
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); }
override public void OnInspectorGUI() { LightingSource2D script = target as LightingSource2D; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Preset", LightingManager2D.Get().preset); EditorGUI.EndDisabledGroup(); //script.lightingCollisionLayer = (LightingCollisionLayer)EditorGUILayout.EnumPopup("Collision Layer", script.lightingCollisionLayer); //script.lightingMaskLayer = (LightingMaskLayer)EditorGUILayout.EnumPopup("Mask Layer", script.lightingMaskLayer); script.layerCount = EditorGUILayout.IntField("Layer Count", script.layerCount); foldout = EditorGUILayout.Foldout(foldout, "Layers"); if (foldout) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; for (int i = 0; i < script.layerCount; i++) { if (script.layerSetting.Length <= i) { System.Array.Resize(ref script.layerSetting, i + 1); } if (script.layerSetting[i] == null) { script.layerSetting[i] = new LayerSetting(); } script.layerSetting[i].layerID = (LightingLayer)EditorGUILayout.EnumPopup("Layer ID", script.layerSetting[i].layerID); script.layerSetting[i].renderingOrder = (LightRenderingOrder)EditorGUILayout.EnumPopup("Order", script.layerSetting[i].renderingOrder); } EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } Color newColor = EditorGUILayout.ColorField("Color", script.lightColor); if (script.lightColor.Equals(newColor) == false) { newColor.a = 1f; script.lightColor = newColor; LightingMainBuffer2D.ForceUpdate(); } float newAlpha = EditorGUILayout.Slider("Alpha", script.lightAlpha, 0, 1); if (script.lightAlpha != newAlpha) { script.lightAlpha = newAlpha; LightingMainBuffer2D.ForceUpdate(); } float newLightSize = EditorGUILayout.FloatField("Size", script.lightSize); if (newLightSize != script.lightSize) { script.lightSize = newLightSize; LightingMainBuffer2D.ForceUpdate(); } switch (LightingManager2D.Get().fixedLightBufferSize) { case true: EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Buffer Size", LightingManager2D.Get().fixedLightTextureSize); EditorGUI.EndDisabledGroup(); break; case false: script.textureSize = (LightingSourceTextureSize)EditorGUILayout.EnumPopup("Buffer Size", script.textureSize); break; } script.lightSprite = (LightingSource2D.LightSprite)EditorGUILayout.EnumPopup("Light Sprite", script.lightSprite); if (script.lightSprite == LightingSource2D.LightSprite.Custom) { Sprite newSprite = (Sprite)EditorGUILayout.ObjectField("Sprite", script.sprite, typeof(Sprite), true); if (newSprite != script.sprite) { script.sprite = newSprite; script.SetMaterial(); LightingMainBuffer2D.ForceUpdate(); } } else { if (script.sprite != LightingSource2D.GetDefaultSprite()) { script.sprite = LightingSource2D.GetDefaultSprite(); script.SetMaterial(); LightingMainBuffer2D.ForceUpdate(); } } script.enableCollisions = EditorGUILayout.Toggle("Apply Shadows & Masks", script.enableCollisions); script.rotationEnabled = EditorGUILayout.Toggle("Apply Rotation", script.rotationEnabled); script.additive = EditorGUILayout.Toggle("Apply Additive Shader", script.additive); if (script.additive) { script.additive_alpha = EditorGUILayout.Slider("Additive Alpha", script.additive_alpha, 0, 1); } script.eventHandling = EditorGUILayout.Toggle("Apply Event Handling", script.eventHandling); script.drawInsideCollider = EditorGUILayout.Toggle("Apply Light Inside Collider", script.drawInsideCollider); if (targets.Length > 1) { if (GUILayout.Button("Apply to All")) { foreach (Object obj in targets) { LightingSource2D copy = obj as LightingSource2D; if (copy == script) { continue; } copy.layerSetting[0].renderingOrder = script.layerSetting[0].renderingOrder; copy.layerSetting[1].renderingOrder = script.layerSetting[1].renderingOrder; copy.lightColor = script.lightColor; copy.lightAlpha = script.lightAlpha; copy.lightSize = script.lightSize; copy.textureSize = script.textureSize; copy.enableCollisions = script.enableCollisions; copy.rotationEnabled = script.rotationEnabled; copy.additive = script.additive; copy.additive_alpha = script.additive_alpha; copy.eventHandling = script.eventHandling; copy.drawInsideCollider = script.drawInsideCollider; copy.lightSprite = script.lightSprite; copy.sprite = script.sprite; copy.SetMaterial(); } LightingMainBuffer2D.ForceUpdate(); } } if (GUI.changed && EditorApplication.isPlaying == false) { EditorUtility.SetDirty(target); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } }
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(); }