using System; using UnityEngine; namespace Leap.Unity { public static class Utils { public static void IgnoreCollisions(GameObject first, GameObject second, bool ignore = true) { if (first == null || second == null) { return; } Collider[] componentsInChildren = first.GetComponentsInChildren(); Collider[] componentsInChildren2 = second.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { for (int j = 0; j < componentsInChildren2.Length; j++) { if (componentsInChildren[i] != componentsInChildren2[j] && componentsInChildren[i].enabled && componentsInChildren2[j].enabled) { Physics.IgnoreCollision(componentsInChildren[i], componentsInChildren2[j], ignore); } } } } public static void DrawCircle(Vector3 center, Vector3 normal, float radius, Color color, int quality = 32, float duration = 0f, bool depthTest = true) { Vector3 forward = Vector3.Slerp(normal, -normal, 0.5f); Utils.DrawArc(360f, center, forward, normal, radius, color, quality, duration, depthTest); } public static void DrawArc(float arc, Vector3 center, Vector3 forward, Vector3 normal, float radius, Color color, int quality = 32, float duration = 0f, bool depthTest = true) { Vector3 normalized = Vector3.Cross(normal, forward).normalized; float num = arc / (float)quality; Vector3 start = center + forward * radius; Vector3 vector = default(Vector3); float num2 = 0f; while (Mathf.Abs(num2) <= Mathf.Abs(arc)) { float num3 = Mathf.Cos(num2 * 0.017453292f); float num4 = Mathf.Sin(num2 * 0.017453292f); vector.x = center.x + radius * (num3 * forward.x + num4 * normalized.x); vector.y = center.y + radius * (num3 * forward.y + num4 * normalized.y); vector.z = center.z + radius * (num3 * forward.z + num4 * normalized.z); Debug.DrawLine(start, vector, color, duration, depthTest); start = vector; num2 += num; } } public static void DrawCone(Vector3 origin, Vector3 direction, float angle, float height, Color color, int quality = 4, float duration = 0f, bool depthTest = true) { float num = height / (float)quality; for (float num2 = num; num2 <= height; num2 += num) { Utils.DrawCircle(origin + direction * num2, direction, Mathf.Tan(angle * 0.017453292f) * num2, color, quality * 8, duration, depthTest); } } } }