Does save works with Localized String from Unity Localization?

Discussion and help for Easy Save 3
Post Reply
robotSmith
Posts: 39
Joined: Thu Apr 01, 2021 4:53 pm

Does save works with Localized String from Unity Localization?

Post by robotSmith »

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" : {
			}
		}
	}
}
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Does save works with Localized String from Unity Localization?

Post by Joel »

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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
robotSmith
Posts: 39
Joined: Thu Apr 01, 2021 4:53 pm

Re: Does save works with Localized String from Unity Localization?

Post by robotSmith »

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!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Does save works with Localized String from Unity Localization?

Post by Joel »

Thanks for sharing, much appreciated :)
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply