I am having this weird issue where saving a dynamically created sprite decreases the pivot normalized value. How I'm doing the save is:
- Save the sprite
- Save the texture2d of the sprite
and on load:
- Load the texture2d of the sprite
- Load the sprite
This is the code snippet. I also attached a video showing the debug info on the Save and Load.
Code: Select all
private void SaveDatabaseWithNewItems()
{
SaveSprites();
ES3.Save<Dictionary<string, IItem>>("ItemDatabase", ItemDictionary);
}
private void SaveSprites()
{
foreach (string itemID in ItemDictionary.Keys)
{
if (ItemDictionary[itemID] is ItemAssembled)
{
string dictionaryID = itemID + "Sprite";
ES3.Save<Sprite>(dictionaryID, ItemDictionary[itemID].Icon);
string textureID = itemID + "Texture";
ES3.Save<Texture2D>(textureID, ItemDictionary[itemID].Icon.texture);
}
}
}
private void Load()
{
ItemDictionary = ES3.Load<Dictionary<string, IItem>>("ItemDatabase");
LoadSprites();
ItemDictionary = ES3.Load<Dictionary<string, IItem>>("ItemDatabase");
}
private void LoadSprites()
{
foreach (string itemID in ItemDictionary.Keys)
{
if (ItemDictionary[itemID] is ItemAssembled)
{
string textureID = itemID + "Texture";
ES3.Load<Texture2D>(textureID);
string dictionaryID = itemID + "Sprite";
ES3.Load<Sprite>(dictionaryID);
}
}
}