//------------------------ Converting to JSON -------------------------- /// <summary> /// Converting AnchorInfo list to JSON data /// </summary> /// <returns></returns> public JObject AnchorInfoListToJSON() { //prepare anchor info list List <AnchorInfo> anchorInfoList = new List <AnchorInfo>(); foreach (GameObject anchorObj in anchorObjList) { AnchorInfo info = anchorObj.GetComponent <AnchorController>().GetAnchorInfo(); anchorInfoList.Add(info); } //prepare an arr for converting to JSON AnchorInfoList tempAnchorList = new AnchorInfoList { sbActivityCollection = new AnchorInfo[anchorInfoList.Count] }; for (int i = 0; i < anchorInfoList.Count; ++i) { tempAnchorList.sbActivityCollection[i] = anchorInfoList[i]; } //convert to JSON JObject jObject = JObject.FromObject(tempAnchorList); MessageManager.Instance.DebugMessage(jObject.ToString()); return(jObject); }
/// <summary> /// Parsing JSON data to have a AnchorInfo list /// </summary> /// <param name="mapMetadata"></param> public void AnchorInfoListFromJSON(JToken mapMetadata) { ClearAnchors(); if (mapMetadata is JObject && mapMetadata[Const.ANCHOR_DATA_JSON_ROOT] is JObject) { AnchorInfoList anchorList = mapMetadata[Const.ANCHOR_DATA_JSON_ROOT].ToObject <AnchorInfoList>(); if (anchorList.sbActivityCollection == null) { Debug.Log("No anchors created!"); return; } foreach (var anchorInfo in anchorList.sbActivityCollection) { GameObject anchorObj = RebornAnchorObj(anchorInfo); anchorObj.GetComponentInChildren <AnchorController>().index = anchorObjList.Count; anchorObjList.Add(anchorObj); } } }