/// <summary> /// Adds the light. /// </summary> /// <param name="Light">The light.</param> public void AddLight(PloobsEngine.Light2D.Light2D Light) { System.Diagnostics.Debug.Assert(Light != null); Light.RenderTarget = graphicsFactory.CreateRenderTarget(Light.baseSize, Light.baseSize); Light.RenderTargetNS = graphicsFactory.CreateRenderTarget(Light.baseSize, Light.baseSize); Lights2D.Add(Light); }
/// <summary> /// Removes the light. /// </summary> /// <param name="Light">The light.</param> public void RemoveLight(PloobsEngine.Light2D.Light2D Light) { Light.RenderTarget.Dispose(); Light.RenderTarget = null; Light.RenderTargetNS.Dispose(); Light.RenderTargetNS = null; Lights2D.Remove(Light); }
// Update is called once per frame void Update() { meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); Lights2D light = GetComponent <Lights2D>(); //Mesh Generation Vector3[] vertices = new Vector3[4]; Vector3[] normals = new Vector3[4]; Vector2[] uvs = new Vector2[4]; int[] tris = new int[6]; Mesh mesh = new Mesh(); Vector3 zero = gameObject.transform.position; vertices[0] = transform.InverseTransformPoint(zero); normals[0] = gameObject.transform.up; //Vector3 leftDir = transform.InverseTransformDirection( light.leftFogVector); Vector3 one = transform.InverseTransformPoint(light.leftEndPoint); vertices[1] = one; normals[1] = gameObject.transform.up; //Vector3 rightDir = transform.InverseTransformDirection(light.rightFogVector); Vector3 two = transform.InverseTransformPoint(light.rightEndPoint); vertices[2] = two; normals[2] = gameObject.transform.up; Vector3 three = transform.InverseTransformPoint(light.topEndPoint); vertices[3] = three; normals[3] = gameObject.transform.up; uvs[0] = new Vector2(0, 1); uvs[1] = new Vector2(1, 0); uvs[2] = new Vector2(1, 1); uvs[3] = new Vector2(0, 0); tris = new int[] { 0, 1, 2, 1, 3, 2 }; mesh.Clear(); mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uvs; mesh.triangles = tris; //mesh.RecalculateNormals(); meshFilter.mesh = mesh; meshRenderer.material = light.lightMat; }
void SortLightsEditor() { //Debug.Log("lights list: " + lightsInScene.Count); if (!sorting) { sorting = true; int counter = 0; int c = 0; Vector3 cam = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0); //Debug.Log("lights in scene: " + lightsInScene.Count); for (int i = 0; i < 5; i++) { Lights2D l = lightsInScene[i]; float distance1 = Vector3.SqrMagnitude(cam - lightsInScene[i].transform.position); for (int j = i + 1; j < lightsInScene.Count; j++) { float distance2 = Vector3.SqrMagnitude(cam - lightsInScene[j].transform.position); //Debug.Log("distance: " + distance2 + "light distance : " + lightsInScene[j].distance * lightsInScene[j].distance); if (distance2 < distance1) { //Swap the lights Lights2D temp = lightsInScene[i]; lightsInScene[i] = lightsInScene[j]; lightsInScene[j] = temp; } l = lightsInScene[i]; counter++; } if (c > 5) { l.gameObject.SetActive(false); } c++; //l.gameObject.SetActive(false); if (counter > 10) { counter = 0; } } //Debug.Log("Lights are being sorted in editor view"); //Gets the closest 5 lights and places them in the lights list lights.Clear(); for (int i = 0; i < 5; i++) { if (i > lightsInScene.Count - 1) break; lightsInScene[i].gameObject.SetActive(true); lights.Add(lightsInScene[i]); } } sorting = false; }
// Use this for initialization void Start() { angle = gameObject.transform.Find("Angle").gameObject; fog = gameObject.transform.Find("Fog").gameObject; distance = gameObject.transform.Find("Distance").gameObject; opacity = gameObject.transform.Find("Opacity").gameObject; lightPoint = gameObject.transform.GetComponentInParent <Lights2D>(); SetLightParameters(); Debug.Log("slider controls script is working"); }
// Use this for initialization void Awake() { light = GetComponent <Lights2D>(); if (light.isAPixelLight) { if (transform.childCount == 0) { InstantiateLightMesh(); } else { AssignLightMesh(); } } //TODO: Add more intuitive mesh generation later. But for now, keep it simple }
IEnumerator TransitionToColor() { Lights2D lights2d = gameObject.transform.GetComponentInParent <Lights2D>(); Color lightColor = lights2d.lightColor; Color32 buttonColor = color; Vector3 destinationColor = new Vector3(lightColor.r * 255 * SliderControls.opa, lightColor.g * 255 * SliderControls.opa, lightColor.b * 255 * SliderControls.opa); Vector3 sourceColor = new Vector3(buttonColor.r * SliderControls.opa, buttonColor.g * SliderControls.opa, buttonColor.b * SliderControls.opa); Debug.Log("Destination color: " + destinationColor); Debug.Log("Source Color: " + sourceColor); SliderControls.ignore = true; float distance = Vector3.Distance(sourceColor, destinationColor); while (distance > 10) { Debug.Log("Inside the while loop"); Vector3 v = Vector3.Lerp(destinationColor, sourceColor, colorChangeSpeed * Time.deltaTime); Debug.Log("v is: " + v); //Assign the light to the light source lights2d.lightColor = new Color(v.x / 255, v.y / 255, v.z / 255); //set the proper vector values destinationColor = v; distance = Vector3.Distance(sourceColor, destinationColor); yield return(new WaitForFixedUpdate()); } //finally, setting the color to the exact value lights2d.lightColor = new Color(color.r * SliderControls.opa, color.g * SliderControls.opa, color.b * SliderControls.opa); SliderControls.ignore = false; yield break; }
IEnumerator SortLights() { //Debug.Log("lights list: " + lightsInScene.Count); if (!sorting) { //Debug.Log("sort"); sorting = true; int counter = 0; int c = 0; Vector3 cam = new Vector3(GameManager.Instance.cameraBounds[0].x, GameManager.Instance.cameraBounds[0].y, 0); //Debug.Log("camera pos:" + cam); //Debug.Log("lights in scene: " + lightsInScene.Count); for (int i = 0; i < lightsInScene.Count; i++) { Lights2D l = lightsInScene[i]; float distance1 = Vector3.SqrMagnitude(cam - lightsInScene[i].transform.position); if (c < 5) { for (int j = i + 1; j < lightsInScene.Count; j++) { float distance2 = Vector3.SqrMagnitude(cam - lightsInScene[j].transform.position); //Debug.Log("distance: " + distance2 + "light distance : " + lightsInScene[j].distance * lightsInScene[j].distance); if (distance2 < distance1) { //Swap the lights Lights2D temp = lightsInScene[i]; lightsInScene[i] = lightsInScene[j]; lightsInScene[j] = temp; } l = lightsInScene[i]; counter++; } } if(c > 5) { if (!l.controlledBySwitch) l.gameObject.SetActive(false); } c++; //l.gameObject.SetActive(false); if(counter > 10) { yield return new WaitForFixedUpdate(); counter = 0; } } //Gets the closest 5 lights and places them in the lights list lights.Clear(); int lightCounter = 0; int maxLights = 10; while(lightCounter < maxLights) { if (lightCounter > lightsInScene.Count - 1) break; if (lightsInScene[lightCounter].controlledBySwitch) { if (lightsInScene[lightCounter].gameObject.activeSelf) { lights.Add(lightsInScene[lightCounter]); } else maxLights++; } else { lightsInScene[lightCounter].gameObject.SetActive(true); lights.Add(lightsInScene[lightCounter]); } lightCounter++; } //for (int i = 0; i < 5; i++) //{ // if (i > lightsInScene.Count - 1) // break; // // lightsInScene[i].gameObject.SetActive(true); // lights.Add(lightsInScene[i]); //} } sorting = false; yield break; }