Skip to content

Commit 873e927

Browse files
committed
Add AllowToPlayWithoutNewestVersion configuration option
1 parent b998be5 commit 873e927

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/Assets/Scripts/Patcher.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Patcher : IDisposable
3939

4040
private KeyLicenseObtainer _keyLicenseObtainer;
4141

42+
private bool _canPlay;
43+
4244
/// <summary>
4345
/// Initializes instance of <see cref="PatcherConfiguration"/>.
4446
/// Must be called from main Unity thread since it requires some initial configuration.
@@ -69,6 +71,11 @@ public PatcherState State
6971
}
7072
}
7173

74+
public bool CanPlay
75+
{
76+
get { return State != PatcherState.Processing && _canPlay && (_configuration.AllowToPlayWithoutNewestVersion || State == PatcherState.Success); }
77+
}
78+
7279
public void Start()
7380
{
7481
if (_thread != null && _thread.IsAlive)
@@ -104,6 +111,10 @@ public void Start()
104111

105112
State = PatcherState.Error;
106113
}
114+
finally
115+
{
116+
_canPlay = _localAppData.IsInstalled();
117+
}
107118
})
108119
{
109120
IsBackground = true

src/Assets/Scripts/PatcherConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ public struct PatcherConfiguration
2121
/// Works only in editor/development build.
2222
/// </summary>
2323
public int ForceVersion;
24+
25+
public bool AllowToPlayWithoutNewestVersion;
2426
}
2527
}

src/Assets/Scripts/UI/MessagePanel.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,32 @@ private void Start()
1919
{
2020
PatcherApplication.Instance.Patcher.OnStateChanged += state =>
2121
{
22-
if (state == PatcherState.None)
22+
if (state == PatcherState.Processing)
2323
{
24-
_animator.SetBool("IsOpened", true);
25-
ButtonText.text = "Patch";
24+
_animator.SetBool("IsOpened", false);
2625
}
27-
else if (state == PatcherState.Cancelled || state == PatcherState.Error || state == PatcherState.UnauthorizedAccess)
26+
else if (PatcherApplication.Instance.Patcher.CanPlay)
2827
{
2928
_animator.SetBool("IsOpened", true);
30-
ButtonText.text = "Retry";
31-
}
32-
else if (state == PatcherState.Processing)
33-
{
34-
_animator.SetBool("IsOpened", false);
29+
ButtonText.text = "Play";
3530
}
36-
else if (state == PatcherState.Success)
31+
else
3732
{
3833
_animator.SetBool("IsOpened", true);
39-
ButtonText.text = "Play";
34+
ButtonText.text = "Retry";
4035
}
4136
};
4237
}
4338

4439
public void Action()
4540
{
46-
var state = PatcherApplication.Instance.Patcher.State;
47-
48-
if (state == PatcherState.None || state == PatcherState.Cancelled || state == PatcherState.Error || state == PatcherState.UnauthorizedAccess)
41+
if (PatcherApplication.Instance.Patcher.CanPlay)
4942
{
50-
PatcherApplication.Instance.RetryPatching();
43+
PatcherApplication.Instance.StartApplicationAndQuit();
5144
}
52-
else if (state == PatcherState.Success)
45+
else
5346
{
54-
PatcherApplication.Instance.StartApplicationAndQuit();
47+
PatcherApplication.Instance.RetryPatching();
5548
}
5649
}
5750
}

0 commit comments

Comments
 (0)