1- using System ;
1+ using IllusionPlugin ;
2+ using System ;
23using System . Collections . Generic ;
3- using System . Linq ;
44using System . IO ;
5+ using System . Linq ;
6+ using System . Text ;
7+ using TMPro ;
58using UnityEngine ;
69using UnityEngine . SceneManagement ;
7- using IllusionPlugin ;
8- using TMPro ;
9- using System . Text ;
1010
11- namespace TestBSPlugin
11+ namespace CustomMenuText
1212{
1313 public class CustomMenuTextPlugin : IPlugin
1414 {
1515 // path to the file to load text from
1616 private const string FILE_PATH = "/UserData/CustomMenuText.txt" ;
17- public static TMP_FontAsset beon ;
17+ // path to load the font prefab from
18+ private const string FONT_PATH = "UserData/CustomMenuFont" ;
19+ // prefab to instantiate when creating the TextMeshPros
20+ public static GameObject textPrefab ;
1821 // used if we can't load any custom entries
1922 public static readonly string [ ] DEFAULT_TEXT = { "BEAT" , "SABER" } ;
2023 public static readonly Color defaultMainColor = new Color ( 0 , 0.5019608f , 1 ) ;
2124 public static readonly Color defaultBottomColor = Color . red ;
2225
2326 public const string DEFAULT_CONFIG =
24- @"# Custom Menu Text v2.2 .0
27+ @"# Custom Menu Text v3.0 .0
2528# by Arti
2629# Special Thanks: Kyle1413
2730#
@@ -42,7 +45,7 @@ public class CustomMenuTextPlugin : IPlugin
4245# You can override the colors even when the text is 2 lines, plus do a lot of other stuff!
4346# (contributed by @Rolo)
4447<size=+5><#ffffff>SBU<#ffff00>BBY
45- <size=-15 ><#1E5142>eef freef.
48+ <size=-5 ><#1E5142>eef freef.
4649
4750# Some more random messages:
4851BEAT
@@ -159,7 +162,7 @@ Ask in <#7289DA>#support
159162 public static List < string [ ] > allEntries = null ;
160163
161164 public string Name => "Custom Menu Text" ;
162- public string Version => "2.2 .0" ;
165+ public string Version => "3.0 .0" ;
163166
164167 // Store the text objects so when we leave the menu and come back, we aren't creating a bunch of them
165168 public static TextMeshPro mainText ;
@@ -173,7 +176,7 @@ public void OnApplicationStart()
173176
174177 private void SceneManagerOnActiveSceneChanged ( Scene arg0 , Scene arg1 )
175178 {
176- if ( arg1 . name == "Menu " ) // Only run in menu scene
179+ if ( arg1 . name == "MenuCore " ) // Only run in menu scene
177180 {
178181 if ( allEntries == null )
179182 {
@@ -204,6 +207,25 @@ private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
204207
205208 }
206209
210+ public static GameObject loadTextPrefab ( string path )
211+ {
212+ GameObject prefab ;
213+ string fontPath = Path . Combine ( Environment . CurrentDirectory , path ) ;
214+ if ( ! File . Exists ( fontPath ) )
215+ {
216+ File . WriteAllBytes ( fontPath , Properties . Resources . Beon ) ;
217+ }
218+ AssetBundle fontBundle = AssetBundle . LoadFromFile ( fontPath ) ;
219+ prefab = fontBundle . LoadAsset < GameObject > ( "Text" ) ;
220+ if ( prefab == null )
221+ {
222+ Console . WriteLine ( "[CustomMenuText] No text prefab found in the provided AssetBundle! Using Beon." ) ;
223+ AssetBundle beonBundle = AssetBundle . LoadFromMemory ( Properties . Resources . Beon ) ;
224+ prefab = beonBundle . LoadAsset < GameObject > ( "Text" ) ;
225+ }
226+ return prefab ;
227+ }
228+
207229 public static List < string [ ] > readFromFile ( string relPath )
208230 {
209231 List < string [ ] > entriesInFile = new List < string [ ] > ( ) ;
@@ -279,33 +301,27 @@ public static List<string[]> readFromFile(string relPath)
279301 /// </summary>
280302 public static void replaceLogo ( )
281303 {
282- if ( beon == null )
283- {
284- var fonts = Resources . FindObjectsOfTypeAll < TMP_FontAsset > ( ) ;
285- foreach ( TMP_FontAsset font in fonts )
286- {
287- if ( font . name == "Beon SDF" )
288- beon = font ;
289- }
290- }
304+ // Since 0.13.0, we have to create our TextMeshPros differently! You can't change the font at runtime, so we load a prefab with the right font from an AssetBundle. This has the side effect of allowing for custom fonts, an oft-requested feature.
305+ if ( textPrefab == null ) textPrefab = loadTextPrefab ( FONT_PATH ) ;
291306
292307 // Logo Top Pos : 0.63, 21.61, 24.82
293308 // Logo Bottom Pos : 0, 17.38, 24.82
294-
295309 if ( mainText == null ) mainText = GameObject . Find ( "CustomMenuText" ) ? . GetComponent < TextMeshPro > ( ) ;
296310 if ( mainText == null )
297311 {
298- GameObject textObj = new GameObject ( "CustomMenuText" ) ;
299- mainText = textObj . AddComponent < TextMeshPro > ( ) ;
312+ GameObject textObj = GameObject . Instantiate ( textPrefab ) ;
313+ textObj . name = "CustomMenuText" ;
314+ textObj . SetActive ( false ) ;
315+ mainText = textObj . GetComponent < TextMeshPro > ( ) ;
300316 mainText . alignment = TextAlignmentOptions . Center ;
301317 mainText . fontSize = 12 ;
302- mainText . font = beon ;
303318 mainText . rectTransform . SetSizeWithCurrentAnchors ( RectTransform . Axis . Horizontal , 2f ) ;
304319 mainText . rectTransform . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , 2f ) ;
305320 mainText . richText = true ;
306321 textObj . transform . localScale *= 3.7f ;
307322 mainText . overflowMode = TextOverflowModes . Overflow ;
308323 mainText . enableWordWrapping = false ;
324+ textObj . SetActive ( true ) ;
309325 }
310326 mainText . rectTransform . position = new Vector3 ( 0f , 21.61f , 24.82f ) ;
311327 mainText . color = defaultMainColor ;
@@ -314,24 +330,26 @@ public static void replaceLogo()
314330 if ( bottomText == null ) bottomText = GameObject . Find ( "CustomMenuText-Bot" ) ? . GetComponent < TextMeshPro > ( ) ;
315331 if ( bottomText == null )
316332 {
317- GameObject textObj2 = new GameObject ( "CustomMenuText-Bot" ) ;
318- bottomText = textObj2 . AddComponent < TextMeshPro > ( ) ;
333+ GameObject textObj2 = GameObject . Instantiate ( textPrefab ) ;
334+ textObj2 . name = "CustomMenuText-Bot" ;
335+ textObj2 . SetActive ( false ) ;
336+ bottomText = textObj2 . GetComponent < TextMeshPro > ( ) ;
319337 bottomText . alignment = TextAlignmentOptions . Center ;
320338 bottomText . fontSize = 12 ;
321- bottomText . font = beon ;
322339 bottomText . rectTransform . SetSizeWithCurrentAnchors ( RectTransform . Axis . Horizontal , 2f ) ;
323340 bottomText . rectTransform . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , 2f ) ;
324341 bottomText . richText = true ;
325342 textObj2 . transform . localScale *= 3.7f ;
326343 bottomText . overflowMode = TextOverflowModes . Overflow ;
327344 bottomText . enableWordWrapping = false ;
345+ textObj2 . SetActive ( true ) ;
328346 }
329347 bottomText . rectTransform . position = new Vector3 ( 0f , 17f , 24.82f ) ;
330348 bottomText . color = defaultBottomColor ;
331349 mainText . text = "SABER" ;
332350
333351 // Destroy Default Logo
334- GameObject defaultLogo = GameObject . Find ( "Logo" ) ;
352+ GameObject defaultLogo = FindUnityObjectsHelper . GetAllGameObjectsInLoadedScenes ( ) . Where ( go => go . name == "Logo" ) . FirstOrDefault ( ) ;
335353 if ( defaultLogo != null ) GameObject . Destroy ( defaultLogo ) ;
336354 }
337355
0 commit comments