Skip to content

Commit f88f729

Browse files
committed
Started adding command and event queue
1 parent 36a2c54 commit f88f729

24 files changed

+983
-3
lines changed

Assets/Patterns/1. Command.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Patterns/1. Command/Command.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern
6+
{
7+
//Base class for the commands
8+
//This class should always look like this to make it more general, so no constructors, parameters, etc!!!
9+
public abstract class Command
10+
{
11+
public abstract void Execute();
12+
13+
public abstract void Undo();
14+
}
15+
}

Assets/Patterns/1. Command/Command.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Patterns/1. Command/Rebind keys.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Patterns/1. Command/Rebind keys/Scripts.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern.RebindKeys
6+
{
7+
//The point of this command is to do nothing
8+
//Is used instead of setting a command to null, so it's called Null Object, which is another programming pattern
9+
public class DoNothingCommand : Command
10+
{
11+
public override void Execute()
12+
{
13+
14+
}
15+
16+
public override void Undo()
17+
{
18+
19+
}
20+
}
21+
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands/DoNothingCommand.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern.RebindKeys
6+
{
7+
public class MoveBackCommand : Command
8+
{
9+
private MoveObject moveObject;
10+
11+
12+
public MoveBackCommand(MoveObject moveObject)
13+
{
14+
this.moveObject = moveObject;
15+
}
16+
17+
18+
public override void Execute()
19+
{
20+
moveObject.MoveBack();
21+
}
22+
23+
24+
//Undo is just the opposite
25+
public override void Undo()
26+
{
27+
moveObject.MoveForward();
28+
}
29+
}
30+
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands/MoveBackCommand.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern.RebindKeys
6+
{
7+
public class MoveForwardCommand : Command
8+
{
9+
private MoveObject moveObject;
10+
11+
12+
public MoveForwardCommand(MoveObject moveObject)
13+
{
14+
this.moveObject = moveObject;
15+
}
16+
17+
18+
public override void Execute()
19+
{
20+
moveObject.MoveForward();
21+
}
22+
23+
24+
//Undo is just the opposite
25+
public override void Undo()
26+
{
27+
moveObject.MoveBack();
28+
}
29+
}
30+
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands/MoveForwardCommand.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern.RebindKeys
6+
{
7+
public class TurnLeftCommand : Command
8+
{
9+
private MoveObject moveObject;
10+
11+
12+
public TurnLeftCommand(MoveObject moveObject)
13+
{
14+
this.moveObject = moveObject;
15+
}
16+
17+
18+
public override void Execute()
19+
{
20+
moveObject.TurnLeft();
21+
}
22+
23+
24+
//Undo is just the opposite
25+
public override void Undo()
26+
{
27+
moveObject.TurnRight();
28+
}
29+
}
30+
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands/TurnLeftCommand.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CommandPattern.RebindKeys
6+
{
7+
public class TurnRightCommand : Command
8+
{
9+
private MoveObject moveObject;
10+
11+
12+
public TurnRightCommand(MoveObject moveObject)
13+
{
14+
this.moveObject = moveObject;
15+
}
16+
17+
18+
public override void Execute()
19+
{
20+
moveObject.TurnRight();
21+
}
22+
23+
24+
//Undo is just the opposite
25+
public override void Undo()
26+
{
27+
moveObject.TurnLeft();
28+
}
29+
}
30+
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Commands/TurnRightCommand.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)