public static void DrawRect(Vector3 min, Vector3 max) { Vector3 leftTop = min; Vector3 leftBtm = new Vector3(min.x, min.y, max.z); Vector3 rightBtm = max; Vector3 rightTop = new Vector3(max.x, min.y, min.z); Vector3[] points = { leftTop, leftBtm, rightBtm, rightTop, leftTop }; DebugLine.DrawLine(points); }
public static void DrawRay( Vector3 start, Vector3 dir, Color color, Color endColor, float duration = 0, float width = 1) { DebugLine.DrawLine(start, start + dir, color, endColor, duration, width); }
public static void DrawLine(Vector3 start, Vector3 end, UnityEngine.Color color = default(UnityEngine.Color), float duration = 0.0f, float width = 1.0f, bool depthTest = true) { if (color.Equals(default(UnityEngine.Color))) { color = DebugColor.normal; } if (isEnabled) { if (Application.isEditor && Application.isPlaying) { UnityEngine.Debug.DrawLine(start, end, color, duration, depthTest); } if (Application.isPlaying && isGamingEnabled) { DebugLine.DrawLine(start, end, color, duration, width); } } }
void FixedUpdate() { var position = listener.position - transform.position; var distance = Vector3.Distance(listener.position, transform.position); var ray = new Ray(transform.position, position); var hits = Physics.RaycastAll(ray, distance, layerMask); var attenuation = (hits.Length > 1)?1f:0f; sound = new RaycastSound( name: name, time: distance / speedOfSound, volume: audio.volume, absorption: 0f, roughness: 0f, occlusion: 0f, attenuation: attenuation, position: position); #if _DEBUG var nearest = ray.GetPoint(distance); DebugLine.DrawLine(ray.origin, nearest, Color.red, Color.red, 10f, 1f); #endif }
//draw line functions - http://docs.unity3d.com/Documentation/ScriptReference/Debug.DrawLine.html public static void DrawLine(Vector3 start, Vector3 end) { DebugLine.DrawLine(start, end, Color.white); }
//draw ray functions - http://docs.unity3d.com/Documentation/ScriptReference/Debug.DrawRay.html public static void DrawRay(Vector3 start, Vector3 dir) { DebugLine.DrawLine(start, start + dir, Color.white); }
IEnumerator BouncingSound( float volume, float distance, Color color, Ray ray) { if (volume <= 0) { yield break; } if ((transform.position - ray.origin).sqrMagnitude > range * range) { yield break; } yield return(new WaitForFixedUpdate()); var hits = Physics.RaycastAll(ray, distance, layerMask); var list = hits.OrderBy(hit => hit.distance); var nextColor = Color.Lerp( color, new Color(color.r, color.g, color.b, 0), 0.5f); var nearest = ray.GetPoint(distance); if (list.Any()) { var hit = list.First(); var renderer = hit.transform.GetComponent <Renderer>(); var tex = renderer.material.mainTexture as Texture2D; if (list.Any()) { nearest = hit.point; } if (tex == null) { (tex = new Texture2D(1, 1)).SetPixel(0, 0, renderer.material.color); } var coords = Vector2.Scale( hit.textureCoord, new Vector2(tex.width, tex.height)); var texel = tex.GetPixel((int)coords.x, (int)coords.y); nextColor = Color.Lerp(nextColor, texel, 0.5f); yield return(StartCoroutine(BouncingSound( volume: CalculateDampening(volume, texel.grayscale), distance: distance, color: nextColor, ray: new Ray( origin: hit.point, direction: Vector3.Reflect( inDirection: ray.direction + ray.origin, inNormal: hit.normal))))); } else { yield return(StartCoroutine(BouncingSound( volume: CalculateDiffusion(volume), distance: distance, color: nextColor, ray: new Ray( origin: ray.GetPoint(distance), direction: ray.direction)))); } //#if _DEBUG DebugLine.DrawLine(ray.origin, nearest, color, nextColor, 10f, 1f); //#endif }