继续
This commit is contained in:
@@ -27,6 +27,18 @@ namespace SLSFramework.UModAssistance
|
||||
{
|
||||
public static readonly SerializableDictionary<string, ModHost> LoadedMods = new SerializableDictionary<string, ModHost>();
|
||||
public static readonly Dictionary<Type, Dictionary<string, ScriptableObject>> Database = new Dictionary<Type, Dictionary<string, ScriptableObject>>();
|
||||
|
||||
/// <summary>
|
||||
/// Get the standardized class name for a mod class, combining its class name and mod name.
|
||||
/// Format: "ModName_ClassName"
|
||||
/// </summary>
|
||||
public static string GetModClassName(Type type)
|
||||
{
|
||||
string modName = type.Namespace!.Replace("Continentis.Mods.", "").Split('.')[0];
|
||||
string className = type.Name;
|
||||
return $"{modName}_{className}";
|
||||
}
|
||||
|
||||
public static bool IsValidAssetName(string assetName) => Regex.IsMatch(assetName, @"^\w+_\w+_.+$");
|
||||
|
||||
/// <summary>
|
||||
@@ -120,6 +132,15 @@ namespace SLSFramework.UModAssistance
|
||||
public partial class ModManager
|
||||
{
|
||||
public static readonly Dictionary<string, Type> TypeRegistry = new Dictionary<string, Type>();
|
||||
public static string GetTypeID(Type type)
|
||||
{
|
||||
return type.Namespace!.Replace("Continentis.Mods.", "") + "." + type.Name;
|
||||
}
|
||||
|
||||
public static string GetTypeID(string modName, string classification, string className)
|
||||
{
|
||||
return $"{modName}.{classification}.{className}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从一个已加载的Mod中,查找所有指定基类的子类,并将其注册到全局字典中。
|
||||
@@ -144,15 +165,16 @@ namespace SLSFramework.UModAssistance
|
||||
|
||||
foreach (var type in typesInAssembly)
|
||||
{
|
||||
if (!TypeRegistry.ContainsKey(type.Name))
|
||||
string typeID = GetTypeID(type);
|
||||
|
||||
if (TypeRegistry.TryAdd(typeID, type))
|
||||
{
|
||||
TypeRegistry.Add(type.Name, type);
|
||||
Debug.Log($"Registered script type '{type.FullName}' from mod '{host.CurrentMod.NameInfo.ModName}'.");
|
||||
Debug.Log($"Registered script type '{typeID}' from mod '{host.CurrentMod.NameInfo.ModName}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理命名冲突:如果不同Mod中存在同名的类,后加载的会被忽略
|
||||
Debug.LogWarning($"Duplicate script type name found: '{type.Name}'. The existing type from assembly '{TypeRegistry[type.Name].Assembly.FullName}' will be kept.");
|
||||
Debug.LogWarning($"Duplicate script type name found: '{typeID}'. The existing type from assembly '{TypeRegistry[type.Name].Assembly.FullName}' will be kept.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,13 +186,13 @@ namespace SLSFramework.UModAssistance
|
||||
}
|
||||
}
|
||||
|
||||
public static Type GetType(string typeName)
|
||||
public static Type GetType(string typeID)
|
||||
{
|
||||
if (TypeRegistry.TryGetValue(typeName, out Type type))
|
||||
if (TypeRegistry.TryGetValue(typeID, out Type type))
|
||||
{
|
||||
return type;
|
||||
}
|
||||
Debug.LogWarning($"Type '{typeName}' not found in TypeRegistry.");
|
||||
Debug.LogWarning($"Type '{typeID}' not found in TypeRegistry.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user