继续
This commit is contained in:
@@ -150,7 +150,7 @@ namespace SLSFramework.UModAssistance
|
||||
/// <param name="namespaceToRemove">可选参数,用于从路径中移除特定的命名空间部分 (例如 ".Cards")</param>
|
||||
/// <returns>如果值被用户改变,则返回true</returns>
|
||||
protected bool DrawTypeSelectorGUI(SerializedProperty classNameProp, string label, Type baseType,
|
||||
string namespacePrefix = null, string namespaceToRemove = null)
|
||||
out Type returnedType, string namespacePrefix = null, string namespaceToRemove = null)
|
||||
{
|
||||
// --- 核心修改 2:使用包含 namespaceToRemove 的复合键 ---
|
||||
var cacheKey = new Tuple<Type, string>(baseType, namespaceToRemove ?? string.Empty);
|
||||
@@ -179,9 +179,12 @@ namespace SLSFramework.UModAssistance
|
||||
classNameProp.stringValue = (newIndex >= 0 && newIndex < types.Length)
|
||||
? types[newIndex].Name
|
||||
: string.Empty;
|
||||
|
||||
returnedType = types[newIndex];
|
||||
return true;
|
||||
}
|
||||
|
||||
returnedType = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace SLSFramework.UModAssistance
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CharacterBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CardLogicBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(EquipmentBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(Continentis.MainGame.Card.CombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(Continentis.MainGame.Character.CombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(CardCombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(CharacterCombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(RulesCollectionBase));
|
||||
|
||||
string manifestName = host.CurrentMod.NameInfo.ModName + "_Manifest";
|
||||
|
||||
@@ -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