Unity Refactoring Tools
ForkCode + examples for Refactoring Data stored in Unity Prefabs, Scenes and other Assets
Unity Project
Built with Unity 2019.4.28f1 · download the source from GitHub

Dependencies (20)
README
Unity Refactor Tools
Tools for refactoring content stored in Unity Prefabs, Scenes and other Assets.
This project was initially used to show examples for this blogpost.
Install it from OpenUPM
This package can be installed using OpenUPM, just click here for more details.
Usage
If you want, for example, copy some MonoBehaviour fields to new field and consider all prefabs and prefab instances in scene, then run something like this:
RefactorTools.RefactorMonoBehaviour<CustomBehaviour>(new RefactorTools.RefactorParameters
{
prefabs = AssetDatabaseExt.FindPrefabs<CustomBehaviour>(),
scenes = AssetDatabaseExt.FindAllScenes()
}, delegate(GameObject gameObject,
RefactorTools.RefactorData _)
{
var behaviours = gameObject.GetComponentsInChildren<CustomBehaviour>();
foreach (var behaviour in behaviours)
{
behaviour.speed = new Speed
{
baseValue = behaviour.speedBaseValue,
incrementValue = behaviour.speedIncrementValue
};
}
return new RefactorTools.RefactorResult
{
completed = true
};
});
RefactorData parameter
You can customize refactors by using extra data received when refactoring with RefactorData parameter:
RefactorTools.RefactorMonoBehaviour<CustomBehaviour>(new RefactorTools.RefactorParameters
{
prefabs = AssetDatabaseExt.FindPrefabs<CustomBehaviour>(),
scenes = AssetDatabaseExt.FindAllScenes()
}, delegate(GameObject gameObject,
RefactorTools.RefactorData data)
{
if (data.inScene)
{
if (data.scenePath.Contains("Levels"))
{
// do extra logic like search for specific reference or anything else
}
}
else
{
// do some prefab refactor
}
});
Roadmap
Here are some ideas on how to expand the project.
- Customize generic refactor logic by expanding
RefactorParameters,RefactorDataandRefactorResult. - More refactor methods for general usage, like moving MonoBehaviour to another object, etc.
- Customizable window to perform general refactors.
- Automatize refactors using SerializedObjects and SerializedProperties to refactor field changes.
Collaborate
Feel free to create issues for feature requests and/or submit pull requests with your own improvements.
Contact
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In