Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/refactortools.git?path=Assets/Gemserk.RefactorTools

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **Unity Refactor Tools by Gemserk** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/refactortools.git?path=Assets%2FGemserk.RefactorTools
```

[![pkglnk](https://www.pkglnk.dev/badge/refactortools.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/refactortools)

README

openupm License: MIT

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 openupm 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, RefactorData and RefactorResult.
  • 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

My Personal Website & Dev Blog

Comments

No comments yet. Be the first!