55 lines
2.7 KiB
C#
55 lines
2.7 KiB
C#
// WL_DressingGrassRemove.cs — PD 지시(2026-09-06 22:3x) "해당 잔디 에셋도 제거" (에디트 모드)
|
|
// unity command run_script --file AgentScripts/WL_DressingGrassRemove.cs --entry WL_DressingGrassRemove.Count
|
|
// unity command run_script --file AgentScripts/WL_DressingGrassRemove.cs --entry WL_DressingGrassRemove.Remove
|
|
// WL_Nature.prefab 드레싱 중 소스 프리팹 경로/이름에 "Grass" 가 들어가는 인스턴스(LMHPOLY Vegetation 풀)를 제거한다. 꽃·버섯·덤불·나무·바위는 유지.
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public static class WL_DressingGrassRemove
|
|
{
|
|
const string MapPrefab = "Assets/Res_Addr/Map/WL_Nature.prefab";
|
|
|
|
static bool IsGrass(GameObject go)
|
|
{
|
|
var src = PrefabUtility.GetCorrespondingObjectFromOriginalSource(go);
|
|
string path = src != null ? AssetDatabase.GetAssetPath(src) : "";
|
|
string n = go.name;
|
|
return (path.IndexOf("Grass", System.StringComparison.OrdinalIgnoreCase) >= 0 || n.IndexOf("Grass", System.StringComparison.OrdinalIgnoreCase) >= 0)
|
|
&& path.IndexOf("/Vegetation/", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
|
}
|
|
|
|
public static object Count()
|
|
{
|
|
var root = PrefabUtility.LoadPrefabContents(MapPrefab);
|
|
try
|
|
{
|
|
var all = root.GetComponentsInChildren<Transform>(true).Select(t => t.gameObject)
|
|
.Where(g => PrefabUtility.IsAnyPrefabInstanceRoot(g) && IsGrass(g)).ToList();
|
|
var byName = all.GroupBy(g => System.Text.RegularExpressions.Regex.Replace(g.name, @" \(\d+\)$", "")).OrderByDescending(x => x.Count());
|
|
var sb = new StringBuilder("grass instances=" + all.Count + "\n");
|
|
foreach (var g in byName.Take(12)) sb.AppendLine(" " + g.Key + " x" + g.Count());
|
|
return sb.ToString();
|
|
}
|
|
finally { PrefabUtility.UnloadPrefabContents(root); }
|
|
}
|
|
|
|
public static object Remove()
|
|
{
|
|
if (Application.isPlaying) return "refused: Play mode";
|
|
var root = PrefabUtility.LoadPrefabContents(MapPrefab);
|
|
try
|
|
{
|
|
var all = root.GetComponentsInChildren<Transform>(true).Select(t => t.gameObject)
|
|
.Where(g => PrefabUtility.IsAnyPrefabInstanceRoot(g) && IsGrass(g)).ToList();
|
|
int n = all.Count;
|
|
foreach (var g in all) if (g != null) Object.DestroyImmediate(g);
|
|
PrefabUtility.SaveAsPrefabAsset(root, MapPrefab);
|
|
int remain = root.GetComponentsInChildren<Transform>(true).Count(t => IsGrass(t.gameObject));
|
|
return "removed grass instances=" + n + " remaining=" + remain + " saved " + MapPrefab;
|
|
}
|
|
finally { PrefabUtility.UnloadPrefabContents(root); }
|
|
}
|
|
}
|