mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
轻轻松松改成定点数咯
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.General
|
||||
@@ -17,7 +18,7 @@ namespace GAS.General
|
||||
public static int CurrentFrameCount => _currentFrameCount;
|
||||
public static void UpdateCurrentFrameCount()
|
||||
{
|
||||
_currentFrameCount = Mathf.FloorToInt((Timestamp() - _startTimestamp) / 1000f * JexGasManager.FrameRate);
|
||||
_currentFrameCount = LMath.FloorToInt((Timestamp() - _startTimestamp) / LFloat.L1000 * JexGasManager.FrameRate);
|
||||
}
|
||||
|
||||
private static long _startTimestamp;
|
||||
|
@@ -1,17 +1,18 @@
|
||||
using UnityEngine;
|
||||
using JNGame.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.General
|
||||
{
|
||||
public static class DebugExtension
|
||||
{
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DebugBox(Vector2 center, Vector2 size, float angle, Color color, float showTime)
|
||||
public static void DebugBox(LVector2 center, LVector2 size, LFloat angle, Color color, LFloat showTime)
|
||||
{
|
||||
var halfSize = size * 0.5f;
|
||||
var p1 = new Vector2(center.x - halfSize.x, center.y - halfSize.y);
|
||||
var p2 = new Vector2(center.x + halfSize.x, center.y - halfSize.y);
|
||||
var p3 = new Vector2(center.x + halfSize.x, center.y + halfSize.y);
|
||||
var p4 = new Vector2(center.x - halfSize.x, center.y + halfSize.y);
|
||||
var halfSize = size * LFloat.L0D5;
|
||||
var p1 = new LVector2(center.x - halfSize.x, center.y - halfSize.y);
|
||||
var p2 = new LVector2(center.x + halfSize.x, center.y - halfSize.y);
|
||||
var p3 = new LVector2(center.x + halfSize.x, center.y + halfSize.y);
|
||||
var p4 = new LVector2(center.x - halfSize.x, center.y + halfSize.y);
|
||||
// p1 绕center旋转angle角度
|
||||
p1 = RotatePoint(center, p1, angle);
|
||||
p2 = RotatePoint(center, p2, angle);
|
||||
@@ -23,24 +24,24 @@ namespace GAS.General
|
||||
DrawLine(p4, p1, color, showTime);
|
||||
}
|
||||
|
||||
public static Vector2 RotatePoint(Vector2 center, Vector2 point, float angle)
|
||||
public static LVector2 RotatePoint(LVector2 center, LVector2 point, LFloat angle)
|
||||
{
|
||||
var cos = Mathf.Cos(angle * Mathf.Deg2Rad);
|
||||
var sin = Mathf.Sin(angle * Mathf.Deg2Rad);
|
||||
var cos = LMath.Cos(angle * LMath.Deg2Rad);
|
||||
var sin = LMath.Sin(angle * LMath.Deg2Rad);
|
||||
var x = cos * (point.x - center.x) - sin * (point.y - center.y) + center.x;
|
||||
var y = sin * (point.x - center.x) + cos * (point.y - center.y) + center.y;
|
||||
return new Vector2(x, y);
|
||||
return new LVector2(x, y);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DebugDrawCircle(Vector2 center, float radius, Color color, float showTime, float segments = 120)
|
||||
public static void DebugDrawCircle(LVector2 center, LFloat radius, Color color, LFloat showTime, LFloat segments = default) // segments = 120
|
||||
{
|
||||
var step = 360f / segments;
|
||||
var from = center + new Vector2(radius, 0);
|
||||
var step = LFloat.L360 / segments;
|
||||
var from = center + new LVector2(radius, LFloat.L0);
|
||||
for (var i = 0; i < segments; i++)
|
||||
{
|
||||
var to = center + new Vector2(radius * Mathf.Cos((i + 1) * step * Mathf.Deg2Rad),
|
||||
radius * Mathf.Sin((i + 1) * step * Mathf.Deg2Rad));
|
||||
var to = center + new LVector2(radius * LMath.Cos((i + 1) * step * LMath.Deg2Rad),
|
||||
radius * LMath.Sin((i + 1) * step * LMath.Deg2Rad));
|
||||
DrawLine(from, to, color, showTime);
|
||||
from = to;
|
||||
}
|
||||
@@ -52,20 +53,20 @@ namespace GAS.General
|
||||
/// <param name="position">位置, 圆心</param>
|
||||
/// <param name="rotation">旋转</param>
|
||||
/// <param name="radius">半径</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCircle(in Vector3 position, in Quaternion rotation, float radius, int segments = 36,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCircle(in LVector3 position, in LQuaternion rotation, LFloat radius, int segments = 36,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawArc(position, rotation, radius, 360, segments, color, duration);
|
||||
}
|
||||
|
||||
public static void DrawCircle(in Vector3 position, in Vector3 forward, float radius, int segments = 36,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCircle(in LVector3 position, in LVector3 forward, LFloat radius, int segments = 36,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawCircle(position, Quaternion.LookRotation(forward), radius, segments, color, duration);
|
||||
DrawCircle(position, LQuaternion.LookRotation(forward), radius, segments, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,33 +76,33 @@ namespace GAS.General
|
||||
/// <param name="rotation">旋转</param>
|
||||
/// <param name="radius">半径</param>
|
||||
/// <param name="angle">角度</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawArc(in Vector3 position, in Quaternion rotation, float radius, float angle, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawArc(in LVector3 position, in LQuaternion rotation, LFloat radius, LFloat angle, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
if (angle <= 0) return;
|
||||
if (radius <= 0) return;
|
||||
if (segments <= 0) return;
|
||||
|
||||
var angleStep = angle / segments;
|
||||
var lastPoint = position + rotation * (Vector3.right * radius);
|
||||
var lastPoint = position + rotation * (LVector3.Right * radius);
|
||||
for (int i = 1; i <= segments; i++)
|
||||
{
|
||||
var currentAngle = i * angleStep;
|
||||
var nextPoint = position + rotation * (Quaternion.Euler(0, currentAngle, 0) * Vector3.right * radius);
|
||||
var nextPoint = position + rotation * (LQuaternion.Euler(0, currentAngle, 0) * LVector3.Right * radius);
|
||||
DrawLine(lastPoint, nextPoint, color, duration);
|
||||
lastPoint = nextPoint;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawArc(in Vector3 position, in Vector3 forward, float radius, float angle, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawArc(in LVector3 position, in LVector3 forward, LFloat radius, LFloat angle, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawArc(position, Quaternion.LookRotation(forward), radius, angle, segments, color, duration);
|
||||
DrawArc(position, LQuaternion.LookRotation(forward), radius, angle, segments, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,27 +112,27 @@ namespace GAS.General
|
||||
/// <param name="rotation">旋转</param>
|
||||
/// <param name="outerRadius">外圈半径</param>
|
||||
/// <param name="innerRadius">内圈半径</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawRing(in Vector3 position, in Quaternion rotation, float outerRadius, float innerRadius, int segments = 36,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawRing(in LVector3 position, in LQuaternion rotation, LFloat outerRadius, LFloat innerRadius, int segments = 36,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
if (outerRadius <= 0) return;
|
||||
if (segments <= 0) return;
|
||||
|
||||
innerRadius = Mathf.Clamp(innerRadius, 0, outerRadius);
|
||||
innerRadius = LMath.Clamp(innerRadius, LFloat.L0, outerRadius);
|
||||
|
||||
// 计算圆的每个点的位置
|
||||
var angleStep = 360f / segments;
|
||||
var lastOuterPoint = position + rotation * (Vector3.right * outerRadius);
|
||||
var lastInnerPoint = position + rotation * (Vector3.right * innerRadius);
|
||||
var angleStep = LFloat.L360 / segments;
|
||||
var lastOuterPoint = position + rotation * (LVector3.Right * outerRadius);
|
||||
var lastInnerPoint = position + rotation * (LVector3.Right * innerRadius);
|
||||
for (int i = 1; i <= segments; i++)
|
||||
{
|
||||
var angle = i * angleStep;
|
||||
var nextOuterPoint = position + rotation * (Quaternion.Euler(0, angle, 0) * Vector3.right * outerRadius);
|
||||
var nextInnerPoint = position + rotation * (Quaternion.Euler(0, angle, 0) * Vector3.right * innerRadius);
|
||||
var nextOuterPoint = position + rotation * (LQuaternion.Euler(0, angle, 0) * LVector3.Right * outerRadius);
|
||||
var nextInnerPoint = position + rotation * (LQuaternion.Euler(0, angle, 0) * LVector3.Right * innerRadius);
|
||||
DrawLine(lastOuterPoint, nextOuterPoint, color, duration);
|
||||
DrawLine(lastInnerPoint, nextInnerPoint, color, duration);
|
||||
DrawLine(nextOuterPoint, nextInnerPoint, color, duration);
|
||||
@@ -141,10 +142,10 @@ namespace GAS.General
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawRing(in Vector3 position, in Vector3 forward, float outerRadius, float innerRadius, int segments = 36,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawRing(in LVector3 position, in LVector3 forward, LFloat outerRadius, LFloat innerRadius, int segments = 36,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawRing(position, Quaternion.LookRotation(forward), outerRadius, innerRadius, segments, color, duration);
|
||||
DrawRing(position, LQuaternion.LookRotation(forward), outerRadius, innerRadius, segments, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -156,16 +157,16 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawRectangle(in Vector3 position, in Quaternion rotation, in Vector2 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawRectangle(in LVector3 position, in LQuaternion rotation, in LVector2 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
// 计算矩形的四个角点在局部坐标系中的位置
|
||||
var halfSize = new Vector3(size.x * 0.5f, 0, size.y * 0.5f);
|
||||
var corners = new Vector3[4];
|
||||
corners[0] = new Vector3(-halfSize.x, 0, -halfSize.z); // 左下角
|
||||
corners[1] = new Vector3(halfSize.x, 0, -halfSize.z); // 右下角
|
||||
corners[2] = new Vector3(halfSize.x, 0, halfSize.z); // 右上角
|
||||
corners[3] = new Vector3(-halfSize.x, 0, halfSize.z); // 左上角
|
||||
var halfSize = new LVector3(size.x * LFloat.L0D5, LFloat.L0, size.y * LFloat.L0D5);
|
||||
var corners = new LVector3[4];
|
||||
corners[0] = new LVector3(-halfSize.x, LFloat.L0, -halfSize.z); // 左下角
|
||||
corners[1] = new LVector3(halfSize.x, LFloat.L0, -halfSize.z); // 右下角
|
||||
corners[2] = new LVector3(halfSize.x, LFloat.L0, halfSize.z); // 右上角
|
||||
corners[3] = new LVector3(-halfSize.x, LFloat.L0, halfSize.z); // 左上角
|
||||
|
||||
// 旋转角点并转换到世界坐标系
|
||||
for (int i = 0; i < corners.Length; i++)
|
||||
@@ -181,10 +182,10 @@ namespace GAS.General
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawRectangle(in Vector3 position, in Vector3 forward, in Vector2 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawRectangle(in LVector3 position, in LVector3 forward, in LVector2 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawRectangle(position, Quaternion.LookRotation(forward), size, color, duration);
|
||||
DrawRectangle(position, LQuaternion.LookRotation(forward), size, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -196,16 +197,16 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawFrontRectangle(in Vector3 position, in Quaternion rotation, in Vector2 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawFrontRectangle(in LVector3 position, in LQuaternion rotation, in LVector2 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
// 计算矩形的四个角点在局部坐标系中的位置
|
||||
var halfX = size.x * 0.5f;
|
||||
var corners = new Vector3[4];
|
||||
corners[0] = new Vector3(-halfX, 0, 0); // 左下角
|
||||
corners[1] = new Vector3(halfX, 0, 0); // 右下角
|
||||
corners[2] = new Vector3(halfX, 0, size.y); // 右上角
|
||||
corners[3] = new Vector3(-halfX, 0, size.y); // 左上角
|
||||
var halfX = size.x * LFloat.L0D5;
|
||||
var corners = new LVector3[4];
|
||||
corners[0] = new LVector3(-halfX, LFloat.L0, LFloat.L0); // 左下角
|
||||
corners[1] = new LVector3(halfX, LFloat.L0, LFloat.L0); // 右下角
|
||||
corners[2] = new LVector3(halfX, LFloat.L0, size.y); // 右上角
|
||||
corners[3] = new LVector3(-halfX, LFloat.L0, size.y); // 左上角
|
||||
|
||||
// 旋转角点并转换到世界坐标系
|
||||
for (int i = 0; i < corners.Length; i++)
|
||||
@@ -221,10 +222,10 @@ namespace GAS.General
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawFrontRectangle(in Vector3 position, in Vector3 forward, in Vector2 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawFrontRectangle(in LVector3 position, in LVector3 forward, in LVector2 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawFrontRectangle(position, Quaternion.LookRotation(forward), size, color, duration);
|
||||
DrawFrontRectangle(position, LQuaternion.LookRotation(forward), size, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -236,24 +237,24 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCube(in Vector3 position, in Quaternion rotation, in Vector3 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCube(in LVector3 position, in LQuaternion rotation, in LVector3 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
// 计算立方体的八个顶点在局部坐标系中的位置
|
||||
var halfSize = size * 0.5f;
|
||||
var vertices = new Vector3[8];
|
||||
var halfSize = size * LFloat.L0D5;
|
||||
var vertices = new LVector3[8];
|
||||
|
||||
// 下底面四个顶点
|
||||
vertices[0] = new Vector3(-halfSize.x, -halfSize.y, -halfSize.z);
|
||||
vertices[1] = new Vector3(halfSize.x, -halfSize.y, -halfSize.z);
|
||||
vertices[2] = new Vector3(halfSize.x, -halfSize.y, halfSize.z);
|
||||
vertices[3] = new Vector3(-halfSize.x, -halfSize.y, halfSize.z);
|
||||
vertices[0] = new LVector3(-halfSize.x, -halfSize.y, -halfSize.z);
|
||||
vertices[1] = new LVector3(halfSize.x, -halfSize.y, -halfSize.z);
|
||||
vertices[2] = new LVector3(halfSize.x, -halfSize.y, halfSize.z);
|
||||
vertices[3] = new LVector3(-halfSize.x, -halfSize.y, halfSize.z);
|
||||
|
||||
// 上顶面四个顶点
|
||||
vertices[4] = new Vector3(-halfSize.x, halfSize.y, -halfSize.z);
|
||||
vertices[5] = new Vector3(halfSize.x, halfSize.y, -halfSize.z);
|
||||
vertices[6] = new Vector3(halfSize.x, halfSize.y, halfSize.z);
|
||||
vertices[7] = new Vector3(-halfSize.x, halfSize.y, halfSize.z);
|
||||
vertices[4] = new LVector3(-halfSize.x, halfSize.y, -halfSize.z);
|
||||
vertices[5] = new LVector3(halfSize.x, halfSize.y, -halfSize.z);
|
||||
vertices[6] = new LVector3(halfSize.x, halfSize.y, halfSize.z);
|
||||
vertices[7] = new LVector3(-halfSize.x, halfSize.y, halfSize.z);
|
||||
|
||||
// 旋转顶点并转换到世界坐标系
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
@@ -279,10 +280,10 @@ namespace GAS.General
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCube(in Vector3 position, in Vector3 forward, in Vector3 size,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCube(in LVector3 position, in LVector3 forward, in LVector3 size,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawCube(position, Quaternion.LookRotation(forward), size, color, duration);
|
||||
DrawCube(position, LQuaternion.LookRotation(forward), size, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -296,10 +297,10 @@ namespace GAS.General
|
||||
/// <param name="color"></param>
|
||||
/// <param name="duration"></param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCylinder(in Vector3 position, in Quaternion rotation, float radius, float height, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCylinder(in LVector3 position, in LQuaternion rotation, LFloat radius, LFloat height, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
var offset = rotation * Vector3.up * (height * 0.5f);
|
||||
var offset = rotation * LVector3.Up * (height * LFloat.L0D5);
|
||||
var topCenter = position + offset;
|
||||
var bottomCenter = position - offset;
|
||||
DrawCylinder(topCenter, bottomCenter, radius, segments, color, duration);
|
||||
@@ -316,42 +317,42 @@ namespace GAS.General
|
||||
/// <param name="color"></param>
|
||||
/// <param name="duration"></param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCylinder(in Vector3 position, in Vector3 forward, float radius, float height, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCylinder(in LVector3 position, in LVector3 forward, LFloat radius, LFloat height, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawCylinder(position, Quaternion.LookRotation(forward), radius, height, segments, in color, duration);
|
||||
DrawCylinder(position, LQuaternion.LookRotation(forward), radius, height, segments, in color, duration);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawCylinder(in Vector3 topCenter, in Vector3 bottomCenter, float radius, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawCylinder(in LVector3 topCenter, in LVector3 bottomCenter, LFloat radius, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
if (radius <= 0) return;
|
||||
if (segments <= 0) return;
|
||||
|
||||
if (Vector3.Distance(topCenter, bottomCenter) <= Mathf.Epsilon) return;
|
||||
if (LVector3.Distance(topCenter, bottomCenter) <= LFloat.EPSILON) return;
|
||||
|
||||
var direction = (topCenter - bottomCenter).normalized;
|
||||
var direction = (topCenter - bottomCenter).Normalized;
|
||||
|
||||
// 计算一个垂直于direction的向量作为forward
|
||||
var forward = Vector3.Cross(direction, Vector3.up).normalized;
|
||||
var forward = LVector3.Cross(direction, LVector3.Up).Normalized;
|
||||
|
||||
// 如果forward和direction平行(即direction和Vector3.up共线),则选择一个不同的方向作为forward
|
||||
if (forward == Vector3.zero)
|
||||
// 如果forward和direction平行(即direction和LVector3.up共线),则选择一个不同的方向作为forward
|
||||
if (forward == LVector3.Zero)
|
||||
{
|
||||
forward = Vector3.Cross(direction, Vector3.right).normalized;
|
||||
forward = LVector3.Cross(direction, LVector3.Right).Normalized;
|
||||
}
|
||||
|
||||
var rotation = Quaternion.LookRotation(forward, direction);
|
||||
var rotation = LQuaternion.LookRotation(forward, direction);
|
||||
|
||||
var angleStep = 360f / segments;
|
||||
var offset = rotation * (Vector3.right * radius);
|
||||
var angleStep = LFloat.L360 / segments;
|
||||
var offset = rotation * (LVector3.Right * radius);
|
||||
var lastTopPoint = topCenter + offset;
|
||||
var lastBottomPoint = bottomCenter + offset;
|
||||
for (int i = 1; i <= segments; i++)
|
||||
{
|
||||
var currentAngle = i * angleStep;
|
||||
offset = rotation * (Quaternion.Euler(0, currentAngle, 0) * (Vector3.right * radius));
|
||||
offset = rotation * (LQuaternion.Euler(0, currentAngle, 0) * (LVector3.Right * radius));
|
||||
var nextTopPoint = topCenter + offset;
|
||||
var nextBottomPoint = bottomCenter + offset;
|
||||
DrawLine(lastTopPoint, nextTopPoint, color, duration);
|
||||
@@ -369,21 +370,21 @@ namespace GAS.General
|
||||
/// <param name="rotation">旋转</param>
|
||||
/// <param name="radius">扇形的半径</param>
|
||||
/// <param name="angle">扇形的角度(度)</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawSector(Vector3 position, Quaternion rotation, float radius, float angle, int segments = 12,
|
||||
Color? color = null, float duration = 0f)
|
||||
public static void DrawSector(LVector3 position, LQuaternion rotation, LFloat radius, LFloat angle, int segments = 12,
|
||||
Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawAnnularSector(position, rotation, radius, 0, angle, segments, color, duration);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawSector(in Vector3 position, in Vector3 forward, float radius, float angle, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawSector(in LVector3 position, in LVector3 forward, LFloat radius, LFloat angle, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawSector(position, Quaternion.LookRotation(forward), radius, angle, segments, color, duration);
|
||||
DrawSector(position, LQuaternion.LookRotation(forward), radius, angle, segments, color, duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,29 +396,29 @@ namespace GAS.General
|
||||
/// <param name="outerRadius">扇形的外半径</param>
|
||||
/// <param name="innerRadius">扇形的内半径, 为0时为标准扇形</param>
|
||||
/// <param name="angle">扇形的角度(度)</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = Mathf.CeilToInt(angle / 10))</param>
|
||||
/// <param name="segments">分段数(建议与角度适配, 如每10°分一段: segments = LMath.CeilToInt(angle / 10))</param>
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawAnnularSector(in Vector3 position, in Quaternion rotation, float outerRadius, float innerRadius, float angle, int segments = 12,
|
||||
in Color? color = null, float duration = 0f)
|
||||
public static void DrawAnnularSector(in LVector3 position, in LQuaternion rotation, LFloat outerRadius, LFloat innerRadius, LFloat angle, int segments = 12,
|
||||
in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
if (outerRadius <= 0) return;
|
||||
if (segments <= 0) return;
|
||||
if (angle <= 0) return;
|
||||
|
||||
innerRadius = Mathf.Clamp(innerRadius, 0, outerRadius);
|
||||
innerRadius = LMath.Clamp(innerRadius, LFloat.L0, outerRadius);
|
||||
|
||||
var angleStep = angle / segments;
|
||||
var currentAngle = -angle * 0.5f;
|
||||
var currentAngle = -angle * LFloat.L0D5;
|
||||
|
||||
var outerPoints = new Vector3[segments + 1];
|
||||
var innerPoints = new Vector3[segments + 1];
|
||||
var outerPoints = new LVector3[segments + 1];
|
||||
var innerPoints = new LVector3[segments + 1];
|
||||
|
||||
// 计算内外扇形的点
|
||||
for (var i = 0; i <= segments; i++)
|
||||
{
|
||||
var currentDirection = rotation * Quaternion.Euler(0, currentAngle, 0) * Vector3.forward;
|
||||
var currentDirection = rotation * LQuaternion.Euler(0, currentAngle, 0) * LVector3.Forward;
|
||||
outerPoints[i] = position + currentDirection * outerRadius;
|
||||
innerPoints[i] = position + currentDirection * innerRadius;
|
||||
currentAngle += angleStep;
|
||||
@@ -443,9 +444,9 @@ namespace GAS.General
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawAnnularSector(in Vector3 position, in Vector3 forward, float outerRadius, float innerRadius, float angle, int segments = 12, in Color? color = null, float duration = 0f)
|
||||
public static void DrawAnnularSector(in LVector3 position, in LVector3 forward, LFloat outerRadius, LFloat innerRadius, LFloat angle, int segments = 12, in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawAnnularSector(position, Quaternion.LookRotation(forward), outerRadius, innerRadius, angle, segments, color, duration);
|
||||
DrawAnnularSector(position, LQuaternion.LookRotation(forward), outerRadius, innerRadius, angle, segments, color, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -456,9 +457,9 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawLine(in Vector3 start, in Vector3 end, in Color? color = null, float duration = 0f)
|
||||
public static void DrawLine(in LVector3 start, in LVector3 end, in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
Debug.DrawLine(start, end, color ?? Color.cyan, duration);
|
||||
Debug.DrawLine(start.ToVector3(), end.ToVector3(), color ?? Color.cyan, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -469,12 +470,12 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawArrow(in Vector3 origin, in Vector3 destination, in Color? color = null, float duration = 0f)
|
||||
public static void DrawArrow(in LVector3 origin, in LVector3 destination, in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
DrawLine(origin, destination, color, duration);
|
||||
var direction = destination - origin;
|
||||
var right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + 30, 0) * Vector3.forward;
|
||||
var left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - 30, 0) * Vector3.forward;
|
||||
var right = LQuaternion.LookRotation(direction) * LQuaternion.Euler(0, 180 + 30, 0) * LVector3.Forward;
|
||||
var left = LQuaternion.LookRotation(direction) * LQuaternion.Euler(0, 180 - 30, 0) * LVector3.Forward;
|
||||
DrawLine(destination, destination + right, color, duration);
|
||||
DrawLine(destination, destination + left, color, duration);
|
||||
}
|
||||
@@ -489,17 +490,17 @@ namespace GAS.General
|
||||
/// <param name="color">颜色</param>
|
||||
/// <param name="duration">绘制时长(0为1帧)</param>
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawArrow(in Vector3 origin, in Quaternion rotation, float length, in Color? color = null, float duration = 0f)
|
||||
public static void DrawArrow(in LVector3 origin, in LQuaternion rotation, LFloat length, in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
var direction = rotation * Vector3.forward;
|
||||
var direction = rotation * LVector3.Forward;
|
||||
var destination = origin + direction * length;
|
||||
DrawArrow(origin, destination, color, duration);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void DrawArrow(in Vector3 origin, in Vector3 direction, float length, in Color? color = null, float duration = 0f)
|
||||
public static void DrawArrow(in LVector3 origin, in LVector3 direction, LFloat length, in Color? color = null, LFloat duration = default) //duration = 0
|
||||
{
|
||||
var destination = origin + direction.normalized * length;
|
||||
var destination = origin + direction.Normalized * length;
|
||||
DrawArrow(origin, destination, color, duration);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user