ThreeKingdomsSlingshot/Tools/recolor_fx.cs

147 lines
7.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEditor;
using UnityEngine;
// 이펙트 사본 색 바꾸기(PD 2026-11-10 「유비 예약 기운이 원색(파란색)처럼 보임 → 투명도·라이팅 · 노란 계열로」).
// 표 = Tools/fx_recolor.csv(s_src → s_out · 색상 · 바꿀 색상 범위 · 투명도 배수 · 더하기 섞기 층) · 원본 사본 무수정(새 사본으로 저장).
// 바꾸는 것 = 입자 시작 색 · 수명 색 · 사용자 데이터 색(Hyper Casual 2nd color = Custom2) · 지정 층 재질(set_apb → set_add = 빛처럼 더함).
// 실행: unity command --project-path "E:/NerdNavis/ThreeKingdomsSlingshot" script eval --file Tools/recolor_fx.cs
string dir = "Assets/Resources/Fx/";
var sb = new System.Text.StringBuilder();
bool InRange(float h, string from)
{
switch (from)
{
case "blue": return h >= 0.5f && h <= 0.75f;
case "red": return h <= 0.05f || h >= 0.9f;
case "green": return h >= 0.2f && h <= 0.45f;
default: return true;
}
}
Color tintColor = Color.white;
float satMul = 1f;
Color Shift(Color c, float hue, string from, float alpha)
{
float h, s, v;
Color.RGBToHSV(c, out h, out s, out v);
Color n = c;
if (from == "tint") // 회색·무채색도: 밝기(v)는 그대로 두고 색을 tintColor 로(흙먼지 → 모래색 · PD 2026-11-10)
{
n = new Color(tintColor.r * v, tintColor.g * v, tintColor.b * v, c.a);
}
else if (s >= 0.15f && InRange(h, from))
{
n = Color.HSVToRGB(hue, Mathf.Clamp01(s * satMul), v);
n.a = c.a;
}
n.a *= alpha;
return n;
}
Gradient Grad(Gradient g, float hue, string from, float alpha)
{
if (g == null) return null;
var ck = g.colorKeys;
for (int i = 0; i < ck.Length; i++) ck[i].color = Shift(ck[i].color, hue, from, 1f);
var ak = g.alphaKeys;
for (int i = 0; i < ak.Length; i++) ak[i].alpha *= alpha;
var ng = new Gradient();
ng.SetKeys(ck, ak);
ng.mode = g.mode;
return ng;
}
ParticleSystem.MinMaxGradient Mmg(ParticleSystem.MinMaxGradient m, float hue, string from, float alpha)
{
switch (m.mode)
{
case ParticleSystemGradientMode.Color: return new ParticleSystem.MinMaxGradient(Shift(m.color, hue, from, alpha));
case ParticleSystemGradientMode.TwoColors: return new ParticleSystem.MinMaxGradient(Shift(m.colorMin, hue, from, alpha), Shift(m.colorMax, hue, from, alpha));
case ParticleSystemGradientMode.TwoGradients: return new ParticleSystem.MinMaxGradient(Grad(m.gradientMin, hue, from, alpha), Grad(m.gradientMax, hue, from, alpha));
default:
var r = new ParticleSystem.MinMaxGradient(Grad(m.gradient, hue, from, alpha));
r.mode = m.mode;
return r;
}
}
string[] head = null;
foreach (var raw in System.IO.File.ReadAllLines("Tools/fx_recolor.csv"))
{
var line = raw.TrimStart('\uFEFF');
if (line.Trim().Length == 0 || line.StartsWith("#")) continue;
var cells = TKS.SkillVfx.SplitCsv(line);
if (head == null) { head = cells; continue; }
System.Func<string, string> C = k => { int i = System.Array.IndexOf(head, k); return i >= 0 && i < cells.Length ? cells[i].Trim() : ""; }; // \uBA38\uB9AC\uAE00 \uC774\uB984\uC73C\uB85C \uC77D\uC74C(\uCE78 \uCD94\uAC00\uC5D0 \uC548\uC804)
string src = dir + C("s_src") + ".prefab", outName = C("s_out");
if (outName.Length == 0) continue;
Color target;
ColorUtility.TryParseHtmlString(C("s_color"), out target);
float hue, ts, tv;
Color.RGBToHSV(target, out hue, out ts, out tv);
tintColor = target;
string from = C("s_hue_from").ToLowerInvariant();
float alpha = float.Parse(C("f_alpha"), System.Globalization.CultureInfo.InvariantCulture);
satMul = C("f_sat").Length > 0 ? float.Parse(C("f_sat"), System.Globalization.CultureInfo.InvariantCulture) : 1f;
var addLayers = new System.Collections.Generic.HashSet<string>(C("s_add_layers").Split(';'));
var offLayers = new System.Collections.Generic.HashSet<string>(C("s_off_layers").Split(';'));
// 한 번만 터질 층(s_once · 층:개수;… · 2026-11-12 PD 주창 「시전 이펙트의 먼지는 계속 생성되지 말고 처음 발동 시점에 한 번만」):
// 시간당 방출 0 · 시작 순간 한 번 그 개수만 터짐 → 반복 기운(b_loopall)에서는 처음 1번(표 s_rate 「층*0」과 함께 써서 반복 방출 없음)
var once = new System.Collections.Generic.Dictionary<string, int>();
foreach (var kv in C("s_once").Split(';'))
{
var p2 = kv.Split(':');
if (p2.Length == 2) once[p2[0].Trim()] = int.Parse(p2[1].Trim());
}
int onceN = 0;
string outPath = dir + outName + ".prefab";
if (!AssetDatabase.CopyAsset(src, outPath) && !System.IO.File.Exists(outPath)) { sb.AppendLine("복사 실패 " + src); continue; }
if (System.IO.File.Exists(outPath)) { AssetDatabase.DeleteAsset(outPath); AssetDatabase.CopyAsset(src, outPath); } // 다시 만들 때 = 원본 사본에서 새로
var go = PrefabUtility.LoadPrefabContents(outPath);
go.name = outName;
int n = 0, add = 0, off = 0;
foreach (var ps in go.GetComponentsInChildren<ParticleSystem>(true))
{
if (offLayers.Contains(ps.name)) // 끌 층(흙 조각 등) = 방출 끔 · 렌더러 끔
{
var em = ps.emission;
em.enabled = false;
var rr = ps.GetComponent<ParticleSystemRenderer>();
if (rr != null) rr.enabled = false;
off++;
continue;
}
int burst1;
if (once.TryGetValue(ps.name, out burst1))
{
var em1 = ps.emission;
em1.rateOverTime = 0f;
em1.SetBursts(new[] { new ParticleSystem.Burst(0f, (short)burst1) });
onceN++;
}
var m = ps.main;
m.startColor = Mmg(m.startColor, hue, from, alpha);
var col = ps.colorOverLifetime;
if (col.enabled) col.color = Mmg(col.color, hue, from, 1f);
var cd = ps.customData;
if (cd.enabled)
foreach (var st in new[] { ParticleSystemCustomData.Custom1, ParticleSystemCustomData.Custom2 })
if (cd.GetMode(st) == ParticleSystemCustomDataMode.Color) cd.SetColor(st, Mmg(cd.GetColor(st), hue, from, 1f));
var r = ps.GetComponent<ParticleSystemRenderer>();
if (r != null && addLayers.Contains(ps.name) && r.sharedMaterial != null && r.sharedMaterial.name.EndsWith("_apb"))
{
var addPath = AssetDatabase.GetAssetPath(r.sharedMaterial).Replace("_apb.mat", "_add.mat");
var addMat = AssetDatabase.LoadAssetAtPath<Material>(addPath);
if (addMat != null)
{
r.sharedMaterial = addMat;
add++;
}
}
n++;
}
PrefabUtility.SaveAsPrefabAsset(go, outPath);
PrefabUtility.UnloadPrefabContents(go);
sb.AppendLine(outName + " ← " + C("s_src") + " · 층 " + n + " · 더하기 " + add + " · 끔 " + off + " · 한 번만 " + onceN + " · 색상 " + hue.ToString("0.00") + " · 채도 ×" + satMul + " · 투명도 ×" + alpha);
}
AssetDatabase.SaveAssets();
return sb.ToString();