move away from using GetCallingAssembly and GetExecutingAssembly

This commit is contained in:
Az committed 2026-10-22 22:35:17 -04:00
1 parent f9274eda09
commit 17dafadec8
4 files changed
+98 -22

No files matched your search

+37 -11
View File
@@ -72,6 +72,7 @@ public static class MiraLocaleManager
/// </summary>
public static Dictionary<MiraLanguage, string> LangCultureList { get; } = new()
{
// Vanilla
{ MiraLanguage.English, "en-US" },
{ MiraLanguage.Latam, "es-419" },
{ MiraLanguage.Brazilian, "pt-BR" },
@@ -88,15 +89,17 @@ public static class MiraLocaleManager
{ MiraLanguage.SChinese, "zh-CN" },
{ MiraLanguage.TChinese, "zh-TW" },
{ MiraLanguage.Irish, "ga-IE" },
{ MiraLanguage.Polish, "pl-PL" }, // Custom
{ MiraLanguage.Turkish, "tr-TR" }, // Custom
{ MiraLanguage.Swedish, "sv-SE" }, // Custom
{ MiraLanguage.Lithuanian, "lt-LT" }, // Custom
{ MiraLanguage.Czech, "cs-CZ" }, // Custom
{ MiraLanguage.LChinese, "lzh-CN" }, // Custom
{ MiraLanguage.Greek, "el-GR" }, // Custom
{ MiraLanguage.Arabic, "arb" }, // Custom
{ MiraLanguage.Hebrew, "heb" }, // Custom
// Custom
{ MiraLanguage.Polish, "pl-PL" },
{ MiraLanguage.Turkish, "tr-TR" },
{ MiraLanguage.Swedish, "sv-SE" },
{ MiraLanguage.Lithuanian, "lt-LT" },
{ MiraLanguage.Czech, "cs-CZ" },
{ MiraLanguage.LChinese, "lzh-CN" },
{ MiraLanguage.Greek, "el-GR" },
{ MiraLanguage.Arabic, "arb" },
{ MiraLanguage.Hebrew, "heb" },
};
/// <summary>
@@ -123,26 +126,49 @@ public static class MiraLocaleManager
/// Call once per mod during plugin Load().
/// </summary>
/// <param name="modGuid">The mod GUID (e.g., "mira.example").</param>
[Obsolete("Pass typeof(YourPlugin).Assembly directly to Register for better performance.")]
public static void Register(string modGuid)
{
var callingAssembly = Assembly.GetCallingAssembly();
LoadInternalStrings(callingAssembly, callingAssembly.GetName().Name!, modGuid);
}
/// <summary>
/// Registers translations for a mod.
/// Call once per mod during plugin Load().
/// </summary>
/// <param name="modGuid">The mod GUID (e.g., "mira.example").</param>
/// <param name="assembly">The <see cref="Assembly"/> to load the strings from.</param>
public static void Register(string modGuid, Assembly assembly)
{
LoadInternalStrings(assembly, assembly.GetName().Name!, modGuid);
}
/// <summary>
/// Registers translations for a mod.
/// Call once per mod during plugin Load().
/// </summary>
/// <param name="modGuid">The mod GUID (e.g., "mira.example").</param>
/// <param name="internalName">The mod's root namespace (e.g., "mira.api").</param>
[Obsolete("Pass typeof(YourPlugin).Assembly directly to Register for better performance.")]
public static void Register(string modGuid, string internalName)
{
var callingAssembly = Assembly.GetCallingAssembly();
LoadInternalStrings(callingAssembly, internalName, modGuid);
}
/// <summary>
/// Registers translations for a mod.
/// Call once per mod during plugin Load().
/// </summary>
/// <param name="modGuid">The mod GUID (e.g., "mira.example").</param>
/// <param name="internalName">The mod's root namespace (e.g., "mira.api").</param>
/// <param name="assembly">The <see cref="Assembly"/> to load the strings from.</param>
public static void Register(string modGuid, string internalName, Assembly assembly)
{
LoadInternalStrings(assembly, internalName, modGuid);
}
/// <summary>
/// Translates a key into the current language.
/// </summary>
@@ -1,3 +1,4 @@
using System;
using System.Reflection;
using UnityEngine;
@@ -6,17 +7,39 @@ namespace MiraAPI.Utilities.Assets;
/// <summary>
/// A utility class for loading .WAV audio assets from the DLL's embedded resources.
/// </summary>
/// <param name="path">The path of the wave file.</param>
public class LoadableAudioResourceAsset(string path) : LoadableAsset<AudioClip>
public class LoadableAudioResourceAsset : LoadableAsset<AudioClip>
{
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
private readonly string _path;
private readonly Assembly _assembly;
/// <summary>
/// Initializes a new instance of the <see cref="LoadableAudioResourceAsset"/> class with the provided resource path and the assembly containing the asset.
/// </summary>
/// <param name="path">The path of the wave file.</param>
/// <param name="assembly">The <see cref="Assembly"/> containing the asset.</param>
public LoadableAudioResourceAsset(string path, Assembly assembly)
{
_path = path;
_assembly = assembly;
}
/// <summary>
/// Initializes a new instance of the <see cref="LoadableAudioResourceAsset"/> class with the provided resource path.
/// </summary>
/// <param name="path">The path of the wave file.</param>
[Obsolete("Pass typeof(YourPlugin).Assembly directly to the constructor for better performance.")]
public LoadableAudioResourceAsset(string path)
{
_path = path;
_assembly = Assembly.GetCallingAssembly();
}
/// <inheritdoc />
public override AudioClip LoadAsset()
{
if (!LoadedAsset)
{
LoadedAsset = AudioTools.LoadAudioFromResources(path, _assembly);
LoadedAsset = AudioTools.LoadAudioFromResources(_path, _assembly);
}
return LoadedAsset!;
@@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
using UnityEngine;
namespace MiraAPI.Utilities.Assets;
@@ -6,18 +7,44 @@ namespace MiraAPI.Utilities.Assets;
/// <summary>
/// A utility class for loading assets from embedded resources.
/// </summary>
/// <param name="path">The path to the embedded resource.</param>
/// <param name="pixelsPerUnit">The pixels per unit for the loaded sprite.</param>
public class LoadableResourceAsset(string path, float pixelsPerUnit = 100f) : LoadableAsset<Sprite>
public class LoadableResourceAsset : LoadableAsset<Sprite>
{
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
private readonly string _path;
private readonly float _pixelsPerUnit;
private readonly Assembly _assembly;
/// <summary>
/// Initializes a new instance of the <see cref="LoadableResourceAsset"/> class with the provided resource path and the assembly containing the asset.
/// </summary>
/// <param name="path">The path to the embedded resource.</param>
/// <param name="assembly">The <see cref="Assembly"/> containing the asset.</param>
/// <param name="pixelsPerUnit">The pixels per unit for the loaded sprite.</param>
public LoadableResourceAsset(string path, Assembly assembly, float pixelsPerUnit = 100f)
{
_path = path;
_assembly = assembly;
_pixelsPerUnit = pixelsPerUnit;
}
/// <summary>
/// Initializes a new instance of the <see cref="LoadableResourceAsset"/> class with the provided resource path and the assembly containing the asset.
/// </summary>
/// <param name="path">The path to the embedded resource.</param>
/// <param name="pixelsPerUnit">The pixels per unit for the loaded sprite.</param>
[Obsolete("Pass typeof(YourPlugin).Assembly directly to the constructor for better performance.")]
public LoadableResourceAsset(string path, float pixelsPerUnit = 100f)
{
_path = path;
_pixelsPerUnit = pixelsPerUnit;
_assembly = Assembly.GetCallingAssembly();
}
/// <inheritdoc />
public override Sprite LoadAsset()
{
if (!LoadedAsset)
{
LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly, pixelsPerUnit);
LoadedAsset = SpriteTools.LoadSpriteFromPath(_path, _assembly, _pixelsPerUnit);
}
return LoadedAsset!;
+1 -1
View File
@@ -12,7 +12,7 @@ public static class MiraAssets
{
var boxTex = SpriteTools.LoadTextureFromResourcePath(
"MiraAPI.Resources.RoundedBox.png",
System.Reflection.Assembly.GetExecutingAssembly());
typeof(MiraAssets).Assembly);
var boxSprite = Sprite.Create(
boxTex,
new Rect(0, 0, boxTex.width, boxTex.height),