Skip to content

Commit

Permalink
Ensure TMP resources available before doing LineViewTests
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Nov 25, 2024
1 parent 5a4bcc3 commit 87541b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/Runtime/DialogueViewTests/LineViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class LineViewTests : IPrebuildSetup, IPostBuildCleanup
public void Setup()
{
RuntimeTestUtility.AddSceneToBuild(DialogueViewTestSceneGUID);

// TMP text view operations like counting the number of visible
// characters won't work unless the TMP essential resources are
// installed, so make sure they're part of the project before
// testing
RuntimeTestUtility.EnsureTMPResourcesAvailable();
}

public void Cleanup()
Expand Down
22 changes: 22 additions & 0 deletions Tests/Runtime/RuntimeTestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ public static void RemoveSceneFromBuild(string GUID)
#if UNITY_EDITOR
// Filter the list to remove any scene with this GUID
EditorBuildSettings.scenes = EditorBuildSettings.scenes.Where(x => x.guid.ToString() != GUID).ToArray();
#endif
}

internal static void EnsureTMPResourcesAvailable()
{
#if UNITY_EDITOR
var s_TextSettings = UnityEngine.Resources.Load<TMPro.TMP_Settings>("TextSettings");
if (s_TextSettings != null)
{
// TMP resources are already available
return;
}
// Install the TMP Essentials package
var unityGUIPackageFullPath = System.IO.Path.GetFullPath("Packages/com.unity.ugui");
if (System.IO.Directory.Exists(unityGUIPackageFullPath) == false)
{
throw new System.InvalidOperationException($"Can't install TMP assets: {unityGUIPackageFullPath} is not a valid directory");
}

UnityEngine.Debug.Log($"Importing TextMeshPro essential resources.");

AssetDatabase.ImportPackage(unityGUIPackageFullPath + "/Package Resources/TMP Essential Resources.unitypackage", false);
#endif
}
}
Expand Down

0 comments on commit 87541b1

Please sign in to comment.