Project_WL/Assets/WL/Combat/WLArcTint.cs

67 lines
4.2 KiB
C#

// ─────────────────────────────────────────────────────────────────────────────
// WLArcTint.cs — 근접 공용 호(Effect_WLSwingArc) 입자 색을 직업 색으로 (#963 · 2026-10-21)
//
// PD 원문(#963-①): 「비수공격 1타와 2타 크기를 3타와 4격 공격 수준으로 더 줄이고 푸른 컬러를 녹색 계열로 변경해줘.」
// ■ 실측 — 1·2타 호 = 모든 근접 직업이 같이 쓰는 Effect_WLSwingArc(Simple Stylized Slash vol2 M_slashB_Add/Alp · 재질 색 속성 = 가장자리색뿐) →
// 색은 입자 시작색이라 직업 궤적 색(SlashTrailSettings 직업 덮기 colorAdditive)이 닿지 않았다(Play 캡처 · 렌더러 목록).
// ■ 처리 — WeaponTrailDriver 호 배치 직후 훅 1줄: 그 직업 덮기의 overrideLook 이 켜져 있으면 호 입자(살아 있는 것 + 다음 분출)의 색을
// colorAdditive 색조(명도 · 알파는 원래 값)로 · 아니면 이 인스턴스의 원래 시작색으로 되돌린다(풀 공유).
// 🔴 Debug.LogError 금지.
// ─────────────────────────────────────────────────────────────────────────────
using UnityEngine;
namespace WL.Combat
{
public static class WLArcTint
{
public static int Tinted, Restored;
static ParticleSystem.Particle[] s_buf = new ParticleSystem.Particle[256];
sealed class Orig : MonoBehaviour { public ParticleSystem[] ps; public ParticleSystem.MinMaxGradient[] col; public bool tinted; }
public static void Apply(GameObject arc, SlashTrailClassOverride cov)
{
if (arc == null) return;
try
{
var o = arc.GetComponent<Orig>();
if (o == null)
{
o = arc.AddComponent<Orig>(); o.ps = arc.GetComponentsInChildren<ParticleSystem>(true);
o.col = new ParticleSystem.MinMaxGradient[o.ps.Length]; for (int i = 0; i < o.ps.Length; i++) o.col[i] = o.ps[i].main.startColor;
}
bool want = cov != null && cov.overrideLook;
if (!want && !o.tinted) return;
float th = 0f, ts = 0f, tv;
if (want) Color.RGBToHSV(cov.colorAdditive, out th, out ts, out tv);
for (int i = 0; i < o.ps.Length; i++)
{
var ps = o.ps[i]; if (ps == null) continue;
var m = ps.main;
if (!want) { m.startColor = o.col[i]; continue; }
m.startColor = Retint(o.col[i], th, ts);
int n = ps.GetParticles(s_buf); // 이미 나온 입자(호는 생성 순간 한 번에 분출)
for (int k = 0; k < n; k++) { var c = (Color)s_buf[k].startColor; s_buf[k].startColor = Hue(c, th, ts); }
if (n > 0) ps.SetParticles(s_buf, n);
}
o.tinted = want; if (want) Tinted++; else Restored++;
}
catch (System.Exception) { }
}
static Color Hue(Color c, float th, float ts) { float h, s, v; Color.RGBToHSV(c, out h, out s, out v); var r = Color.HSVToRGB(th, Mathf.Max(s, ts * 0.6f), v); r.a = c.a; return r; }
static ParticleSystem.MinMaxGradient Retint(ParticleSystem.MinMaxGradient g, float th, float ts)
{
switch (g.mode)
{
case ParticleSystemGradientMode.Color: return new ParticleSystem.MinMaxGradient(Hue(g.color, th, ts));
case ParticleSystemGradientMode.TwoColors: return new ParticleSystem.MinMaxGradient(Hue(g.colorMin, th, ts), Hue(g.colorMax, th, ts));
default:
if (g.gradient == null) return g;
var ng = new Gradient(); var ks = g.gradient.colorKeys; for (int k = 0; k < ks.Length; k++) ks[k].color = Hue(ks[k].color, th, ts);
ng.SetKeys(ks, g.gradient.alphaKeys); return new ParticleSystem.MinMaxGradient(ng);
}
}
}
}