【发布时间】:2021-06-17 19:43:53
【问题描述】:
我正在使用 unity c# 开发 2D 游戏应用程序。
我有一个项目(对象)列表,每个项目包含双倍价格、双倍乘数和 int 级别。
我正在尝试使用 json 将该列表加载到 FireBase 实时数据库,以保存玩家的个人商店。 尝试让它在数据库中看起来像这样:
这是我的 Item 类:
public class Item
{
public double Price {get; set;}
public double Multiplier { get; set; }
public int Level { get; set; }
public Item(double price, double multiplier, int level)
{
this.Price = price;
this.Multiplier = multiplier;
this.Level = level;
}
}
这是我的 Shop 课程:
public class Shop
{
public List<Item> ShopList { get; set; }
public Shop()
{
this.ShopList = new List<Item>();
}
public void InitShop()
{
string[] lines = System.IO.File.ReadAllLines(@"Assets\Scripts\Data\ShopData.txt");
foreach (string line in lines)
{
string[] words = line.Split(',');
double price = Convert.ToDouble(words[0]);
double mul = Convert.ToDouble(words[1]);
int level = Convert.ToInt32(words[2]);
Item i = new Item(price, mul, level);
this.ShopList.Add(i);
}
}
【问题讨论】:
标签: c# firebase unity3d firebase-realtime-database