using UnityEngine;
namespace TKS
{
///
/// 반복 이펙트의 입자를 좌우로 까딱까딱 기울인다(표 skill_vfx.csv s_wobble = 「각도*주기」 · 각도 = 한쪽으로 기우는 최대 도 · 주기 = 왼쪽 → 오른쪽 → 왼쪽 한 번의 초 ·
/// PD 2026-11-13 「물음표에 움직임 · 각도만 살짝 왼쪽으로 기울였다가 오른쪽으로 기울이는 형태로 지속시간 동안 까딱 까딱」).
/// 화면을 보는 입자(빌보드)는 오브젝트를 돌려도 안 돌아가므로 입자 회전 값을 매 프레임 직접 넣는다.
///
public class SkillVfxWobble : MonoBehaviour
{
float deg;
float period = 1f;
float t0;
ParticleSystem[] systems;
ParticleSystem.Particle[] buf = new ParticleSystem.Particle[16];
public void Init(float maxDeg, float seconds)
{
deg = maxDeg;
period = Mathf.Max(0.1f, seconds);
t0 = Time.time;
systems = GetComponentsInChildren(true);
}
void LateUpdate()
{
if (systems == null || deg <= 0f) return;
float a = deg * Mathf.Sin((Time.time - t0) * Mathf.PI * 2f / period);
foreach (var ps in systems)
{
if (ps == null || ps.main.startRotation3D) continue;
int n = ps.particleCount;
if (n <= 0) continue;
if (buf.Length < n) buf = new ParticleSystem.Particle[n];
n = ps.GetParticles(buf, n);
for (int i = 0; i < n; i++) buf[i].rotation = a;
ps.SetParticles(buf, n);
}
}
}
}