You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
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 DrawShape(Shape shape, Vector3 posReal, Vector3 direction, Color color)
|
|
{
|
|
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, posReal, direction, color);
|
|
break;
|
|
case EShapeType.Sector:
|
|
DrawShapeBody(shape, posReal, direction, color);
|
|
break;
|
|
case EShapeType.Circle:
|
|
DrawShapeBody(shape, posReal, 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 posReal, Vector3 direction, Color color)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
} |