There's a class I can't edit directly with a method something like
BuildingSaveData {
public override BuildingSaveData SaveTheThing(Building b){
this.propOne = b.propOne;
//etc etc
return this;
}
public SerializableVector3 propOne;
}
And somewhere down the line it gets serialized and saved off for later.
Then in reverse
public override Building LoadTheThing(Building b){
b.propOne = this.propOne;
//etc etc
return b;
}
I want to add a property to this object to get serialized/deserialized along with everything else.
I don't think it's possible to add a property at runtime to a class in C#, but I'm not that familiar with Harmony yet so it may have some magic for this I'm unaware of.
My Attempt
This is what I'm trying to do on the save:
[HarmonyPatch(typeof(BuildingSaveData))]
[HarmonyPatch(nameof(BuildingSaveData.SaveTheThing))]
public class BuildingSavePatch
{
static void Postfix(Building b, BuildingSaveData __result)
{
__result.localScale = b.transform.GetChild(0).localScale;
}
}
But this throws the obvious error of "BuildingSaveData does not contain a definition for localScale"