|
I've recently joined a project as a coder and most of the scripts are in the Scripts folder. Sometimes I come across scripts that have duplicates and I want to delete one of them, but I cant figure out how I can see WHERE that script is beeing used. Other objects in Unity have the action "Select dependencies", but this doesnt seem to work for Scripts.
(comments are locked)
|
|
AngryAnt has a great script on his site that does the trick:
Looks like you need to clean up your code segment, but yes, AngryAnt's ComponentLister script will do the trick. You can find the post here: http://angryant.com/general/tipsandtricks/where-did-that-component-go/
Feb 18 '10 at 06:30 PM
burnumd
Yeah I tried cleaning it up. Every time it left something out.
Feb 18 '10 at 07:59 PM
JDonavan 1
Aug 30 '12 at 09:04 AM
AngryAnt ♦♦
(comments are locked)
|
|
I'm pretty sure this is not possible. My reasoning for this is that all scripts are included at runtime, and therefore all scripts are potentially available as types which could potentially be instantiated at runtime. In order for the editor to know whether any particular scripts are used or not, it would have to be able to somehow parse every possible runtime permutation of your code. consider:
The editor would have to work out every potential value for a & b, before knowing which scripts might potentially be called on! :)
(comments are locked)
|
|
This should be possible with editor scripting - but I think it's not trivial: You'd have to go through all your scenes. Among other things, you'd use EditorApplication.OpenScene to do this. In the scenes, you should be able to use Object.FindObjectsOfType with the type you're looking for, to get all game objects that have the script you're looking for attached (actually, you get the components - but from there you can easily get the actual game object; and the hierarchy of the game objects is stored in the "transform" attribute of the components which the inherit from Component). You should be able to select those objects with Selection.gameObjects - but since you're iterating through the scenes that won't help you much, so it's probably better to simply log the names of the game objects and maybe iterate through their transform.parent to get the full path. I haven't tried setting Selection.gameObjects - but the scripting reference doesn't say it's read-only so that should work (if you want to just do this for a single scene, that sure would be nice). Finally, you'd have to check out all the prefabs in the project. One approach might be simple iterating through the file structure (that could be done with standard .NET API calls - DirectoryInfo.GetDirectories is one of the methods you'd be using for that) and then using AssetDatabase.LoadAssetAtPath to get "living instances" of any prefab and then checking if those contain the script you're looking for (via GetComponent - if it doesn't return null for the given type, the script is used). I'm not sure this will all work (and you'll probably need a bit more than what I've linked here), and when it works (which I would hope) it'll be a bit of work to implement this - but it's certainly worth a try and would be a great example of the power of editor scripting ;-)
(comments are locked)
|
|
I'm sorry if I didn't phrase my question correctly, and that it was unclear. Since scripts are added to gameobjects using the unity inspector, I was merely looking for a way to see which gameobjects a certain script had been added to. Now I have to go through every gameobject by hand in the hierarchy or look at prefabs in the Project that I think has some relation to the script and see if they have been added to it.
(comments are locked)
|
|
I tried a little improvement of Angry Ant's script. Basically all component are sorted and you can fold/unfold them for better readibility. I did it during my student project (also my first Unity project). And now that the project is over, I'm happy to share it with the commmunity. Very handy script! Can't ask for more :-)
Apr 12 '12 at 11:48 AM
hylde
(comments are locked)
|
1 2 next page »
