Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

Commit 4ab2de0

Browse files
committed
Updating settings UI
1 parent 72f0861 commit 4ab2de0

File tree

3 files changed

+63
-23
lines changed

3 files changed

+63
-23
lines changed

Assets/GameScriptSettings.asset

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ MonoBehaviour:
1616
InitialConversationPool: 1
1717
PreventSingleNodeChoices: 1
1818
DatabasePath: D:/Work/GameScriptUnity/Database/TestDB
19-
DatabaseVersion: 0.0.0
20-
GeneratedPath: D:/Work/GameScriptUnity/Assets/GameScript
21-
GameDataPath: D:/Work/GameScriptUnity/Assets/StreamingAssets/GameScript
22-
GameDataPathRelative: /GameScript
19+
DatabaseVersion:
20+
GeneratedPath:
21+
GameDataPath: /Users/eric/Work/GameScriptUnity/Assets/StreamingAssets/GameScript

Packages/studio.shortsleeve.gamescriptunity/Editor/Menu/SettingsEditor.cs

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,46 @@ public override VisualElement CreateInspectorGUI()
119119
databasePathField.SetEnabled(false);
120120

121121
// Select Editor Database Button
122+
Button databaseSelectButton = new();
123+
databaseSelectButton.name = "SelectDatabase";
124+
databaseSelectButton.text = "Select Database";
125+
databaseSelectButton.tooltip =
126+
"Select a database file to use for importing conversation data.";
127+
128+
// Import Database Button
122129
Button databaseImportButton = new();
123130
databaseImportButton.name = "ImportDatabase";
124131
databaseImportButton.text = "Import Database";
125132
databaseImportButton.tooltip =
126-
"Select a database file to import. This will prepare "
133+
"Import the selected database. This will prepare "
127134
+ "all of your conversation data for runtime use and may take some time.";
135+
136+
// Wire up Select Database Button callback
137+
databaseSelectButton.clickable.clicked += () =>
138+
{
139+
string absoluteDbPath = EditorUtility.OpenFilePanel("Select Database", "", "");
140+
if (string.IsNullOrEmpty(absoluteDbPath))
141+
return;
142+
143+
// Convert to relative and save
144+
string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
145+
string relativeDbPath = GetRelativePath(projectRoot, absoluteDbPath);
146+
serializedObject.FindProperty("DatabasePath").stringValue = relativeDbPath;
147+
serializedObject.ApplyModifiedProperties();
148+
149+
// Update display with absolute path
150+
databasePathField.value = absoluteDbPath;
151+
152+
// Revalidate to update Import button state
153+
ValidatePathsAndUpdateImportButton(
154+
generatedPathField,
155+
runtimeDatabasePath,
156+
databasePathField,
157+
databaseImportButton
158+
);
159+
};
160+
161+
// Wire up Import Database Button callback
128162
databaseImportButton.clickable.clicked += () =>
129163
{
130164
// Make sure import isn't in progress
@@ -138,22 +172,9 @@ public override VisualElement CreateInspectorGUI()
138172
return;
139173
}
140174

