File tree 1 file changed +34
-0
lines changed
Assets/Patterns/1. Command/Rebind keys/Scripts
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,23 @@ void Update()
94
94
redoCommands . Push ( lastCommand ) ;
95
95
}
96
96
}
97
+ //Undo with Q
98
+ else if ( Input . GetKeyDown ( KeyCode . Q ) )
99
+ {
100
+ if ( undoCommands . Count < 2 )
101
+ {
102
+ Debug . Log ( "Can't undo twice because we are back where we started or there is only one undo command" ) ;
103
+ }
104
+ else
105
+ {
106
+ Command lastCommand = undoCommands . Pop ( ) ;
107
+ lastCommand . Undo ( ) ;
108
+ redoCommands . Push ( lastCommand ) ;
109
+ lastCommand = undoCommands . Pop ( ) ;
110
+ lastCommand . Undo ( ) ;
111
+ redoCommands . Push ( lastCommand ) ;
112
+ }
113
+ }
97
114
//Redo with r
98
115
else if ( Input . GetKeyDown ( KeyCode . R ) )
99
116
{
@@ -111,6 +128,23 @@ void Update()
111
128
undoCommands . Push ( nextCommand ) ;
112
129
}
113
130
}
131
+ //Redo twice
132
+ else if ( Input . GetKeyDown ( KeyCode . Alpha2 ) )
133
+ {
134
+ if ( redoCommands . Count < 2 )
135
+ {
136
+ Debug . Log ( "Can't redo twice because we are at the end or there is only one left" ) ;
137
+ }
138
+ else
139
+ {
140
+ Command nextCommand = redoCommands . Pop ( ) ;
141
+ nextCommand . Execute ( ) ;
142
+ undoCommands . Push ( nextCommand ) ;
143
+ nextCommand = redoCommands . Pop ( ) ;
144
+ nextCommand . Execute ( ) ;
145
+ undoCommands . Push ( nextCommand ) ;
146
+ }
147
+ }
114
148
115
149
116
150
//Rebind keys by just swapping A and D buttons
You can’t perform that action at this time.
0 commit comments