Class ResistanceDictionaryFormatter
- Namespace
- GrindFest
- Assembly
- GrindFest.dll
MemoryPack cannot handle a custom collection subclass, and ResistanceDictionary is exactly that: a UnitySerializedDictionary<TKey, TValue> deriving from Dictionary<Element, float>. Without this formatter the type is simply unknown to MemoryPack and every resistance on every item and hero would vanish on save - silently, read back as all zeroes rather than failing. The data does live in the base dictionary, so this reuses the built-in DictionaryFormatter instead of re-implementing the encoding.
It cannot be attached with an attribute: MemoryPackCustomFormatterAttribute<T> is abstract, and a generic attribute needs C# 11 while Unity compiles at C# 9. So it is registered at runtime by MemoryPackSetup - and anything that (de)serializes a SaveData outside play mode (editor tooling, an edit-mode test) has to call that itself, because the RuntimeInitializeOnLoadMethod hook does not run there. That is how a plain round-trip failed the first time this was tested.
[Preserve]
public sealed class ResistanceDictionaryFormatter : MemoryPackFormatter<ResistanceDictionary>, IMemoryPackFormatter<ResistanceDictionary>, IMemoryPackFormatter
- Inheritance
-
objectMemoryPackFormatter<ResistanceDictionary>ResistanceDictionaryFormatter
- Implements
-
IMemoryPackFormatter<ResistanceDictionary>IMemoryPackFormatter