Exception thrown when reading ES3UserType_xxx with an enum variable
Posted: Sat Jul 17, 2021 3:20 pm
The exception:
Write:
Read:
I have to change enum to int:[Exception] FormatException: Input string was not in a correct format.
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
ES3JSONReader.Read_int() at /Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:549
-->549: internal override int Read_int(){ return int.Parse(GetValueString()); }
ES3Type_enum.Read[T]() at /Plugins/Easy Save 3/Scripts/Types/Primitive Types/ES3Type_enum.cs:42
-->42: if(underlyingType == typeof(int)) return Enum.ToObject (type, reader.Read_int());
Write:
Code: Select all
protected override void WriteComponent(object obj, ES3Writer writer)
{
var instance = (NaAGames.Humanoid)obj;
//writer.WriteProperty("humanoidState", instance.humanoidState, ES3Internal.ES3TypeMgr.GetES3Type(typeof(NaAGames.HumanoidState)));
writer.WriteProperty("humanoidState", instance.humanoidState, ES3Type_int.Instance);
}
Code: Select all
protected override void ReadComponent<T>(ES3Reader reader, object obj)
{
var instance = (NaAGames.Humanoid)obj;
foreach(string propertyName in reader.Properties)
{
switch(propertyName)
{
case "humanoidState":
//instance.humanoidState = reader.Read<NaAGames.HumanoidState>();
instance.humanoidState = (NaAGames.HumanoidState)reader.Read<System.Int32>(ES3Type_int.Instance);
break;
}
}
}
}