From 29fcaf34e1e6932379714ec3f2adffbbd487810e Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 18 Jan 2026 10:59:11 -0800 Subject: Impostors: generate assets based on hierarchy path --- Scripts/Impostors.cs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Scripts/Impostors.cs b/Scripts/Impostors.cs index 29d92d0..1214b8f 100755 --- a/Scripts/Impostors.cs +++ b/Scripts/Impostors.cs @@ -28,7 +28,7 @@ public class Impostors : MonoBehaviour public bool HasImpostor => impostorObject != null; private float Radius => sphere_radius_ * Mathf.Max(transform.lossyScale.x, transform.lossyScale.y, transform.lossyScale.z); - private const string OutputFolder = "Assets/yum_food/3ner/Impostor_Generated"; + private string OutputFolder => GetOutputFolder(); void OnEnable() => Camera.onPreRender += UpdateMainCameraPos; void OnDisable() => Camera.onPreRender -= UpdateMainCameraPos; @@ -59,6 +59,24 @@ public class Impostors : MonoBehaviour } } + string GetOutputFolder() + { + string hierarchyPath = GetHierarchyPath(); + return $"Assets/yum_food/3ner/Impostor_Generated/{hierarchyPath}"; + } + + string GetHierarchyPath() + { + string path = gameObject.name; + Transform parent = transform.parent; + while (parent != null) + { + path = parent.name + "/" + path; + parent = parent.parent; + } + return path; + } + Vector3 PlaneToHemiOctahedron(int gridX, int gridY) { float x = (gridX / (float)(gridResolution - 1)) * 2f - 1f; @@ -437,9 +455,18 @@ public class Impostors : MonoBehaviour { if (!AssetDatabase.IsValidFolder(OutputFolder)) { - if (!AssetDatabase.IsValidFolder("Assets/yum_food/3ner")) - AssetDatabase.CreateFolder("Assets/yum_food", "3ner"); - AssetDatabase.CreateFolder("Assets/yum_food/3ner", "Impostor_Generated"); + string[] pathParts = OutputFolder.Split('/'); + string currentPath = ""; + for (int i = 0; i < pathParts.Length; i++) + { + string parentPath = i == 0 ? "" : string.Join("/", pathParts, 0, i); + currentPath = i == 0 ? pathParts[0] : $"{parentPath}/{pathParts[i]}"; + if (!AssetDatabase.IsValidFolder(currentPath)) + { + string folderName = pathParts[i]; + AssetDatabase.CreateFolder(parentPath, folderName); + } + } } string baseName = gameObject.name.Replace(" ", "_"); -- cgit v1.2.3