Undo and Redo in Unity

Redo and Undo action is everywhere, but how it’s done? In most cases, developers use the Command Design Pattern which we implemented in Unity last time. So how can we extend it with undo and redo action? Let’s find out! ?

Because we did a lot in the last post about the Command Design Pattern, we will use it as our base. If you didn’t see it yet, it’s a great time to do so! I can wait. ?

Ready? So let’s get into that!

There is a lot of places where undo and redo action can come handy. Maybe it’s not that popular in games, but almost every app has it!

Continue reading “Undo and Redo in Unity”

Implementing Command Design Pattern in Unity

Let’s get back to the design patterns for Unity!
Today let’s introduce Command Design Pattern! This design pattern is famous for its encapsulation of requests, which can be useful for many applications and often is used for handling user input, but it’s not the only use case.

Command Design Pattern

The idea behind this design pattern is to move requests to the objects which could be collected and be executed in the queue. You can think about them like Actions or Events but represented as objects.

Continue reading “Implementing Command Design Pattern in Unity”

Conditional Compilation in Unity

We are spoiled by Unity with that whole “write once, run everywhere” thing. But what if we want to run different code on different platforms? Conditional compilation will come very handy here, or like Unity like to put it Platform Depended Compilation. ?

Wait, what’s that?

Great question! Conditional compilation is basically a way to tell the compiler to run code only if compiling condition is met.

Wait a moment. This sounds a lot of like a regular if-statement! What’s the catch?

Continue reading “Conditional Compilation in Unity”

Extension Methods in Unity

Today we are going to learn something entirely new! Extension Methods!
Sometimes as you are developing a game, you have this idea in your mind that you wish you could add some more functionality to Unity Components.
With extension methods, you can do that! ?

But how do they work?

Extension methods are mostly used when you have existing classes, but you can’t edit them, just like in Unity. With them, we can add more functions that will make our lives easier.

Continue reading “Extension Methods in Unity”

Custom Window in Unity

Continuing subject of building tools in Unity, today we are going to build custom window in Unity Editor. If you’ve missed the last post about building a custom component inspector, I would recommend checking it first. ?

To build custom tools in Unity, we have to prepare a custom window in Editor. We can achieve that by using the EditorWindow class.

Like with a custom inspector for components, and here we have to use the old GUI system. There is just one difference between building inspector and window. In inspector, we were using OnInspectorGUI() method and we could use DrawDefaultInspector() to draw component’s properties. In the window, we don’t have such luxury, but we have OnGUI() which works in the same way.

Continue reading “Custom Window in Unity”