Tag: dotnet

  • Get-text style localization in Unity

    In past Unity projects I have used basic string table lookup to localize UI text using carefully named keys. Whilst straightforward in terms of implementation this has a number of downsides such as being unable to properly handle the plural forms of some languages; not to mention the problem of having to come up with meaningful keys and locating strings in source code.

    Continue reading...

  • Managing states with a lightweight FSM

    Games will typically have a number of states and sub-states and there are endless ways in which these states can be defined from using a switch statement, to using delegates, state pattern, coroutines, scenes, animation events, etc. Each approach brings its own advantages and disadvantages and some are better suited depending on the use case.

    Continue reading...

  • Tweening with DOTween

    There are several really good tweening libraries for Unity although I must say DOTween is my favorite since it has a wealth of features and performs well even on mobile. DOTween is open source although there is a DOTween Pro version which includes extra features such as visual editors but most importantly allows you to show some support to the fantastic developer of this asset.

    Continue reading...

  • Services and configuration assets for Unity projects

    With many of the projects that I have worked on it has been necessary to support a variety of build targets that are either configured differently or make use of entirely different services. In early projects I would simply use the various symbols that Unity defines such as UNITY_ANDROID but this falls short when supporting multiple Android based platforms. Not to mention dealing with projects that contain multiple reskins of the same core game each with a range of different platforms.

    Continue reading...

  • Separation of concerns with Unity UI

    I have worked with various interpretations of MVC-like patterns over the years and have experimented a lot with applying them to UIs in Unity. The patterns that I found to work best with nGUI and uGUI are MVP (Model-View-Presenter) (passive view) and MVVM (Model-View-ViewModel).

    Continue reading...

  • Managing and reporting player achievements

    When implementing goals such as achievements I like to keep the detection logic separate from the main game logic wherever possible. Otherwise it is easy to end up with spaghetti where achievements are being reported all over the place. One way to separate this cross cutting concern is to have each goal monitor the game’s state to detect success or even failure.

    Continue reading...

  • Dependency injection in Unity with Zenject

    Dependency injection in Unity projects is slightly complicated by the fact that we do not have full control over the initialization of the engine. Unity instantiates it’s various object types (GameObject, Component, MonoBehaviour, ScriptableObject, Material, etc) when scenes and assets are loaded. Put simply… the objects exist before we can do anything with them.

    Continue reading...

  • Custom editor controls in Unity - Part 5: Custom styles

    Sometimes it becomes necessary to define custom GUIStyle’s to get the most desirable user experience from your editor controls. Custom styles can be defined using a number of different approaches. You can create GUISkin asset files; custom asset files or simply write some code that creates the GUIStyle’s programmatically. The latter is nice when you want the styles to be embedded into a DLL.

    Continue reading...

  • Custom editor controls in Unity - Part 4: Property drawers

    Often it is nice to customize the way that some properties are presented in the inspector but you don’t necessarily want to define an entire custom inspector. Fortunately Unity has a feature that enables you to customize the drawing of properties without having to define how the entire inspector of a component should work.

    Continue reading...

  • Custom editor controls in Unity - Part 3: Input control

    More often than not editor controls will have some sort of value that is shown and editable visually. In this post I am going to walk you through the creation of a custom control that allows some flags to be toggled using a simple grid.

    Continue reading...