Код: Выделить всё
[Serializable]
public class PuzzleSphereTarget
{
public Nullable x;
public Nullable y;
public Nullable z;
public PuzzleSphereTarget()
{
this.x = null;
this.y = null;
this.z = null;
}
public PuzzleSphereTarget(float xParam, float yParam, float zParam)
{
this.x = xParam;
this.y = yParam;
this.z = zParam;
}
public string ToJson()
{
return JsonUtility.ToJson(this);
}
}
Код: Выделить всё
[Serializable]
public class PuzzleSphereInformation
{
public string creatorName { get; set; }
public List
puzzleSphereTarget { get; set; }
public PuzzleSphereInformation()
{
this.creatorName = null;
this.puzzleSphereTarget = new List();
}
public PuzzleSphereInformation(string creatorName, List puzzleSphereTarget)
{
this.creatorName = creatorName;
this.puzzleSphereTarget = puzzleSphereTarget;
}
public string ToJson()
{
return JsonUtility.ToJson(this);
}
}
Код: Выделить всё
// creatorName: string, puzzleTargets: List
private void SavePuzzle(creatorName, puzzleTargets)
PuzzleSphereInformation puzzleInfo = new PuzzleSphereInformation(creatorName, puzzleTargets);
string puzzleInfoJson = JsonConvert.SerializeObject(puzzleInfo);
FirebaseDatabase.DefaultInstance.GetReference($"/community_puzzles/").Push().SetRawJsonValueAsync(puzzleInfoJson);
}
Код: Выделить всё
{"creatorName":"test user","puzzleSphereTarget":[{"x":-0.2674436,"y":0.009597826,"z":0.894937754},{"x":0.2539144,"y":0.00647806656,"z":0.8653086}]}Код: Выделить всё
_databaseReference.GetValueAsync().ContinueWithOnMainThread(task =>
{
//// omitted firebase code ////
foreach (DataSnapshot targetInfo in targetSnapshot.Children)
{
string puzzleDataJson = targetInfo.GetRawJsonValue();
PuzzleSphereInformation puzzleInformation = JsonConvert.DeserializeObject
(puzzleDataJson);
Debug.Log("creatorName" + puzzleInformation.creatorName); // nothing
}
//// omitted fb code////
});
Я пробовал JsonUtility.FromJson, JsonConvert, но ни один из них не помог.
Подробнее здесь: https://stackoverflow.com/questions/788 ... ot-working
Мобильная версия