TalkingDataSearch.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using UnityEngine;
  2. public class TalkingDataSearch
  3. {
  4. #if UNITY_ANDROID
  5. public AndroidJavaObject javaObj;
  6. #endif
  7. #if UNITY_IPHONE
  8. private string category;
  9. private string content;
  10. #if TD_RETAIL
  11. private string itemId;
  12. private string itemLocationId;
  13. #endif
  14. #if TD_TOUR
  15. private string destination;
  16. private string origin;
  17. private long startDate;
  18. private long endDate;
  19. #endif
  20. #endif
  21. public static TalkingDataSearch CreateSearch()
  22. {
  23. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  24. {
  25. TalkingDataSearch search = new TalkingDataSearch();
  26. #if UNITY_ANDROID
  27. AndroidJavaClass javaClass = new AndroidJavaClass("com.tendcloud.tenddata.TalkingDataSearch");
  28. search.javaObj = javaClass.CallStatic<AndroidJavaObject>("createSearch");
  29. #endif
  30. return search;
  31. }
  32. return null;
  33. }
  34. // 搜索分类
  35. public TalkingDataSearch SetCategory(string category)
  36. {
  37. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  38. {
  39. #if UNITY_ANDROID
  40. if (javaObj != null)
  41. {
  42. javaObj.Call<AndroidJavaObject>("setCategory", category);
  43. }
  44. #endif
  45. #if UNITY_IPHONE
  46. this.category = category;
  47. #endif
  48. }
  49. return this;
  50. }
  51. // 搜索内容
  52. public TalkingDataSearch SetContent(string content)
  53. {
  54. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  55. {
  56. #if UNITY_ANDROID
  57. if (javaObj != null)
  58. {
  59. javaObj.Call<AndroidJavaObject>("setContent", content);
  60. }
  61. #endif
  62. #if UNITY_IPHONE
  63. this.content = content;
  64. #endif
  65. }
  66. return this;
  67. }
  68. #if TD_RETAIL
  69. // 商品 ID(eg.酒店/汽车);至多64字符,支持数字+字母
  70. public TalkingDataSearch SetItemId(string itemId)
  71. {
  72. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  73. {
  74. #if UNITY_ANDROID
  75. if (javaObj != null)
  76. {
  77. javaObj.Call<AndroidJavaObject>("setItemId", itemId);
  78. }
  79. #endif
  80. #if UNITY_IPHONE
  81. this.itemId = itemId;
  82. #endif
  83. }
  84. return this;
  85. }
  86. // 商品位置 ID(eg.求职招聘/教育行业);至多64字符,支持数字+字母
  87. public TalkingDataSearch SetItemLocationId(string itemLocationId)
  88. {
  89. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  90. {
  91. #if UNITY_ANDROID
  92. if (javaObj != null)
  93. {
  94. javaObj.Call<AndroidJavaObject>("setItemLocationId", itemLocationId);
  95. }
  96. #endif
  97. #if UNITY_IPHONE
  98. this.itemLocationId = itemLocationId;
  99. #endif
  100. }
  101. return this;
  102. }
  103. #endif
  104. #if TD_TOUR
  105. // 目的地城市 ID;至多64字符,支持数字+字母
  106. public TalkingDataSearch SetDestination(string destination)
  107. {
  108. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  109. {
  110. #if UNITY_ANDROID
  111. if (javaObj != null)
  112. {
  113. javaObj.Call<AndroidJavaObject>("setDestination", destination);
  114. }
  115. #endif
  116. #if UNITY_IPHONE
  117. this.destination = destination;
  118. #endif
  119. }
  120. return this;
  121. }
  122. // 出发地城市 ID;至多64字符,支持数字+字母
  123. public TalkingDataSearch SetOrigin(string origin)
  124. {
  125. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  126. {
  127. #if UNITY_ANDROID
  128. if (javaObj != null)
  129. {
  130. javaObj.Call<AndroidJavaObject>("setOrigin", origin);
  131. }
  132. #endif
  133. #if UNITY_IPHONE
  134. this.origin = origin;
  135. #endif
  136. }
  137. return this;
  138. }
  139. // 业务事件起始日期(eg.航班出发日期)
  140. public TalkingDataSearch SetStartDate(long startDate)
  141. {
  142. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  143. {
  144. #if UNITY_ANDROID
  145. if (javaObj != null)
  146. {
  147. javaObj.Call<AndroidJavaObject>("setStartDate", startDate);
  148. }
  149. #endif
  150. #if UNITY_IPHONE
  151. this.startDate = startDate;
  152. #endif
  153. }
  154. return this;
  155. }
  156. // 业务事件截止日期(eg.航班返程日期)
  157. public TalkingDataSearch SetEndDate(long endDate)
  158. {
  159. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  160. {
  161. #if UNITY_ANDROID
  162. if (javaObj != null)
  163. {
  164. javaObj.Call<AndroidJavaObject>("setEndDate", endDate);
  165. }
  166. #endif
  167. #if UNITY_IPHONE
  168. this.endDate = endDate;
  169. #endif
  170. }
  171. return this;
  172. }
  173. #endif
  174. #if UNITY_IPHONE
  175. public override string ToString()
  176. {
  177. if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
  178. {
  179. string searchStr = "{\"category\":\"" + category + "\""
  180. + ",\"content\":\"" + content + "\""
  181. #if TD_RETAIL
  182. + ",\"itemId\":\"" + itemId + "\""
  183. + ",\"itemLocationId\":\"" + itemLocationId + "\""
  184. #endif
  185. #if TD_TOUR
  186. + ",\"destination\":\"" + destination + "\""
  187. + ",\"origin\":\"" + origin + "\""
  188. + ",\"startDate\":" + startDate
  189. + ",\"endDate\":" + endDate
  190. #endif
  191. + "}";
  192. return searchStr;
  193. }
  194. return null;
  195. }
  196. #endif
  197. }