141-
// Select database file
142-
string absoluteDbPath = EditorUtility.OpenFilePanel("Import Database", "", "");
143-
if (string.IsNullOrEmpty(absoluteDbPath))
144-
return;
145-
146-
// Convert to relative and save
147-
string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
148-
string relativeDbPath = GetRelativePath(projectRoot, absoluteDbPath);
149-
serializedObject.FindProperty("DatabasePath").stringValue = relativeDbPath;
150-
serializedObject.ApplyModifiedProperties();
151-
152-
// Update display
153-
databasePathField.value = absoluteDbPath;
154-
155175
// Load database using absolute paths
156176
Settings settings = (Settings)serializedObject.targetObject;
177+
string absoluteDbPath = settings.GetAbsoluteDatabasePath();
157178
string gameScriptOutputPath = settings.GetAbsoluteGeneratedPath();
158179
string conversationOutputPath = settings.GetAbsoluteGameDataPath();
159180
DatabaseImporter.ImportDatabase(
@@ -188,6 +209,7 @@ public override VisualElement CreateInspectorGUI()
188209
ValidatePathsAndUpdateImportButton(
189210
generatedPathField,
190211
runtimeDatabasePath,
212+
databasePathField,
191213
databaseImportButton
192214
);
193215
}
@@ -213,6 +235,7 @@ public override VisualElement CreateInspectorGUI()
213235
ValidatePathsAndUpdateImportButton(
214236
generatedPathField,
215237
runtimeDatabasePath,
238+
databasePathField,
216239
databaseImportButton
217240
);
218241
}
@@ -234,6 +257,7 @@ public override VisualElement CreateInspectorGUI()
234257
editorSettingsFoldout.Add(databaseHeader);
235258
editorSettingsFoldout.Add(databasePathField);
236259
editorSettingsFoldout.Add(databaseVersionField);
260+
editorSettingsFoldout.Add(databaseSelectButton);
237261
editorSettingsFoldout.Add(databaseImportButton);
238262
#endregion
239263

@@ -255,6 +279,7 @@ public override VisualElement CreateInspectorGUI()
255279
ValidatePathsAndUpdateImportButton(
256280
generatedPathField,
257281
runtimeDatabasePath,
282+
databasePathField,
258283
databaseImportButton
259284
);
260285

@@ -268,6 +293,7 @@ public override VisualElement CreateInspectorGUI()
268293
ValidatePathsAndUpdateImportButton(
269294
generatedPathField,
270295
runtimeDatabasePath,
296+
databasePathField,
271297
databaseImportButton
272298
);
273299
}
@@ -282,6 +308,7 @@ public override VisualElement CreateInspectorGUI()
282308
ValidatePathsAndUpdateImportButton(
283309
generatedPathField,
284310
runtimeDatabasePath,
311+
databasePathField,
285312
databaseImportButton
286313
);
287314
}
@@ -331,11 +358,12 @@ private void OnDbVersionChanged(TextField databaseVersionField, string newVersio
331358
}
332359

333360
/// <summary>
334-
/// Validates both required paths and updates the Import button state and field highlighting
361+
/// Validates all required paths and updates the Import button state and field highlighting
335362
/// </summary>
336363
private void ValidatePathsAndUpdateImportButton(
337364
TextField generatedPathField,
338365
TextField runtimeDatabasePath,
366+
TextField databasePathField,
339367
Button databaseImportButton
340368
)
341369
{
@@ -353,6 +381,10 @@ Button databaseImportButton
353381
requireExists: false
354382
);
355383

384+
// Database file must exist
385+
bool databasePathValid = !string.IsNullOrEmpty(databasePathField.value)
386+
&& File.Exists(databasePathField.value);
387+
356388
// Update field highlighting
357389
if (generatedPathValid)
358390
{
@@ -372,8 +404,17 @@ Button databaseImportButton
372404
SetElementWarning(runtimeDatabasePath);
373405
}
374406

375-
// Enable Import button only if both paths are valid
376-
databaseImportButton.SetEnabled(generatedPathValid && gameDataPathValid);
407+
if (databasePathValid)
408+
{
409+
UnsetElementWarning(databasePathField);
410+
}
411+
else
412+
{
413+
SetElementWarning(databasePathField);
414+
}
415+
416+
// Enable Import button only if all paths are valid
417+
databaseImportButton.SetEnabled(generatedPathValid && gameDataPathValid && databasePathValid);
377418
}
378419

379420
/// <summary>

Packages/studio.shortsleeve.gamescriptunity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "studio.shortsleeve.gamescriptunity",
33
"displayName": "GameScriptUnity",
4-
"version": "0.0.20",
4+
"version": "0.0.21",
55
"unity": "2023.2",
66
"description": "Cross-platform dialogue middleware",
77
"keywords": [

0 commit comments

Comments
 (0)