Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc8e84b

Browse filesBrowse files
The abstract CommandBase class is changed to ICommand interface
1 parent 8428ebc commit fc8e84b
Copy full SHA for fc8e84b

File tree

7 files changed

+33
-42
lines changed
Filter options

7 files changed

+33
-42
lines changed

‎Assets/Patterns/14. Command Queue (Event Queue)/CommandBase.cs

Copy file name to clipboardExpand all lines: Assets/Patterns/14. Command Queue (Event Queue)/CommandBase.cs
-18Lines changed: 0 additions & 18 deletions
This file was deleted.

‎Assets/Patterns/14. Command Queue (Event Queue)/CommandQueue.cs

Copy file name to clipboardExpand all lines: Assets/Patterns/14. Command Queue (Event Queue)/CommandQueue.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ namespace CommandQueuePattern
55
public class CommandQueue
66
{
77
// queue of commands
8-
private readonly Queue<CommandBase> _queue;
8+
private readonly Queue<ICommand> _queue;
99

1010
// it's true when a command is running
1111
private bool _isPending;
1212

1313
public CommandQueue()
1414
{
1515
// create a queue
16-
_queue = new Queue<CommandBase>();
16+
_queue = new Queue<ICommand>();
1717

1818
// no command is running
1919
_isPending = false;
2020
}
2121

22-
public void Enqueue(CommandBase cmd)
22+
public void Enqueue(ICommand cmd)
2323
{
2424
// add a command
2525
_queue.Enqueue(cmd);

‎Assets/Patterns/14. Command Queue (Event Queue)/Commands/FirstCmd.cs

Copy file name to clipboardExpand all lines: Assets/Patterns/14. Command Queue (Event Queue)/Commands/FirstCmd.cs
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using UnityEngine;
52

63
namespace CommandQueuePattern
74
{
8-
public class FirstCmd : CommandBase
5+
public class FirstCmd : ICommand
96
{
107
private readonly GameController _owner;
118

12-
public override bool IsFinished { get; protected set; } = false;
9+
public Action OnFinished { get; set; }
1310

1411
public FirstCmd(GameController owner)
1512
{
1613
_owner = owner;
1714
}
1815

19-
public override void Execute()
16+
public void Execute()
2017
{
2118
// activate gameobject
2219
_owner.firstPopUp.gameObject.SetActive(true);
@@ -33,8 +30,7 @@ private void OnClose()
3330
_owner.firstPopUp.gameObject.SetActive(false);
3431

3532
// rise the OnFinished event to say we're done with this command
36-
CallOnFinished();
37-
IsFinished = true;
33+
OnFinished?.Invoke();
3834
}
3935
}
4036
}

‎Assets/Patterns/14. Command Queue (Event Queue)/Commands/SecondCmd.cs

Copy file name to clipboardExpand all lines: Assets/Patterns/14. Command Queue (Event Queue)/Commands/SecondCmd.cs
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
namespace CommandQueuePattern
1+
using System;
2+
3+
namespace CommandQueuePattern
24
{
3-
public class SecondCmd : CommandBase
5+
public class SecondCmd : ICommand
46
{
57
private readonly GameController _owner;
68

7-
public override bool IsFinished { get; protected set; } = false;
8-
99
public SecondCmd(GameController owner)
1010
{
1111
_owner = owner;
1212
}
1313

14-
public override void Execute()
14+
public Action OnFinished { get; set; }
15+
16+
public void Execute()
1517
{
1618
// activate gameobject
1719
_owner.secondPopup.gameObject.SetActive(true);
@@ -28,8 +30,7 @@ private void OnClose()
2830
_owner.secondPopup.gameObject.SetActive(false);
2931

3032
// rise the OnFinished event to say we're done with this command
31-
CallOnFinished();
32-
IsFinished = true;
33+
OnFinished?.Invoke();
3334
}
3435
}
3536
}

‎Assets/Patterns/14. Command Queue (Event Queue)/Commands/ThirdCmd.cs

Copy file name to clipboardExpand all lines: Assets/Patterns/14. Command Queue (Event Queue)/Commands/ThirdCmd.cs
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
namespace CommandQueuePattern
1+
using System;
2+
3+
namespace CommandQueuePattern
24
{
3-
public class ThirdCmd : CommandBase
5+
public class ThirdCmd : ICommand
46
{
57
private readonly GameController _owner;
68

7-
public override bool IsFinished { get; protected set; } = false;
9+
public Action OnFinished { get; set; }
810

911
public ThirdCmd(GameController owner)
1012
{
1113
_owner = owner;
1214
}
1315

14-
public override void Execute()
16+
public void Execute()
1517
{
1618
// activate gameobject
1719
_owner.thirdPopup.gameObject.SetActive(true);
@@ -28,8 +30,7 @@ private void OnClose()
2830
_owner.thirdPopup.gameObject.SetActive(false);
2931

3032
// rise the OnFinished event to say we're done with this command
31-
CallOnFinished();
32-
IsFinished = true;
33+
OnFinished?.Invoke();
3334
}
3435
}
3536
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace CommandQueuePattern
4+
{
5+
public interface ICommand
6+
{
7+
Action OnFinished { get; set; }
8+
9+
void Execute();
10+
}
11+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.