Skip to content

Tools and Features

Andrew Rumak edited this page Jul 20, 2019 · 13 revisions

AssetPressetPreprocessor — Conditionally apply Presets to your assets on import
TimeTest — Measure performance with simple api
IPrepare — Easy way to replace caching, calculations and asserts from playmode
Features — Cleanup Empty Directories, AutoSave featur, Hotkeys


AssetPressetPreprocessor

Tool to unleash true power of Preset assets and rid off of AssetPostprocessor scripts.

  1. Create some Presets! 😉

  2. Access this tool via "Tools/MyBox/Postprocess Preset Tool" menu item.

  3. First time accessed you'll see Save Folder Panel prompt to create AssetsPresetPostprocessBase asset.

  4. Either use menu item again or manually select this asset to access its inspector.

  5. Fill up ConditionalPresetsBase with your presets! Conditions supported: "Path contains", "FileType", "Prefix", "Postfix".

    You may reorder Conditional Preset items. First item that match all conditions will be applied.

  6. Reimport existing assets. Newly imported assets will be set up accordingly.

AssetPressetPreprocessor AssetPressetPreprocessor2

note that Presets will apply all import settings and sometimes you'll don't want that. For example, you probably will want to keep SpriteBorder setting of your sprites. You able to exclude such properties through ConditionalPresetsBase inspector. SpriteBorder excluded by default. Push "Apply Excludes" button to update existing ConditionalPresets.

Please contact me if you'll find out some other properties that should be excluded by default


TimeTest

TimeTest is a tool to benchmark code with simple api

// Use static methods
TimeTest.Start(string title, bool useMilliseconds = false)
...
TimeTest.End()
// Or as disposable with using statement
using (new TimeTest(string title, bool useMilliseconds = false))
{
  ...
}

Example:

TimeTest.Start("1k GO creation", true);
		
List<GameObject> objects = new List<GameObject>();
for (var i = 0; i < 1000; i++)
{
  objects.Add(new GameObject("Object No" + i));
}

TimeTest.End();

using (new TimeTest("Massive parenting"))
{
  Transform parent = null;
  foreach (var o in objects)
  {
    if (parent == null)
    {
      parent = o.transform;
      continue;
    }
    o.transform.SetParent(parent);
    parent = o.transform;
  }
}

TimeTest Example


Cleanup Empty Directories and AutoSave features and some Hotkeys

Cleanup feature will remove empty folders on save. No more pesky .meta files for empty folders in your vcs 🙌

AutoSave will save your scenes on Playmode. You'll be glad it's on, especially if Unity will crash a few times in a row

Toggle Inspector Lock hotkey [Alt+Q] is with me for years. I don't know how I'd survive without it. It is SOOO EXHAUSTING to toggle inspector lock manually 😩

Both features located in "Tools/MyBox/" menu and may be disabled (enabled by default)

Features


IPrepare

tldr; bool Prepare() is called on MonoBehaviours every time you enter playmode and marks component dirty + saves the scene if method returns true;

IPrepare is a way to cache some things and perform calculations on Edit time, not Play time.
I was inspired to make this one by Playdead (creators of Limbo and Inside) 2016 talk. They are using PostProcessScene to cache things on build time. I was eager to bring this idea to my projects but soon realised that it's handy to use freshly cached result on playmode right away.
To achieve this you may simply implement IPrepare on MonoBehaviour and every time you hit play Prepare() will be called automatically and changes (if any) will be saved to the scene

For instance, you want to find all Waypoints on scene and assign to your NPCs:

// Some relatively heavy calculation
this.Waypoints = FindObhectsOfType<Waypoint>().Where(w => w.Agent.Name => this.Name).ToArray();

Surely you may put this in Awake, but if you are interested fast execution you'd like to put as much calculations as possible away from play time. The only thing you need to do now is to implement IPrepare.

You'll notice, that Prepare() method returns bool. This is because we need to know that something changed, otherwise we will save our scene every time we hit play. This check will require some little bit of extra work, but it totally worth it! Besides, MyBox provides several extension methods that'll help you with that:

public bool Prepare() 
{
// Conditional compilation is not required. 
// No need to keep this code in build either :)
#if UNITY_EDITOR 
  var waypoints = FindObhectsOfType<Waypoint>().Where(w => w.Agent.Name => this.Name).ToArray();
  // It's nice place to keep your checks/assertions too
  if (waypoints.IsNullOrEmpty()) Debug.LogWarning("No waypoints found for agent " + this.Name, this);
  // ContentsMatch is extension method for collections. Part of MyCollections.cs
  if (!waypoints.ContentsMatch(this.Waypoints)) 
  { 
    _behaviors = behaviors;
    return true;
  }
#endif
  return false;
}

//TODO: ImageStringConverter

SerializedPropertyViewer

Clone this wiki locally