Skip to content

Commit 9a91017

Browse files
committed
Adds "CanRestart" function to editor window
1 parent 9a297a7 commit 9a91017

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Packages/Ink/Editor/Tools/Player Window/InkPlayerWindow.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,14 @@ static void Restart () {
952952
Stop();
953953
if(storyJSONTextAsset != null)
954954
Play(storyJSONTextAsset);
955-
else
955+
else if(storyJSON != null)
956956
Play(storyJSON);
957+
else
958+
Debug.LogError("Can't restart because no text asset or cached JSON exists");
959+
}
960+
961+
static bool CanRestart() {
962+
return storyJSONTextAsset != null || storyJSON != null;
957963
}
958964

959965
static void ContinueStory () {
@@ -1143,7 +1149,7 @@ void DisplayHeader () {
11431149
Play(storyJSONTextAsset);
11441150
}
11451151
}
1146-
if(storyJSONTextAsset != null && storyJSON != null) {
1152+
if(CanRestart()) {
11471153
string fullJSONFilePath = InkEditorUtils.UnityRelativeToAbsolutePath(AssetDatabase.GetAssetPath(storyJSONTextAsset));
11481154
var updatedStoryJSONLastEditDateTime = File.GetLastWriteTime(fullJSONFilePath);
11491155
if (currentStoryJSONLastEditDateTime != updatedStoryJSONLastEditDateTime ) {
@@ -1186,10 +1192,12 @@ void DisplayStoryControlGroup () {
11861192
if(GUILayout.Button(new GUIContent("Stop", stopIcon, "Stop the story"), EditorStyles.toolbarButton)) {
11871193
Stop();
11881194
}
1195+
EditorGUI.BeginDisabledGroup(!CanRestart());
11891196
if(GUILayout.Button(new GUIContent("Restart", restartIcon, "Restarts the story"), EditorStyles.toolbarButton)) {
11901197
Restart();
11911198
}
11921199
EditorGUI.EndDisabledGroup();
1200+
EditorGUI.EndDisabledGroup();
11931201
}
11941202

11951203
GUILayout.FlexibleSpace();

0 commit comments

Comments
 (0)