Skip to content

With String-O-Matic, magic strings are over.

License

Notifications You must be signed in to change notification settings

haywirephoenix/StringOMatic

Repository files navigation

Title

With String-O-Matic, magic strings are over. Generate all your constants at the click of a button.

Description
Unity's policy for implementing magic strings in almost all of its systems is one the major sources of bugs and headaches, especially for amateurs. Using constant values instead of relying on magic strings heavily reduces the amount of runtime errors.

String-O-Matic scans your project based on your needs to automatically generate constants and static classes holding references to all of those magic strings, effectively replacing soft runtime errors by robust compile errors.
Key Features
  • Replace Unity magic strings for static classes and constants.

  • Changing magic strings in the Editor will produce compile errors that would otherwise cause undesired beahviour.

  • Comes with many built-in modules, each one addressing a different system.

  • Easily configurable based on each project needs.

  • Easy to use: you just have to click a button.

  • Easy to extend: you can create your own modules, satisfying your own project needs.

  • Fully documented =)

  • And last but not least, full source code included.


Modules
  • Tags

  • Layers

  • Sorting Layers

  • Input axes

  • Navigation Areas

  • Scenes -- Lists every scene name and path added to the build.

  • Audio -- Lists every mixer controller and, for each one, their exposed parameters and snaphots.

  • Mecanim-- Lists every animator's parameters, layers, states and sub state machines, recursively.

  • Resources-- Lists every object under your resources folder/s and subfolders.

  • Shaders-- Lists the shader name and it's properties for every built-in and custom shader

Planned Features
  • FilterList global class
  • FilterList for more categories
  • FilterList path fields
  • FilterList object fields
  • Custom module template repo
  • Custom namespace name fields for modules?
  • Docs for module creation in the new format
  • Update banner with Update button in preferences
  • Revisit Addressables IResource constant
  • Addressables feature (Complete)
  • Support for multiple constant types (Complete)
  • Support package manager git url (Complete)
  • Animator hash generation (Complete)
  • Improved compatibility with newer versions of Unity (Complete)
  • Text fields to specify the namespace, target directory, and class name. (Complete)
  • Remove XML intermediary generation (Complete)
  • Improve performance (Complete)
Installation

Install from a Git URL

Yoy can also install this package via Git URL. To load a package from a Git URL:

  • Open Unity Package Manager window.
  • Click the add + button in the status bar.
  • The options for adding packages appear.
  • Select Add package from git URL from the add menu. A text box and an Add button appear.
  • Enter the https://github.com/haywirephoenix/StringOMatic.git Git URL in the text box and click Add.

Getting Started
  • Open Preferences > String-O-Matic or Tools > String-O-Matic > Preferences
  • Toggle the modules that you want to generate - click on them as some have more sub options.
  • Toggle any of the customization options at the top if you would like to change them.
  • Press the Refresh All button at the bottom.
  • Your new consts file will be generated in your project.

Usage

Once you've generated your constants, in your project you will have access to all the module classes.

If you used the "Wrap modules in namespaces" option:

using StringOMatic.InputModule;

Then you can access them like this:

Input.GetAxis(InputStatics.horizontal)

Or you can create a shortcut to a specific class:

using MyControllerParams = StringOMatic.MecanimModule.MecanimStatics.Controllers.MyController.Parameters;

Then you can reference them like this:

animator.SetFloat(MyControllerParams.horizontalFullPathHash,x);

Rewired Addon Installation

Readme: rewired-addon

Please make sure Rewired is installed first.

Install from a Git URL

Yoy can also install this package via Git URL. To load a package from a Git URL:

  • Open Unity Package Manager window.
  • Click the add + button in the status bar.
  • The options for adding packages appear.
  • Select Add package from git URL from the add menu. A text box and an Add button appear.
  • Enter the https://github.com/haywirephoenix/StringOMatic.git#rewired-addon Git URL in the text box and click Add.

Addressables Addon Installation

Readme: addressables-addon

Install from a Git URL

Yoy can also install this package via Git URL. To load a package from a Git URL:

  • Open Unity Package Manager window.
  • Click the add + button in the status bar.
  • The options for adding packages appear.
  • Select Add package from git URL from the add menu. A text box and an Add button appear.
  • Enter the https://github.com/haywirephoenix/StringOMatic.git#addressables-addon Git URL in the text box and click Add.

Addressables Usage

If you have the Addressables addon installed, the Addressables module should now be included in the StringOMatic preferences window. When enabled, it will generate constant strings from your Addressables:

MainAsset - AddressableAssetEntry.AssetPath, AddressableAssetGroup.Guid SubAssets - AddressableAssetEntry.address

The MainAsset GUID is stored as a string, the same as Unity stores it.


Loading all the animation clips in a bundled fbx:

var handle = Addressables.LoadAssetAsync<AnimationClip[]>(AddressablesStatics.MyAnimations.mainAssetPath);

await handle.Task;

if (handle.Status == AsyncOperationStatus.Succeeded)
{
    AnimationClip[] myFBXAnims = handle.Result;
}

Loading a SubAsset (for example an animationclip in a bundled fbx):

var handle = Addressables.LoadAssetAsync<AnimationClip>(AddressablesStatics.MyAnimations.SubAssets.myanimationClip);

await handle.Task;

if (handle.Status == AsyncOperationStatus.Succeeded)
{
    AnimationClip myanimationClip = handle.Result;   
}

Updates
v1.1.1:
  • Add a filter list to the Mecanim module
  • Fix Refresh from reverting animation controller changes
  • Mechanim module now adds Animator.StringToHash ints
  • Fix preferences layout and menuitem.
  • Add github repo button to preferences

v2.0.0:
  • Update C# generation - completely rewritten
  • Update StringToHash int generation
  • Remove XML generation intermediary step
  • Add namespace generation to modules with "Module" suffix
  • Create new data structure for storing and generating constants
  • Update all modules to support new structure
  • Update Rewired module to search for InputManager prefab or scene
  • Upate Resources module - new project scanning and const gen approach
  • Update Preferences UI + current and backwards compatibility
  • Add new fields to Preferences UI to customize Path, Class and Namespace
  • Fix MenuItem methods, with backwards compatibility
  • New and improved Animator Hash generation
v2.0.1 - 2.0.3:
  • Fix minor bugs
  • Add package manager support
v2.0.4:
  • Add addressables support
  • Add support for multiple constant types
v3.0.0:
  • Split Addons into seperate branches

Convert error-prone code
SOM Not Used
into safe, robust code
SOM Used

A continuation of the work done by Cobo Antonio with permission. Pull requests welcome!

About

With String-O-Matic, magic strings are over.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages