Hi
Simple question:
Is there any list of all the script used in the scene?
And with object are these script attach to?
“Hmm… Is this script already attach somewhere…?”
/errormaker
Hi
Simple question:
Is there any list of all the script used in the scene?
And with object are these script attach to?
“Hmm… Is this script already attach somewhere…?”
/errormaker
This could be a start (untested):
Object[] objects;
objects = FindObjectsOfType( typeof( MonoBehaviour ) );
foreach( MonoBehaviour monoBehaviour in objects )
{
Debug.Log( monoBehaviour.GetType().Name + " is attached to " + monoBehaviour.gameObject.name );
}
Thax for Your replay!
But it didn’t work…
Error:
On this line:
Object[] objects;
Can You test Your code, plaese?
I’m very interested in Your way to get this info.
I guess, where isn’t no such list in Unity (with a list of all the script used in the scene)…
Or…?
/errormaker
Thats a C# script not javascript. Just create a C# script and drop that code in and attach it to a gameobject. Run it and then do Window->Console.
Thax, It worked!
But… that give me a very long list (and difficult to read)…
(and “UnityEngine.Debug:Log(Object)” on every output…)
And I could not copy that list to edit elsewhere… or search the
console window… Is this possible?
Is it possible to write this to an text file… or something…?
I guess that is rather difficult…
/errormaker
Make sure you put the code snippit in void Start() not void Update() so it only runs once (on init)
As to copy/paste the console log.
On a mac, run the app ‘Console’ via spotlight
Click clear display
Click Show Log List and make sure Console Messages is highlighted.
Run your Unity Game then stop it (should generate the console log)
In the console app click Reload and viola your unity console messages should be displayed.
Not at all. You’ve already got the data - just do something differently with it
You could even do an editor window with it (untested):
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ScriptLister : EditorWindow
{
private static ScriptLister instance;
private Hashtable sets = new Hashtable();
public ScriptLister()
{
if( instance != null )
{
Debug.LogError( "Attempt to create second instance of singleton. NOWAI!" );
Destroy( this );
return;
}
instance = this;
}
public void OnDisable()
{
instance = null;
}
public void OnCloseWindow()
{
OnDisable();
}
public static ScriptLister Instance
{
get
{
if( instance == null )
{
new ScriptLister();
}
return instance;
}
}
[ MenuItem( "Component/ScriptLister" ) ]
public void Launch()
{
Instance.Show();
}
public void UpdateList()
{
Object[] objects;
sets.Clear();
objects = FindObjectsOfType( typeof( MonoBehaviour ) );
foreach( MonoBehaviour monoBehaviour in objects )
{
if( !sets.ContainsKey( monoBehaviour.GetType() ) )
{
sets[ monoBehaviour.GetType() ] = new ArrayList();
}
( ( ArrayList )sets[ monoBehaviour.GetType() ] ).Add( monoBehaviour.gameObject );
}
}
public void OnGUI()
{
if( GUILayout.Button( "Refresh" ) )
{
UpdateList();
}
foreach( Type type in sets.Keys )
{
GUILayout.Label( type.Name + ":" );
foreach( GameObject gameObject in sets[ type ] )
{
if( GIULayout.Button( gameObject.name ) )
{
Selection.activeObject = gameObject;
}
}
}
}
}
Edit: Since this is an editor script, it needs to be placed in your Assets/Editor folder.
Edit: Added menu item. The window should be launched via the Component/ScriptLister menu item.
Interesting… but got an error:
and mark this line…
using UnityEditor;
It’s an .cs script and I don’t add anything to Your script…
Remember You are talking to a newbie…
the script must in the editor subfolder of the assets folder to work as an editor script
Check my edits. Modified the script a bit and added info.