Files
aibis-dream/Assets/Scripts/MiniGame/HuoShan/Emo/TargetPointManager.cs
T
2025-05-08 16:17:49 +08:00

112 lines
3.8 KiB
C#

using UnityEngine;
using System.Collections.Generic;
using Shapes;
public enum TargetType
{
Sphere,
Cube,
Torus
}
public class TargetPointManager
{
private List<Vector3> targetPoints = new List<Vector3>();
private List<TargetType> targetTypes = new List<TargetType>();
private float targetSize;
private float wireScale;
private float heightOffset;
private Color entityColor;
private Color wireColor;
private float rotationSpeed;
private float floatSpeed;
private float floatHeight;
public TargetPointManager(float size, float wireScale, float height, Color entity, Color wire, float rotSpeed, float floatSpeed, float floatHeight)
{
this.targetSize = size;
this.wireScale = wireScale;
this.heightOffset = height;
this.entityColor = entity;
this.wireColor = wire;
this.rotationSpeed = rotSpeed;
this.floatSpeed = floatSpeed;
this.floatHeight = floatHeight;
}
public void AddTargetPoint(Vector3 position, TargetType type)
{
targetPoints.Add(position);
targetTypes.Add(type);
}
public void ClearTargetPoints()
{
targetPoints.Clear();
targetTypes.Clear();
}
public void DrawTargetPoints(float currentTime)
{
for (int i = 0; i < targetPoints.Count; i++)
{
Vector3 pos = targetPoints[i];
TargetType type = targetTypes[i];
// 计算浮动效果
float floatOffset = Mathf.Sin(currentTime * floatSpeed) * floatHeight;
Vector3 finalPos = pos + Vector3.up * (heightOffset + floatOffset);
// 绘制外框(立方体)
DrawWireCube(finalPos, targetSize * wireScale, wireColor);
// 绘制内部形状
switch (type)
{
case TargetType.Sphere:
Draw.Sphere(finalPos, targetSize * 0.8f, entityColor);
break;
case TargetType.Cube:
Draw.Cube(finalPos, Quaternion.Euler(0, currentTime * rotationSpeed, 0), targetSize * 0.8f, entityColor);
break;
case TargetType.Torus:
Draw.Torus(finalPos, Quaternion.Euler(0, currentTime * rotationSpeed, 0), targetSize * 0.8f, targetSize * 0.2f, entityColor);
break;
}
}
}
private void DrawWireCube(Vector3 position, float size, Color color)
{
float halfSize = size / 2f;
Vector3[] points = new Vector3[]
{
position + new Vector3(-halfSize, -halfSize, -halfSize),
position + new Vector3(halfSize, -halfSize, -halfSize),
position + new Vector3(halfSize, -halfSize, halfSize),
position + new Vector3(-halfSize, -halfSize, halfSize),
position + new Vector3(-halfSize, halfSize, -halfSize),
position + new Vector3(halfSize, halfSize, -halfSize),
position + new Vector3(halfSize, halfSize, halfSize),
position + new Vector3(-halfSize, halfSize, halfSize)
};
// 绘制底面
Draw.Line(points[0], points[1], 0.1f, color);
Draw.Line(points[1], points[2], 0.1f, color);
Draw.Line(points[2], points[3], 0.1f, color);
Draw.Line(points[3], points[0], 0.1f, color);
// 绘制顶面
Draw.Line(points[4], points[5], 0.1f, color);
Draw.Line(points[5], points[6], 0.1f, color);
Draw.Line(points[6], points[7], 0.1f, color);
Draw.Line(points[7], points[4], 0.1f, color);
// 绘制连接线
Draw.Line(points[0], points[4], 0.1f, color);
Draw.Line(points[1], points[5], 0.1f, color);
Draw.Line(points[2], points[6], 0.1f, color);
Draw.Line(points[3], points[7], 0.1f, color);
}
}