diff options
Diffstat (limited to 'Packages/dev.zue.vrcog')
| -rw-r--r-- | Packages/dev.zue.vrcog/Editor/VRCog/FileStatTree.cs | 107 | ||||
| -rw-r--r-- | Packages/dev.zue.vrcog/Editor/VRCog/PoiyomiFinder.cs | 81 | ||||
| -rw-r--r-- | Packages/dev.zue.vrcog/package.json | 13 |
3 files changed, 201 insertions, 0 deletions
diff --git a/Packages/dev.zue.vrcog/Editor/VRCog/FileStatTree.cs b/Packages/dev.zue.vrcog/Editor/VRCog/FileStatTree.cs new file mode 100644 index 0000000..3e1fe81 --- /dev/null +++ b/Packages/dev.zue.vrcog/Editor/VRCog/FileStatTree.cs @@ -0,0 +1,107 @@ +// Editor window for auditing assets referenced by a hierarchy root.
+//
+// It collects unique materials, textures used by those materials, and meshes found under the selected GameObject, then displays them sorted by on-disk file size so large contributors are easy to spot.
+
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+public class FileStatTree : EditorWindow
+{
+ private GameObject targetObject;
+ private List<AssetSizeInfo> assetList = new List<AssetSizeInfo>();
+ private Vector2 scrollPos;
+
+ struct AssetSizeInfo
+ {
+ public Object asset;
+ public long size;
+ public string type;
+ }
+
+ [MenuItem("Tools/VRCog/File Stat Tree")]
+ public static void ShowWindow() => GetWindow<FileStatTree>("File Stat Tree");
+
+ private void OnGUI()
+ {
+ GUILayout.Label("Sort Hierarchy Assets by Size", EditorStyles.boldLabel);
+ targetObject = (GameObject)EditorGUILayout.ObjectField("Target Root", targetObject, typeof(GameObject), true);
+
+ if (GUILayout.Button("Analyze Hierarchy Assets"))
+ {
+ AnalyzeAssets();
+ }
+
+ EditorGUILayout.Space();
+
+ scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
+ foreach (var info in assetList)
+ {
+ EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
+ EditorGUILayout.ObjectField(info.asset, info.asset.GetType(), false);
+ GUILayout.Label(FormatSize(info.size), GUILayout.Width(80));
+ EditorGUILayout.EndHorizontal();
+ }
+ EditorGUILayout.EndScrollView();
+ }
+
+ private void AnalyzeAssets()
+ {
+ assetList.Clear();
+ if (targetObject == null) return;
+
+ HashSet<Object> foundAssets = new HashSet<Object>();
+ Renderer[] renderers = targetObject.GetComponentsInChildren<Renderer>(true);
+
+ foreach (var ren in renderers)
+ {
+ foreach (var mat in ren.sharedMaterials)
+ {
+ if (mat == null) continue;
+
+ // Track the Material
+ foundAssets.Add(mat);
+
+ // Track Textures within that material
+ Shader shader = mat.shader;
+ int propertyCount = ShaderUtil.GetPropertyCount(shader);
+ for (int i = 0; i < propertyCount; i++)
+ {
+ if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
+ {
+ Texture tex = mat.GetTexture(ShaderUtil.GetPropertyName(shader, i));
+ if (tex != null) foundAssets.Add(tex);
+ }
+ }
+ }
+
+ // Track Mesh
+ MeshFilter mf = ren.GetComponent<MeshFilter>();
+ if (mf != null && mf.sharedMesh != null) foundAssets.Add(mf.sharedMesh);
+ }
+
+ foreach (var asset in foundAssets)
+ {
+ string path = AssetDatabase.GetAssetPath(asset);
+ if (!string.IsNullOrEmpty(path))
+ {
+ FileInfo fi = new FileInfo(path);
+ if (fi.Exists)
+ {
+ assetList.Add(new AssetSizeInfo { asset = asset, size = fi.Length, type = asset.GetType().Name });
+ }
+ }
+ }
+
+ // Sort by size descending
+ assetList = assetList.OrderByDescending(asf => asf.size).ToList();
+ }
+
+ private string FormatSize(long bytes)
+ {
+ if (bytes >= 1048576) return (bytes / 1048576f).ToString("F2") + " MB";
+ return (bytes / 1024f).ToString("F2") + " KB";
+ }
+}
\ No newline at end of file diff --git a/Packages/dev.zue.vrcog/Editor/VRCog/PoiyomiFinder.cs b/Packages/dev.zue.vrcog/Editor/VRCog/PoiyomiFinder.cs new file mode 100644 index 0000000..6a65445 --- /dev/null +++ b/Packages/dev.zue.vrcog/Editor/VRCog/PoiyomiFinder.cs @@ -0,0 +1,81 @@ +// Editor window for finding objects that use Poiyomi shaders in a hierarchy.
+//
+// It scans renderers under the selected root GameObject, lists each matching object once, and provides a quick Select action to jump directly to results for material cleanup.
+
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+
+public class PoiyomiFinder : EditorWindow
+{
+ private GameObject targetObject;
+ private List<GameObject> results = new List<GameObject>();
+ private Vector2 scrollPos;
+
+ [MenuItem("Tools/VRCog/Poiyomi Finder")]
+ public static void ShowWindow()
+ {
+ GetWindow<PoiyomiFinder>("Poiyomi Finder");
+ }
+
+ private void OnGUI()
+ {
+ GUILayout.Label("Search Hierarchy for Poiyomi Shaders", EditorStyles.boldLabel);
+
+ targetObject = (GameObject)EditorGUILayout.ObjectField("Target Root", targetObject, typeof(GameObject), true);
+
+ if (GUILayout.Button("Find Poiyomi Materials"))
+ {
+ FindMaterials();
+ }
+
+ EditorGUILayout.Space();
+
+ if (results.Count > 0)
+ {
+ GUILayout.Label($"Found {results.Count} objects:", EditorStyles.helpBox);
+ scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
+
+ foreach (GameObject obj in results)
+ {
+ EditorGUILayout.BeginHorizontal();
+ EditorGUILayout.ObjectField(obj, typeof(GameObject), true);
+ if (GUILayout.Button("Select", GUILayout.Width(60)))
+ {
+ Selection.activeGameObject = obj;
+ }
+ EditorGUILayout.EndHorizontal();
+ }
+
+ EditorGUILayout.EndScrollView();
+ }
+ }
+
+ private void FindMaterials()
+ {
+ results.Clear();
+ if (targetObject == null) return;
+
+ // Get all renderers in children
+ Renderer[] renderers = targetObject.GetComponentsInChildren<Renderer>(true);
+
+ foreach (Renderer ren in renderers)
+ {
+ foreach (Material mat in ren.sharedMaterials)
+ {
+ if (mat != null && mat.shader != null)
+ {
+ // Check if the shader name contains "poiyomi" (case-insensitive)
+ if (mat.shader.name.ToLower().Contains("poiyomi"))
+ {
+ if (!results.Contains(ren.gameObject))
+ {
+ results.Add(ren.gameObject);
+ }
+ break; // Move to next renderer once found
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Packages/dev.zue.vrcog/package.json b/Packages/dev.zue.vrcog/package.json new file mode 100644 index 0000000..d712e30 --- /dev/null +++ b/Packages/dev.zue.vrcog/package.json @@ -0,0 +1,13 @@ +{ + "name": "dev.zue.vrcog", + "displayName": "VRCog", + "version": "0.0.1", + "unity": "2022.3", + "description": "Unity editor utilities for VRChat creators. The missing gear in your workflow.", + "vrchatVersion": "2022.1.1", + "author": { + "name": "Alex Pooley (@zuedev)", + "email": "zuedev@gmail.com", + "url": "https://zue.dev" + } +}
\ No newline at end of file |
