Skip to content

Commit 0613b2f

Browse files
Update to 0.13.0; add custom font support(!)
1 parent f08185c commit 0613b2f

File tree

6 files changed

+265
-33
lines changed

6 files changed

+265
-33
lines changed

Custom Menu Text/Beon

308 KB
Binary file not shown.

Custom Menu Text/CustomMenuText.csproj

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848
<Reference Include="System.Data" />
4949
<Reference Include="System.Net.Http" />
5050
<Reference Include="System.Xml" />
51-
<Reference Include="TextMeshPro-1.0.55.2017.1.0b12, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
52-
<SpecificVersion>False</SpecificVersion>
53-
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\TextMeshPro-1.0.55.2017.1.0b12.dll</HintPath>
51+
<Reference Include="Unity.TextMeshPro">
52+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
5453
</Reference>
5554
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
5655
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
5756
</Reference>
57+
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
60+
</Reference>
5861
<Reference Include="UnityEngine.CoreModule">
5962
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
6063
</Reference>
@@ -65,6 +68,20 @@
6568
<ItemGroup>
6669
<Compile Include="CustomMenuTextPlugin.cs" />
6770
<Compile Include="Properties\AssemblyInfo.cs" />
71+
<Compile Include="Properties\Resources.Designer.cs">
72+
<AutoGen>True</AutoGen>
73+
<DesignTime>True</DesignTime>
74+
<DependentUpon>Resources.resx</DependentUpon>
75+
</Compile>
76+
</ItemGroup>
77+
<ItemGroup>
78+
<EmbeddedResource Include="Properties\Resources.resx">
79+
<Generator>ResXFileCodeGenerator</Generator>
80+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
81+
</EmbeddedResource>
82+
</ItemGroup>
83+
<ItemGroup>
84+
<None Include="Beon" />
6885
</ItemGroup>
6986
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7087
<PropertyGroup>

Custom Menu Text/CustomMenuTextPlugin.cs

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
using System;
1+
using IllusionPlugin;
2+
using System;
23
using System.Collections.Generic;
3-
using System.Linq;
44
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using TMPro;
58
using UnityEngine;
69
using 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:
4851
BEAT
@@ -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

Custom Menu Text/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("3.0.0.0")]
36+
[assembly: AssemblyFileVersion("3.0.0.0")]

Custom Menu Text/Properties/Resources.Designer.cs

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)