Skip to content

Instantly share code, notes, and snippets.

@mmj-the-fighter
Last active October 25, 2015 10:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmj-the-fighter/db813cacb06bbc737708 to your computer and use it in GitHub Desktop.
Save mmj-the-fighter/db813cacb06bbc737708 to your computer and use it in GitHub Desktop.
Unity3D Editor Script : Displays gameobjects linked to each shader present in a scene.
//Copyright © 2015 Manoj M J
//All Rights Reserved
//Why I do copyright the code that I provide at gist.github.com
//( https://gist.github.com/mmj-the-fighter/bccd0a7ff57c638beee8 )
/*
* ShadersLister.cs - Displays gameobjects linked to each shader present in a scene.
* It is useful for checking if the scene contains any unwanted shaders.
*/
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ShadersLister : EditorWindow {
private Hashtable shaderGameObjectTable = new Hashtable();
private Vector2 scrollPosition;
[ MenuItem( "Tools/ShadersLister" ) ]
public static void Launch()
{
EditorWindow window = GetWindow( typeof( ShadersLister ) );
window.Show();
}
public void UpdateList()
{
Object[] renderers;
shaderGameObjectTable.Clear();
renderers = FindObjectsOfType( typeof( Renderer ) );
foreach( Renderer renderer in renderers )
{
foreach(Material mat in renderer.sharedMaterials)
{
string shaderName = mat.shader.name;
if( !shaderGameObjectTable.ContainsKey (shaderName) )
{
shaderGameObjectTable[shaderName] = new ArrayList();
}
( ( ArrayList )shaderGameObjectTable[shaderName] ).Add( renderer.gameObject);
}
}
}
public void OnGUI()
{
GUILayout.BeginHorizontal();
GUILayout.Label( "Shaders in scene:" );
GUILayout.FlexibleSpace();
if( GUILayout.Button( "Refresh" ) )
{
UpdateList();
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
foreach (string shaderName in shaderGameObjectTable.Keys)
{
GUILayout.Label( shaderName + ":" );
foreach(GameObject gameObject in (ArrayList)shaderGameObjectTable[shaderName])
{
if (GUILayout.Button(gameObject.name))
{
Selection.activeObject = gameObject;
}
}
}
GUILayout.EndScrollView();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment