ATNativeAdView.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Text;
  5. namespace AnyThinkAds.Api
  6. {
  7. public class ATNativeAdView
  8. {
  9. public ATNativeConfig config;
  10. public ATNativeAdView(ATNativeConfig config)
  11. {
  12. this.config = config;
  13. }
  14. private string parentKey = "parent";
  15. private string appIconKey = "appIcon";
  16. private string mainImageKey = "mainImage";
  17. private string titleKey = "title";
  18. private string descKey = "desc";
  19. private string adLogoKey = "adLogo";
  20. private string ctaButtonKey = "cta";
  21. private string dislikeButtonKey = "dislike";
  22. private string elementsKey = "elements";
  23. public string toJSON()
  24. {
  25. StringBuilder builder = new StringBuilder();
  26. builder.Append("{");
  27. if(config.parentProperty != null)
  28. {
  29. builder.Append("\"").Append(parentKey).Append("\"");
  30. builder.Append(":");
  31. builder.Append(JsonUtility.ToJson(config.parentProperty));
  32. builder.Append(",");
  33. }
  34. if(config.appIconProperty != null){
  35. builder.Append("\"").Append(appIconKey).Append("\"");
  36. builder.Append(":");
  37. builder.Append(JsonUtility.ToJson(config.appIconProperty));
  38. builder.Append(",");
  39. }
  40. if(config.mainImageProperty != null)
  41. {
  42. builder.Append("\"").Append(mainImageKey).Append("\"");
  43. builder.Append(":");
  44. builder.Append(JsonUtility.ToJson(config.mainImageProperty));
  45. builder.Append(",");
  46. }
  47. if(config.titleProperty != null)
  48. {
  49. builder.Append("\"").Append(titleKey).Append("\"");
  50. builder.Append(":");
  51. builder.Append(JsonUtility.ToJson(config.titleProperty));
  52. builder.Append(",");
  53. }
  54. if(config.descProperty != null)
  55. {
  56. builder.Append("\"").Append(descKey).Append("\"");
  57. builder.Append(":");
  58. builder.Append(JsonUtility.ToJson(config.descProperty));
  59. builder.Append(",");
  60. }
  61. if(config.adLogoProperty != null)
  62. {
  63. builder.Append("\"").Append(adLogoKey).Append("\"");
  64. builder.Append(":");
  65. builder.Append(JsonUtility.ToJson(config.adLogoProperty));
  66. builder.Append(",");
  67. }
  68. if(config.ctaButtonProperty != null)
  69. {
  70. builder.Append("\"").Append(ctaButtonKey).Append("\"");
  71. builder.Append(":");
  72. builder.Append(JsonUtility.ToJson(config.ctaButtonProperty));
  73. builder.Append(",");
  74. }
  75. if(config.dislikeButtonProperty != null)
  76. {
  77. builder.Append("\"").Append(dislikeButtonKey).Append("\"");
  78. builder.Append(":");
  79. builder.Append(JsonUtility.ToJson(config.dislikeButtonProperty));
  80. builder.Append(",");
  81. }
  82. if (config.elementsProperty != null)
  83. {
  84. builder.Append("\"").Append(elementsKey).Append("\"");
  85. builder.Append(":");
  86. builder.Append(JsonUtility.ToJson(config.elementsProperty));
  87. }
  88. string temp = builder.ToString();
  89. if (temp.EndsWith(","))
  90. {
  91. temp = temp.Substring(0, temp.Length - 1);
  92. }
  93. temp = temp + "}";
  94. return temp;
  95. }
  96. }
  97. }