Discussion and help for Easy Save 3, The Complete Save Game & Data Serializer System for the Unity Engine
robotSmith
Posts: 39 Joined: Thu Apr 01, 2021 4:53 pm
Post
by robotSmith » Sat May 20, 2023 2:51 pm
Hello!
I recently moved from I2 to Unity's Localization (Unity.Localization), and I use LocalizedString variables in some of the objects I save, however, I see that the LocalizedString is not being saved. Is is supported? And if not, do you have any plans in your roadmap to support it natively?
Thank you!
Regards
Code: Select all
{
"item" : {
"__type" : "Item,Assembly-CSharp",
"value" : {
"_ES3Ref" : "5910518074290597606",
"itemID" : "Feather",
"itemName" : "Feather",
"itemCategory" : 1,
"itemIcon" : {
"_ES3Ref" : "4472055720407138531"
},
"material" : {
"_ES3Ref" : "851144455802509952"
},
"gridSize" : {
"x" : 32,
"y" : 32
},
"localName" : {
}
}
}
}
Joel
Moodkie Staff
Posts: 5048 Joined: Wed Nov 07, 2012 10:32 pm
Post
by Joel » Mon May 22, 2023 9:13 am
Hi there,
As this is the first time this has been requested I've added a feature request here:
https://moodkie.com/forum/viewtopic.php ... 23&p=11089
There are aspects which Unity have made internal which wouldn't be possible to serialize at runtime and makes this non-trivial. However, if there's enough demand for it we'll look into it deeper.
All the best,
Joel
robotSmith
Posts: 39 Joined: Thu Apr 01, 2021 4:53 pm
Post
by robotSmith » Mon May 22, 2023 8:17 pm
Sounds good Joel, thank you for creating the request.
I ended up figuring out how to do it with a user type for my use case. This does a simple job of finding and assigning a LocalizedString to a variable, as that's as much as I need.
Sharing here in case somebody needs this:
Code: Select all
namespace ES3Types
{
[UnityEngine.Scripting.Preserve]
[ES3PropertiesAttribute("TableReference", "TableEntryReference")]
public class ES3UserType_LocalizedString : ES3ObjectType
{
public static ES3Type Instance = null;
public ES3UserType_LocalizedString() : base(typeof(UnityEngine.Localization.LocalizedString)){ Instance = this; priority = 1; }
protected override void WriteObject(object obj, ES3Writer writer)
{
var instance = (UnityEngine.Localization.LocalizedString)obj;
writer.WriteProperty<string>("TableReference", instance.TableReference.TableCollectionName);
writer.WriteProperty<long>("TableEntryReference", instance.TableEntryReference.KeyId);
}
protected override void ReadObject<T>(ES3Reader reader, object obj)
{
var instance = (UnityEngine.Localization.LocalizedString)obj;
foreach (string propertyName in reader.Properties)
{
switch (propertyName)
{
case "TableReference":
instance.TableReference = reader.Read<string>();
break;
case "TableEntryReference":
instance.TableEntryReference = reader.Read<long>();
break;
default:
reader.Skip();
break;
}
}
}
protected override object ReadObject<T>(ES3Reader reader)
{
var instance = new UnityEngine.Localization.LocalizedString();
ReadObject<T>(reader, instance);
return instance;
}
}
public class ES3UserType_LocalizedStringArray : ES3ArrayType
{
public static ES3Type Instance;
public ES3UserType_LocalizedStringArray() : base(typeof(UnityEngine.Localization.LocalizedString[]), ES3UserType_LocalizedString.Instance)
{
Instance = this;
}
}
}
Regards!
Joel
Moodkie Staff
Posts: 5048 Joined: Wed Nov 07, 2012 10:32 pm
Post
by Joel » Tue May 23, 2023 8:33 am
Thanks for sharing, much appreciated