Skip to content

Instantly share code, notes, and snippets.

@andybak
Created December 23, 2021 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andybak/84610558b586c9100d7b8362842eda4d to your computer and use it in GitHub Desktop.
Save andybak/84610558b586c9100d7b8362842eda4d to your computer and use it in GitHub Desktop.
// Copyright 2021 The Tilt Brush Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace TiltBrush
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class TextureLister : MonoBehaviour
{
private static StringBuilder brushList;
private static List<Guid> deprecated;
[MenuItem("Tilt/Info/Texture 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($"Experimental brush loading error: {UnassignedReferenceException}");
}
}
Debug.Log($"{brushList}");
}
public static string getBrushRowString(BrushDescriptor brush, bool experimental)
{
if (brush.m_SupersededBy != null) return "";
string info = "";
if (brush.Material)
{
var texPropNames = brush.Material.GetTexturePropertyNames();
foreach (var texProp in texPropNames)
{
var tex = brush.Material?.GetTexture(texProp);
if (tex != null)
{
info += $"Brush: {brush.m_Description} {texProp}: rw? {tex.isReadable} path: {UnityEditor.AssetDatabase.GetAssetPath(tex)}\n";
}
}
}
return info;
}
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