File tree Expand file tree Collapse file tree 4 files changed +18
-30
lines changed
samples/Unity.Match3/Assets/Scripts/Common Expand file tree Collapse file tree 4 files changed +18
-30
lines changed Original file line number Diff line number Diff line change @@ -17,27 +17,33 @@ protected override void Start()
17
17
_stateSpriteRenderer . sprite = GetStateSprite ( _currentStateIndex ) ;
18
18
}
19
19
20
- public virtual bool NextState ( )
20
+ public void NextState ( )
21
21
{
22
22
_currentStateIndex ++ ;
23
23
24
- if ( _currentStateIndex >= _stateSpriteNames . Length )
24
+ if ( _currentStateIndex < _stateSpriteNames . Length )
25
+ {
26
+ _stateSpriteRenderer . sprite = GetStateSprite ( _currentStateIndex ) ;
27
+ }
28
+ else
25
29
{
26
30
_stateSpriteRenderer . enabled = false ;
27
- return false ;
31
+ OnComplete ( ) ;
28
32
}
29
-
30
- _stateSpriteRenderer . sprite = GetStateSprite ( _currentStateIndex ) ;
31
- return true ;
32
33
}
33
34
34
- public virtual void ResetState ( )
35
+ public void ResetState ( )
35
36
{
36
37
_currentStateIndex = 0 ;
37
38
_stateSpriteRenderer . enabled = true ;
38
39
_stateSpriteRenderer . sprite = GetStateSprite ( 0 ) ;
40
+
41
+ OnReset ( ) ;
39
42
}
40
43
44
+ protected abstract void OnComplete ( ) ;
45
+ protected abstract void OnReset ( ) ;
46
+
41
47
private Sprite GetStateSprite ( int index )
42
48
{
43
49
return GetSprite ( _stateSpriteNames [ index ] ) ;
Original file line number Diff line number Diff line change @@ -10,21 +10,13 @@ public class IceState : StatefulGridTile
10
10
public override bool CanContainItem => true ;
11
11
public override TileGroup Group => TileGroup . Ice ;
12
12
13
- public override bool NextState ( )
13
+ protected override void OnComplete ( )
14
14
{
15
- var hasNextState = base . NextState ( ) ;
16
- if ( hasNextState )
17
- {
18
- return true ;
19
- }
20
-
21
15
_isLocked = false ;
22
- return false ;
23
16
}
24
17
25
- public override void ResetState ( )
18
+ protected override void OnReset ( )
26
19
{
27
- base . ResetState ( ) ;
28
20
_isLocked = true ;
29
21
}
30
22
}
Original file line number Diff line number Diff line change @@ -11,24 +11,14 @@ public class StoneState : StatefulGridTile
11
11
public override bool CanContainItem => _canContainItem ;
12
12
public override TileGroup Group => TileGroup . Stone ;
13
13
14
- public override bool NextState ( )
14
+ protected override void OnComplete ( )
15
15
{
16
- var hasNextState = base . NextState ( ) ;
17
- if ( hasNextState )
18
- {
19
- return true ;
20
- }
21
-
22
16
_isLocked = false ;
23
17
_canContainItem = true ;
24
-
25
- return false ;
26
18
}
27
19
28
- public override void ResetState ( )
20
+ protected override void OnReset ( )
29
21
{
30
- base . ResetState ( ) ;
31
-
32
22
_isLocked = true ;
33
23
_canContainItem = false ;
34
24
}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ namespace Common.Interfaces
2
2
{
3
3
public interface IStatefulSlot
4
4
{
5
- bool NextState ( ) ;
5
+ void NextState ( ) ;
6
6
void ResetState ( ) ;
7
7
}
8
8
}
You can’t perform that action at this time.
0 commit comments