scaffolding dialogue test system

This commit is contained in:
2026-08-14 13:49:40 +02:00
parent f3057c65aa
commit 98fe1794c6
9 changed files with 846 additions and 0 deletions
@@ -0,0 +1,80 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using Yarn.Compiler;
using Yarn.Unity;
using Yarn.Unity.Editor;
public static class YarnDemoSetup
{
const string YarnProjectPath = "Assets/Dialogue/NightclubArcadia.yarnproject";
const string ScenePath = "Assets/Scenes/DialogueTest.unity";
[MenuItem("Tools/Nightclub Arcadia/Set Up Yarn Dialogue Test")]
public static void SetUpYarnDialogueTest()
{
if (!AssetDatabase.IsValidFolder("Assets/TextMesh Pro"))
{
Debug.LogWarning("TextMesh Pro essential resources are missing. Run Window → TextMeshPro → Import TMP Essential Resources.");
}
if (!AssetDatabase.IsValidFolder("Assets/Dialogue"))
{
AssetDatabase.CreateFolder("Assets", "Dialogue");
}
if (!AssetDatabase.IsValidFolder("Assets/Scenes"))
{
AssetDatabase.CreateFolder("Assets", "Scenes");
}
var yarnProject = AssetDatabase.LoadAssetAtPath<YarnProject>(YarnProjectPath);
if (yarnProject == null)
{
// YarnProjectUtility.CreateDefaultYarnProject is internal, so
// construct the same default project here.
var project = new Project
{
ExcludeFilePatterns = new[] { "**/*~/*", "./Samples/Yarn Spinner*/*" },
};
YarnEditorUtility.CreateYarnProject(YarnProjectPath, project);
AssetDatabase.Refresh();
yarnProject = AssetDatabase.LoadAssetAtPath<YarnProject>(YarnProjectPath);
}
var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var runner = CreateDialogueRunnerMenuItem.CreateDialogueRunner();
var so = new SerializedObject(runner);
so.FindProperty("yarnProject").objectReferenceValue = yarnProject;
so.ApplyModifiedPropertiesWithoutUndo();
runner.autoStart = true;
runner.startNode = "Start";
EditorUtility.SetDirty(runner);
#if UNITY_2023_1_OR_NEWER
var eventSystems = Object.FindObjectsByType<EventSystem>(FindObjectsInactive.Include, FindObjectsSortMode.None);
#else
var eventSystems = Object.FindObjectsOfType<EventSystem>(true);
#endif
foreach (var eventSystem in eventSystems)
{
if (eventSystem.GetComponent<BaseInputModule>() != null)
{
continue;
}
#if ENABLE_INPUT_SYSTEM
eventSystem.gameObject.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
#endif
}
EditorSceneManager.SaveScene(scene, ScenePath);
AssetDatabase.SaveAssets();
Debug.Log($"Yarn dialogue test setup complete. Scene saved to {ScenePath}");
}
}