// Find the closest light to a position within a tolerance public DS2GXLightBase FindLightByPosition(Vector3 pos, float tolerance = 0.1f) { var lights = GetLights(); if (lights == null) { return(null); } DS2GXLightBase closest = null; float mindist = float.MaxValue; foreach (var light in lights) { float dist = Vector3.Distance(pos, light.Position); if (dist <= tolerance && dist < mindist) { closest = light; mindist = dist; } } return(closest); }
public void OnDrawGizmosSelected() { if (ConnectedLightDS2 != null && ConnectedLightDS2.IsValid()) { if (ConnectedLightDS2 is DS2GXSpotLight) { ((DS2GXSpotLight)ConnectedLightDS2).Transform = gameObject.transform.localToWorldMatrix; float angle2 = (ConeAngleWidthDS2 == 0.0f) ? ConeAngle : ConeAngleWidthDS2; Matrix4x4 projection = Matrix4x4.zero; float S1 = 1.0f / Mathf.Tan((ConeAngle / 2.0f) * Mathf.Deg2Rad); float S2 = 1.0f / Mathf.Tan((angle2 / 2.0f) * Mathf.Deg2Rad); projection.m00 = S2; projection.m11 = S1; projection.m22 = Radius / (Radius - NearPlane); projection.m23 = -Radius * NearPlane / (Radius - NearPlane); projection.m32 = 1.0f; ((DS2GXSpotLight)ConnectedLightDS2).Projection = projection; ((DS2GXSpotLight)ConnectedLightDS2).NearClip = NearPlane; ((DS2GXSpotLight)ConnectedLightDS2).FieldOfView = ConeAngle * Mathf.Deg2Rad; ((DS2GXSpotLight)ConnectedLightDS2).FieldOfViewWidth = angle2 * Mathf.Deg2Rad; ((DS2GXSpotLight)ConnectedLightDS2).FieldOfViewRatio = Mathf.Tan(angle2 * Mathf.Deg2Rad * 0.5f) / Mathf.Tan(ConeAngle * Mathf.Deg2Rad * 0.5f); } else { ConnectedLightDS2.Position = gameObject.transform.position; } ConnectedLightDS2.Diffuse = DiffuseColor; ConnectedLightDS2.DiffusePower = DiffusePower; ConnectedLightDS2.Specular = new Color(DiffuseColor.r * SpecularColor.r, DiffuseColor.g * SpecularColor.g, DiffuseColor.b * SpecularColor.b); ConnectedLightDS2.SpecularPower = SpecularPower; ConnectedLightDS2.Radius = Radius; ConnectedLightDS2.EnableShadows = CastsShadows; ConnectedLightDS2.FlickerMin = FlickerIntervalMin; ConnectedLightDS2.FlickerMax = FlickerIntervalMax; ConnectedLightDS2.FlickerMult = FlickerBrightnessMult; } else { ConnectedLightDS2 = null; } if (ConnectedLightDS3 != null && ConnectedLightDS3.IsValid()) { if (ConnectedLightDS3 is DS3GXSpotLight) { ((DS3GXSpotLight)ConnectedLightDS3).Transform = gameObject.transform.localToWorldMatrix; } else { ConnectedLightDS3.Position = gameObject.transform.position; } ConnectedLightDS3.Diffuse = DiffuseColor; ConnectedLightDS3.DiffusePower = DiffusePower; ConnectedLightDS3.Specular = new Color(DiffuseColor.r * SpecularColor.r, DiffuseColor.g * SpecularColor.g, DiffuseColor.b * SpecularColor.b); ConnectedLightDS3.SpecularPower = SpecularPower; ConnectedLightDS3.Radius = Radius; ConnectedLightDS3.EnableShadows = CastsShadows; ConnectedLightDS3.FlickerMin = FlickerIntervalMin; ConnectedLightDS3.FlickerMax = FlickerIntervalMax; ConnectedLightDS3.FlickerMult = FlickerBrightnessMult; } else { ConnectedLightDS3 = null; } }
public void SetConnectedLight(DS2GXLightBase light) { ConnectedLightDS2 = light; }