ThreeKingdomsSlingshot/Tools/build_tornado.cs

127 lines
5.7 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;
// 제갈근 선풍계 회오리 프리팹(2026-11-19 PD 「제갈근의 회오리가 여전히 부자연스러워 · 첨부 파일과 같은 느낌」)
// TKS_Fx_C_Tornado = 평평한 만화 회오리 그림 16 장(Tools/make_tornado_texture.py → Assets/VFX/TKS2D/sk_tornado_sheet.png · 4 × 4)을 입자 1개가 칸 넘김으로 돌림 ·
// 크기 단위 = 유닛 키 1(표 size 1) · 기준점 = 회오리 끝(발밑) · 그림은 기준점 위로 1 · 수명 10초(날아가는 동안 · 도착하면 표 f_fade 로 흐려짐) ·
// 한 바퀴 = SPIN 초 · 처음 POP 초에 0.6 → 1 크기로 커지며 나타남.
// 실행: python -I -X utf8 Tools/make_tornado_texture.py . → unity command --project-path . --timeout 300 script eval --file Tools/build_tornado.cs
string tex = "Assets/VFX/TKS2D/sk_tornado_sheet.png";
string matPath = "Assets/VFX/TKS2D/Mat_sk_tornado.mat";
string dst = "Assets/Resources/Fx/TKS_Fx_C_Tornado.prefab";
float LIFE = 10f, SPIN = 0.5f, POP = 0.15f;
AssetDatabase.Refresh();
var ti = AssetImporter.GetAtPath(tex) as TextureImporter;
if (ti == null) return "그림 없음: " + tex;
ti.textureType = TextureImporterType.Default;
ti.sRGBTexture = true;
ti.alphaIsTransparency = true;
ti.wrapMode = TextureWrapMode.Clamp;
ti.mipmapEnabled = true;
ti.textureCompression = TextureImporterCompression.Uncompressed;
ti.SaveAndReimport();
var mat = AssetDatabase.LoadAssetAtPath<Material>(matPath);
if (mat == null)
{
mat = new Material(Shader.Find("Sprites/Default"));
AssetDatabase.CreateAsset(mat, matPath);
}
mat.shader = Shader.Find("Sprites/Default");
mat.mainTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(tex);
EditorUtility.SetDirty(mat);
var root = new GameObject("TKS_Fx_C_Tornado");
var body = new GameObject("Body");
body.transform.SetParent(root.transform, false);
body.transform.localPosition = new Vector3(0f, 0.5f, 0f);
var ps = body.AddComponent<ParticleSystem>();
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
var m = ps.main;
m.duration = LIFE;
m.loop = false;
m.playOnAwake = true;
m.startLifetime = LIFE;
m.startSpeed = 0f;
m.startSize = 1f;
m.maxParticles = 1;
m.gravityModifier = 0f;
m.simulationSpace = ParticleSystemSimulationSpace.Local;
m.scalingMode = ParticleSystemScalingMode.Hierarchy;
var em = ps.emission;
em.rateOverTime = 0f;
em.SetBursts(new[] { new ParticleSystem.Burst(0f, 1) });
var sh = ps.shape;
sh.enabled = false;
var ts = ps.textureSheetAnimation;
ts.enabled = true;
ts.mode = ParticleSystemAnimationMode.Grid;
ts.numTilesX = 4;
ts.numTilesY = 4;
ts.animation = ParticleSystemAnimationType.WholeSheet;
ts.cycleCount = Mathf.Max(1, Mathf.RoundToInt(LIFE / SPIN));
var sz = ps.sizeOverLifetime;
sz.enabled = true;
sz.size = new ParticleSystem.MinMaxCurve(1f, new AnimationCurve(new Keyframe(0f, 0.6f), new Keyframe(POP / LIFE, 1f), new Keyframe(1f, 1f)));
var col = ps.colorOverLifetime;
col.enabled = true;
var g = new Gradient();
g.SetKeys(new[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) },
new[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(1f, POP / LIFE), new GradientAlphaKey(1f, 1f) });
col.color = new ParticleSystem.MinMaxGradient(g);
var r = body.GetComponent<ParticleSystemRenderer>();
r.sharedMaterial = mat;
r.renderMode = ParticleSystemRenderMode.Billboard;
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
r.receiveShadows = false;
// 끝의 흙먼지(2026-11-20 PD 「회오리 끝이 지면에 흙먼지와 함께 나아가야」) — 월드 공간(지나간 자리에 남아 퍼지며 사라짐) · 그림 = 슬링샷 이동 흙먼지(dash2d_puff) · 모래색 ·
// 회오리 몸보다 앞(sortingFudge −5 = 끝을 감싸는 먼지)
var puffMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/VFX/TKS2D/Mat_Dash2D_Puff.mat");
var dustGo = new GameObject("Dust");
dustGo.transform.SetParent(root.transform, false);
dustGo.transform.localPosition = new Vector3(0f, 0.04f, 0f);
var dust = dustGo.AddComponent<ParticleSystem>();
dust.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
var dm = dust.main;
dm.duration = 1f;
dm.loop = true;
dm.playOnAwake = true;
dm.startLifetime = new ParticleSystem.MinMaxCurve(0.45f, 0.8f);
dm.startSpeed = new ParticleSystem.MinMaxCurve(0.25f, 0.7f);
dm.startSize = new ParticleSystem.MinMaxCurve(0.2f, 0.38f);
dm.startRotation = new ParticleSystem.MinMaxCurve(0f, Mathf.PI * 2f);
Color sand;
ColorUtility.TryParseHtmlString("#E9D6AE", out sand);
dm.startColor = sand;
dm.maxParticles = 60;
dm.simulationSpace = ParticleSystemSimulationSpace.World;
dm.scalingMode = ParticleSystemScalingMode.Hierarchy;
var de = dust.emission;
de.rateOverTime = 34f;
var ds = dust.shape;
ds.enabled = true;
ds.shapeType = ParticleSystemShapeType.Circle;
ds.radius = 0.1f;
ds.rotation = Vector3.zero;
ds.scale = new Vector3(1f, 0.45f, 1f);
var dsz = dust.sizeOverLifetime;
dsz.enabled = true;
dsz.size = new ParticleSystem.MinMaxCurve(1f, new AnimationCurve(new Keyframe(0f, 0.6f), new Keyframe(1f, 1.5f)));
var dc = dust.colorOverLifetime;
dc.enabled = true;
var dg = new Gradient();
dg.SetKeys(new[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) },
new[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(0.85f, 0.15f), new GradientAlphaKey(0f, 1f) });
dc.color = new ParticleSystem.MinMaxGradient(dg);
var dr = dustGo.GetComponent<ParticleSystemRenderer>();
dr.sharedMaterial = puffMat;
dr.renderMode = ParticleSystemRenderMode.Billboard;
dr.sortingFudge = -5f;
dr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
dr.receiveShadows = false;
PrefabUtility.SaveAsPrefabAsset(root, dst);
Object.DestroyImmediate(root);
AssetDatabase.SaveAssets();
return "ok " + dst;