Is it possible to write script which will open prefab selected in Project tree (where all resources are available) do something with it’s content (find and change GameObjects) and than save it.
Yes, it’s entirely possible.
I don’t know exactly what you had in mind. Look at my answer at Generating a prefab from Audio Clip via script if you want to see one real example of what can be done.
- The
UnityEditor
namespace contains API for writing editor scripts. - Your Editor scripts should be placed in a folder that you create, called
Editor
.
If you are new to Editor Scripting, I’d suggest you start reading Extending the Editor. Then start looking at the Scripting Reference for all kinds of editor APIs that are available, to build yourself a rough sense of what is available. Not all of it will make sense to you at first glance, but it helps to have it in the back of your head as a vague imprint. If you look on the left side, you can set the dropdown to Editor Classes and the list below will populate with the documented API.
- PrefabUtility is a class that has prefab helper methods.
- Selection is a class that gives you easy access to whatever you have selected in the editor. See the link for details.
- AssetDatabase is the main entry point to accessing assets in the project.
EditorUtility.SetDirty (GameObject);
Did it for me in a script editing node editor. May help someone.
It actually took me a couple of hours to figure out how to do it from the resources provided above, so here’s what actually worked for me - this little example shows editing a Version prefab from script as a way of automating updating version numbers for a build script:
// get a reference to the prefab itself, not a clone or instantiation:
GameObject versionObject = AssetDatabase.LoadAssetAtPath("Assets/Resources/Version.prefab",
typeof(GameObject)) as GameObject;
// Edit it
versionObject.GetComponent().versionNumber = versionNumber;