Hello,
So this might be a vague question, if so, let me know and I’ll try to elaborate.
(preface, I am using C#)
I am currently using a Json file so I can easily and quickly create a varied amount of items to be collected in game.
However, if I release my game, I won’t want the data to be stored in an easily read and edited json file - so how would I go about encrypting the Json for a release build? Or is there an easier way to read from a file, that is encrypted, but easily editable while developing the project?
I have attached some pseudo code below so people can take a look at how I am currently operating and if there is an easy solution.
Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class ItemPickupClass : MonoBehaviour
{
public string itemDataPath;
public Spring SpringData;
public Summer SummerData;
public Autumn AutumnData;
public Winter WinterData;
[System.Serializable]
public class AllSeasons
{
public Spring Spring;
public Summer Summer;
public Autumn Autumn;
public Winter Winter;
}
public class Season
{
public List<Item> Day;
public List<Item> Night;
}
[System.Serializable]
public class Spring : Season
{
}
[System.Serializable]
public class Summer : Season
{
}
[System.Serializable]
public class Autumn : Season
{
}
[System.Serializable]
public class Winter : Season
{
}
[System.Serializable]
public class Item
{
public int ItemID;
public string name;
public string description;
public int value;
public int weight;
}
private void Start()
{
itemDataPath = Path.Combine(Application.streamingAssetsPath, "ItemDatabase.json");
string JsonText = File.ReadAllText(itemDataPath);
AllSeasons getSeasonData = new AllSeasons();
getSeasonData = JsonUtility.FromJson<AllSeasons>(JsonText);
SpringData = getSeasonData.Spring;
SummerData = getSeasonData.Summer;
AutumnData = getSeasonData.Autumn;
WinterData = getSeasonData.Winter;
}
}
and here is an example (stripped down to be shorter) of the Json I am reading from:
{
"Spring":
{
"Day": [
{
"ItemID": 1,
"name": "Spring Day Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
],
"Night": [
{
"ItemID": 1,
"name": "Spring Night Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
]
},
"Summer":
{
"Day": [
{
"ItemID": 1,
"name": "Summer Day Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
],
"Night": [
{
"ItemID": 1,
"name": "Summer Night Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
]
},
"Autumn":
{
"Day": [
{
"ItemID": 1,
"name": "Autumn Day Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
],
"Night": [
{
"ItemID": 1,
"name": "Autumn Night Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
]
},
"Winter":
{
"Day": [
{
"ItemID": 1,
"name": "Winter Day Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
],
"Night": [
{
"ItemID": 1,
"name": "Winter Night Book",
"description": "A small book",
"value": 2,
"weight": 50,
}
]
},
}