Game Design Pattern: Command Pt.2- Game Dev Series 137

Objective: playing stored contents/command by using CommandManager.

In this tutorial, we will continue to create a manager class that would play all command we created in order, and also can rewind or clear it.

CommandManager

To make it easier to call, the CommandManager must be a singleton. Then create a list variable to it to store the executed command.

Inside this manager, we would need some methods to do the following functions:

  • Adding command into list
  • Playing all command from list
  • Playing all command in rewind from list
  • Setting all color into white when finished changing
  • Reset the list

Adding command into list

In this method, we would pass in the current executed command when clicking on cube, and store it into list.
By doing this, we can use List.Add(object).

Then we need to call this method in PlayerInput after execute the command.

Playing & reverse all command

The Playing is quite simple. We need to make it replay all result of command in list, what’s more, we will need it to play one per second. The best way to present this is creating a coroutine.

For the rewind playing, we can use the reverse function of LINQ to do this part. Before we using LINQ, you will need to add a namespace of System.Linq to this script.
Then we create another coroutine to reverse playing the list.

Done and reset

All you need to set cubes to white, is calling every cubes by tag, then set their color to white in foreach loop.

The last one: reset.
Just Clear out the whole list and that is all you need.

Assign to buttons and test

Now we just need to create an empty object to contain this manager class in game scene, and assign these methods to all buttons.

And we can test the result of using Command Design Pattern.

--

--

--

A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A journey from callback hell to Kotlin coroutines, episode 2

How To: Super-heroine Rails API

Release Planning in Agile — How is it done?

7 Reasons to Go With a Headless CMS

What do we mean by automating workflow?

Parallel blocks

Part 4 — A complete beginner’s guide to Computer Programming with Clojure: Maths.

Kubernetes POD Readiness

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

2D Mobile: Designing Enemies Using Abstract Classes

Creating the Main Menu

Day 103: Creating A Ledge Grab in Unity Part 1

Building A Stealth Game — Helping Your Guards “See”