Last active
February 11, 2021 17:24
-
-
Save andybak/a073910bd2f3b7e0956d989ccc0dd1d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using TiltBrush; | |
using UnityEditor; | |
using UnityEngine; | |
using Valve.Newtonsoft.Json.Utilities; | |
using Object = UnityEngine.Object; | |
public class BrushLister : MonoBehaviour | |
{ | |
private static StringBuilder brushList; | |
private static List<Guid> deprecated; | |
[MenuItem("Tools/Brush Lister")] | |
static void ListBrushes() | |
{ | |
brushList = new StringBuilder(); | |
Object[] defaultBrushes = Resources.LoadAll("Brushes", typeof(BrushDescriptor)).ToArray(); | |
var experimentalBrushes = Resources.LoadAll("X/Brushes", typeof(BrushDescriptor)).ToArray(); | |
deprecated = new List<Guid>(); | |
foreach (BrushDescriptor b in defaultBrushes) { if (b.m_Supersedes!=null) deprecated.Add(b.m_Supersedes.m_Guid);} | |
foreach (BrushDescriptor b in experimentalBrushes) { if (b.m_Supersedes!=null) deprecated.Add(b.m_Supersedes.m_Guid);} | |
foreach (BrushDescriptor brush in defaultBrushes) {AppendValidBrushString(brush, false);} | |
foreach (BrushDescriptor brush in experimentalBrushes) | |
{ | |
try {AppendValidBrushString(brush, true);} | |
catch (Exception UnassignedReferenceException) {} | |
} | |
Debug.Log($"{brushList}"); | |
} | |
public static string getBrushRowString(BrushDescriptor brush, bool experimental) | |
{ | |
// Exclude legacy brushes | |
if (brush.m_SupersededBy != null) return ""; | |
var brushScripts = sniffBrushScript(brush); | |
string prefabName = brush.m_BrushPrefab!= null ? brush.m_BrushPrefab.name : ""; | |
string materialName = brush.Material != null ? brush.Material.name : ""; | |
return $"{brush.m_Description}\t{brush.m_AudioReactive}\t{prefabName}\t{materialName}\t{brushScripts}\t{experimental}\t{brush.m_SupersededBy}"; | |
} | |
public static string sniffBrushScript(BrushDescriptor brush) | |
{ | |
GameObject prefab = brush.m_BrushPrefab; | |
if (prefab == null) return ""; | |
var componentNames = new List<string>(); | |
foreach (MonoBehaviour c in prefab.GetComponents<MonoBehaviour>()) | |
{ | |
if (c.GetType() == typeof(MeshFilter) || c.GetType() == typeof(Transform) || c.GetType() == typeof(MeshRenderer)) continue; | |
componentNames.Add(c.GetType().ToString().Replace("TiltBrush.", "")); | |
} | |
return string.Join(",", componentNames); | |
} | |
public static void AppendValidBrushString(BrushDescriptor brush, bool experimental) | |
{ | |
if (deprecated.Contains(brush.m_Guid)) return; | |
var rowString = getBrushRowString(brush, experimental); | |
if (rowString != "") brushList.AppendLine($"{rowString}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment