void ISerializationCallbackReceiver.OnAfterDeserialize() { if (this.hasPackages == false) { this.packages = null; } if (this.hasLanguages == false) { this.languages = null; } if (this.hasVets == false) { this.vets = null; } if (this.hasVoucherPackages == false) { this.voucherPackages = null; } if (this.hasVouchers == false) { this.vouchers = null; } if (this.hasPeriods == false) { this.periods = null; } // Link detailed versions to their version in packages. if (this.Packages != null && this.versions != null) { for (int i = 0, max = this.versions.Count; i < max; ++i) { VersionDetailed versionDetail = this.versions[i]; for (int j = 0, max2 = this.Packages.Length; j < max2; ++j) { Package package = this.Packages[j]; for (int k = 0, max3 = package.versions.Length; k < max3; ++k) { Version version = package.versions[k]; if (version.id == versionDetail.package.version.id) { version.detailed = versionDetail; } } } } } }
public static void RequestGetPackageVersion(this PublisherDatabase database, IPublisherAPI api, Version version, Action <RequestResponse <VersionDetailed> > onCompleted = null) { api.GetPackageVersion(version.id, (r, result) => { RequestResponse <VersionDetailed> requestResponse = new RequestResponse <VersionDetailed>() { context = version, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { try { StringBuilder buffer = Utility.GetBuffer(result); // Convert object "languages" to a JSON array. int start = result.IndexOf("\"languages\":{"); Debug.AssertFormat(start != -1, "Token \"languages\" not found when requesting version \"{0}\".", version); start += "\"languages\":{".Length - 1; // Rely on brackets instead of sibling, in case Unity server changes the order. int end = DataStructureExtension.DigestBracketScope(buffer, start) - 1; Debug.AssertFormat(end < buffer.Length, "Closing token of \"languages\" not found when requesting version \"{0}\".", version); buffer[start] = '['; buffer[end] = ']'; int i = start; while (i < buffer.Length && buffer[i] != ']') { ++i; int startBracket = i; i = DataStructureExtension.DigestString(buffer, i); buffer[i + 1] = ','; buffer.Remove(i + 2, 1); buffer.Insert(startBracket, "{\"languageCode\":"); i = DataStructureExtension.DigestBracketScope(buffer, startBracket); } result = Utility.ReturnBuffer(buffer); } catch (Exception ex) { Debug.LogException(ex); } VersionDetailed versionDetail = JsonUtility.FromJson <VersionDetailed>(result); var languages = new List <VersionDetailed.Package.Version.Language>(versionDetail.package.version.languages); languages.Sort((a, b) => a.languageCode.CompareTo(b.languageCode)); versionDetail.package.version.languages = languages.ToArray(); version.detailed = versionDetail; int index = database.versions.FindIndex(v => v.package.version.id == versionDetail.package.version.id); if (index != -1) { database.versions[index] = versionDetail; } else { database.versions.Add(versionDetail); } requestResponse.ok = true; requestResponse.result = versionDetail; } if (onCompleted != null) { onCompleted(requestResponse); } }); }