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

Dockerizing a Flask-MySQL app with docker-compose

Human Computer Interaction

Testing signed and encrypted cookies in Rails

How I got into Open Humans as an Outreachy intern

How to Design a Better Command Line Interface

9 reasons why you should use Docker as a development environment

Shipping containers, axonometric perspective

No Free Java LTS Version?

Beautiful[Soup] Guide to Web Scraping

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

Using the Unity Animation System (Game Dev Day 59)

Creating a Game Manager

Hidden Shortcuts to Make Level Design Easier in Unity.

My journey becoming a Unity game developer: 2.5D Infinite Runner-Moving Platform with player