-
-
Notifications
You must be signed in to change notification settings - Fork 245
Tools and Features
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 feature, Hotkeys
UnityEvent Inspector — Allows you to fold and reorder event subscribers
Tool to unleash true power of Preset assets and rid off of AssetPostprocessor scripts.
-
Create some Presets! 😉
-
Access this tool via "Tools/MyBox/Postprocess Preset Tool" menu item.
-
First time accessed you'll see Save Folder Panel prompt to create AssetsPresetPostprocessBase asset.
-
Either use menu item again or manually select this asset to access its inspector.
-
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.
-
Reimport existing assets. Newly imported assets will be set up accordingly.
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 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;
}
}
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
Features may be enabled or disabled via MyBox Window located in "Tools/MyBox/MyBox Window" or via "Tools/MyBox" menu items
Enable in Settings
tldr: implement IPrepare on Monobehaviour, bool Prepare()
method will be called every time you hit Play. Return true
and component will be marked dirty, scene will be saved. This way you will keep your heavy calculations out of the build
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 = FindObjectsOfType<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 = FindObjectsOfType<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;
}
Nice-looking UnityEvent inspector, allows to fold and reorder your event subscribers:
thanks to Byron Mayne for sharing
//TODO: ImageStringConverter
SerializedPropertyViewer