using System.Collections; using UnityEngine; namespace Game { public abstract partial class Util { public static void Draw(Vector3 start, Vector3 end, Color color, float duration = 0) { if (!GameSetting.IsDebugDraw) { return; } Debug.DrawLine(start, end, color, duration); } public static void DrawBox(Vector3 center, Vector3 halfExtents, Vector3 direction, Color color, float duration = 0) { if (!GameSetting.IsDebugDraw) { return; } var rot = Quaternion.FromToRotation(Vector3.right, direction); var boxPoints = new Vector3[8]; boxPoints[0] = center + rot * new Vector3(halfExtents.x, halfExtents.y, halfExtents.z); boxPoints[1] = center + rot * new Vector3(halfExtents.x, halfExtents.y, -halfExtents.z); boxPoints[2] = center + rot * new Vector3(halfExtents.x, -halfExtents.y, halfExtents.z); boxPoints[3] = center + rot * new Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z); boxPoints[4] = center + rot * new Vector3(-halfExtents.x, halfExtents.y, halfExtents.z); boxPoints[5] = center + rot * new Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z); boxPoints[6] = center + rot * new Vector3(-halfExtents.x, -halfExtents.y, halfExtents.z); boxPoints[7] = center + rot * new Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z); for (int i = 0; i < 8; i++) { for (int j = i; j < 8; j++) { var p1 = boxPoints[i]; var p2 = boxPoints[j]; int defCount = 0; defCount += (p1.x == p2.x ? 1 : 0); defCount += (p1.y == p2.y ? 1 : 0); defCount += (p1.z == p2.z ? 1 : 0); Debug.DrawLine(boxPoints[i], boxPoints[j], color, duration); } } } public static void DrawShape(Shape shape, Vector3 pos, Vector3 direction, Color color) { var posReal = pos + shape.Offset; var posRealTop = posReal + Vector3.up * shape.Height; var posRealMid = posReal + Vector3.up * (shape.Height / 2); switch (shape.Type) { case EShapeType.Dot: DrawShapeCross(posReal, 1, color); DrawShapeCenter(posReal, 1, color); break; case EShapeType.Box: DrawShapeBody(shape, pos, direction, color); break; case EShapeType.Sector: DrawShapeBody(shape, pos, direction, color); break; case EShapeType.Circle: DrawShapeBody(shape, pos, direction, color); DrawShapeCenter(posRealMid, shape.Height / 2, color); DrawShapeCross(posReal, shape.Radius, color); DrawShapeCross(posRealTop, shape.Radius, color); break; } } private static void DrawShapeCenter(Vector3 pos, float h, Color color) { Debug.DrawLine(pos + Vector3.down * h, pos + Vector3.up * h, color); } private static void DrawShapeCross(Vector3 pos, float r, Color color) { Debug.DrawLine(pos + Vector3.left * r, pos + Vector3.right * r, color); Debug.DrawLine(pos + Vector3.back * r, pos + Vector3.forward * r, color); } private static void DrawShapeBody(Shape shape, Vector3 pos, Vector3 direction, Color color) { var posReal = pos + shape.Offset; var posRealTop = posReal + Vector3.up * shape.Height; shape.ForeachVerticesPair(direction, (v1, v2) => { Debug.DrawLine(posReal + v1, posReal + v2, color); Debug.DrawLine(posRealTop + v1, posRealTop + v2, color); }); shape.ForeachVertices(direction, v => { Debug.DrawLine(posReal + v, posRealTop + v, color); }); } public static void Print(params object[] values) { string text = ""; foreach (object obj in values) { text += Str(obj) + " "; } Debug.Log(text); } private static string Str(object obj) { string ret = ""; if (obj is null) { ret = $"null"; } else if (obj is string) { ret = $"\"{obj}\""; } else if (obj is IEnumerable) { ret += "List["; foreach (object subobj in (IEnumerable)obj) { ret += Str(subobj) + " "; } ret += "]"; } else { ret = obj.ToString(); } return ret; } } }