2026-01-29 06:58:38 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
|
|
|
|
|
public class PureUnityFan : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("--- 참조 ---")]
|
2026-01-29 16:11:10 +00:00
|
|
|
|
[SerializeField] private PlayerAttack attackScript;
|
|
|
|
|
|
[SerializeField] private PlayerInteraction interaction;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
[Header("--- 부채꼴 설정 ---")]
|
2026-01-29 16:11:10 +00:00
|
|
|
|
[SerializeField] private float radius = 5f;
|
|
|
|
|
|
[SerializeField] private int segments = 40;
|
|
|
|
|
|
[SerializeField] private Color fanColor = new Color(1f, 0.9f, 0f, 0.4f);
|
|
|
|
|
|
[Tooltip("풀차징 시에도 유지할 최소 부채꼴 각도 (너무 얇으면 안 보일 수 있음)")]
|
|
|
|
|
|
[SerializeField] private float minAngle = 2f; // ⭐ [추가] 최소 두께 설정
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
private Mesh _mesh;
|
|
|
|
|
|
private MeshFilter _meshFilter;
|
|
|
|
|
|
private MeshRenderer _meshRenderer;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_mesh = new Mesh();
|
|
|
|
|
|
_meshFilter = GetComponent<MeshFilter>();
|
|
|
|
|
|
_meshRenderer = GetComponent<MeshRenderer>();
|
|
|
|
|
|
_meshFilter.mesh = _mesh;
|
|
|
|
|
|
_meshRenderer.material.color = fanColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
// 1. 참조 확인 및 예외 처리
|
|
|
|
|
|
if (attackScript == null || interaction == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!attackScript.IsCharging || interaction.CurrentWeapon == null)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
_meshRenderer.enabled = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_meshRenderer.enabled = true;
|
|
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
// 2. 점진적 보간(Lerp)을 통한 부드러운 정확도 계산
|
|
|
|
|
|
float progress = attackScript.ChargeProgress; // 0.0 ~ 1.0
|
|
|
|
|
|
float smoothSpread;
|
|
|
|
|
|
|
|
|
|
|
|
var config = interaction.CurrentWeapon.Config;
|
|
|
|
|
|
float s1 = config.GetSpread(1); // 시작 정확도
|
|
|
|
|
|
float s2 = config.GetSpread(2); // 중간 정확도
|
|
|
|
|
|
float s3 = config.GetSpread(3); // 최종 정확도 (0)
|
|
|
|
|
|
|
|
|
|
|
|
if (progress < 0.5f)
|
|
|
|
|
|
{
|
|
|
|
|
|
smoothSpread = Mathf.Lerp(s1, s2, progress * 2f);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
smoothSpread = Mathf.Lerp(s2, s3, (progress - 0.5f) * 2f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. ⭐ [핵심 수정] 계산된 각도가 설정한 최소 각도보다 작아지지 않도록 제한
|
|
|
|
|
|
// (WeaponConfig에서 0을 반환하더라도, UI는 최소 minAngle만큼은 유지함)
|
|
|
|
|
|
float targetAngle = Mathf.Max(smoothSpread * 2f, minAngle);
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
CreateFanMesh(targetAngle);
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CreateFanMesh(float angle)
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
// 메쉬 생성 로직 (기존과 동일)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
int vertexCount = segments + 2;
|
|
|
|
|
|
Vector3[] vertices = new Vector3[vertexCount];
|
|
|
|
|
|
int[] triangles = new int[segments * 3];
|
|
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
vertices[0] = Vector3.zero;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
float halfAngle = angle / 2f;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <= segments; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
float currAngle = Mathf.Lerp(-halfAngle, halfAngle, (float)i / segments);
|
|
|
|
|
|
float rad = currAngle * Mathf.Deg2Rad;
|
|
|
|
|
|
vertices[i + 1] = new Vector3(Mathf.Sin(rad), 0, Mathf.Cos(rad)) * radius;
|
|
|
|
|
|
|
|
|
|
|
|
if (i < segments)
|
|
|
|
|
|
{
|
|
|
|
|
|
triangles[i * 3] = 0;
|
|
|
|
|
|
triangles[i * 3 + 1] = i + 1;
|
|
|
|
|
|
triangles[i * 3 + 2] = i + 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_mesh.Clear();
|
|
|
|
|
|
_mesh.vertices = vertices;
|
|
|
|
|
|
_mesh.triangles = triangles;
|
2026-01-29 16:11:10 +00:00
|
|
|
|
_mesh.RecalculateNormals();
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|