Unitilities for the rest of us

Unity is a wonderful engine, however if you start developing for it, soon you’ll discover that some things are just painful to do or you start to notice that some basic things are missing.

Some months ago, I started to put together many scripts I’ve been developing for various projects in Unity (and interesting functions I found at the Internet). It still needs more work, but it has a pretty good base of items ready to facilitate the work in Unity.

Among the features that it provides, are:

  • Extension methods for:
    • GameObjects
    • Numbers and comparable types
    • Lists and arrays
    • Vectors
    • Strings
    • Colors
    • Date/Time
  • PlayerPrefs window to view and modify preferences inside the Unity Editor (Windows only).
  • A Timer and ManagedTimer type, useful to do things after a certain time.
  • Definition of type Tuple.
    • Tuple-2, Tuple-3 and Tuple-4 for:
      • Generic types: Tuple<int, string> /  Tuple<MyClass, GameObject> / etc.
      • Common types: TupleI (works like Tuple<int, int>), TupleF.
  • Gizmo-helpers for the Editor to see invisible objects.
  • Various helpful functions, like calculation of positions over a sphere and HSV-defined (Hue, Saturation, Value) color, among others.
  • [Work in Progress] A FSM (Finite-state Machine) system that takes advantage of Unity’s scripting architecture.
  • [Work in Progress] Abstraction of user input (mouse/touch).

A more detailed list can be seen here (I’m working to update it one bit at a time, I prefer to do other things than documenting code hahaha)

I could say, without doubt, that the things I most use from it are the timers and the PlayerPrefs Editor to easily delete the PlayerPrefs when testing.

The FSM is not the best around and it was more of an experiment than anything else. All the FSMs I found relied on a classical pipeline (Unity embraces modular work, not like XNA or other frameworks), so basically you had to call their logic and action phases by yourself; my solution was taking advantage of the modular architecture and use the scripts as the machine’s states (and not having a single script handling the whole FSM). This design results in a more elegant and understandable FSM; however, it has some flaws and needs to be more secure.

The current version includes some examples of many of the features I mentioned, but nevertheless I tried to document as far as I could (at least with the function signatures and the classes definitions. I’ll be working to put more examples whenever I can to make it more understandable and writing posts here on the blog about some of the things I came up with (hint: the first one is here).

Here’s the link of the Unitilities repo.

And here’s the link to the most stable version of the unitypackage: Unitilities v0.1.0

Feel free to share any doubt or suggestions, and any bug report as well!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.