AnySDKAds.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System;
  7. namespace anysdk {
  8. public enum AdsResultCode
  9. {
  10. kAdsReceived = 0, /**< enum the callback: the ad is received is at center. */
  11. kAdsShown, /**< enum the callback: the advertisement dismissed. */
  12. kAdsDismissed, /**< enum the callback: the advertisement dismissed. */
  13. kPointsSpendSucceed, /**< enum the callback: the points spend succeed. */
  14. kPointsSpendFailed, /**< enum the callback: the points spend failed. */
  15. kNetworkError, /**< enum the callback of Network error at center. */
  16. kUnknownError, /**< enum the callback of Unknown error. */
  17. kOfferWallOnPointsChanged, /**< enum the callback of Changing the point of offerwall. */
  18. kAdsExtension = 40000 /**< enum value is extension code . */
  19. } ;
  20. /** @brief AdsPos enum, with inline docs */
  21. public enum AdsPos
  22. {
  23. kPosCenter = 0,/**< enum the toolbar is at center. */
  24. kPosTop,/**< enum the toolbar is at top. */
  25. kPosTopLeft,/**< enum the toolbar is at topleft. */
  26. kPosTopRight,/**< enum the toolbar is at topright. */
  27. kPosBottom,/**< enum the toolbar is at bottom. */
  28. kPosBottomLeft,/**< enum the toolbar is at bottomleft. */
  29. kPosBottomRight,/**< enum the toolbar is at bottomright. */
  30. };
  31. /** @brief AdsType enum, with inline docs */
  32. public enum AdsType
  33. {
  34. AD_TYPE_BANNER = 0,/**< enum value is banner ads . */
  35. AD_TYPE_FULLSCREEN,/**< enum value is fullscreen ads . */
  36. AD_TYPE_MOREAPP,/**< enum value is moreapp ads . */
  37. AD_TYPE_OFFERWALL,/**< enum value is offerwall ads . */
  38. } ;
  39. public class AnySDKAds
  40. {
  41. private static AnySDKAds _instance;
  42. public static AnySDKAds getInstance() {
  43. if( null == _instance ) {
  44. _instance = new AnySDKAds();
  45. }
  46. return _instance;
  47. }
  48. /**
  49. *
  50. * @Title: showAds
  51. * @Description: show ad with the type and idx
  52. * @param @param adsType the type of ad
  53. * @param @param idx
  54. * @return void
  55. */
  56. public void showAds(AdsType adsType, int idx = 1)
  57. {
  58. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  59. AnySDKAds_nativeShowAds (adsType,idx);
  60. #else
  61. Debug.Log("This platform does not support!");
  62. #endif
  63. }
  64. /**
  65. *
  66. * @Title: hideAds
  67. * @Description: hide ad with the type and idx
  68. * @param @param adsType the type of ad
  69. * @param @param idx
  70. * @return void
  71. */
  72. public void hideAds(AdsType adsType, int idx = 1)
  73. {
  74. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  75. AnySDKAds_nativeHideAds (adsType,idx);
  76. #else
  77. Debug.Log("This platform does not support!");
  78. #endif
  79. }
  80. /**
  81. - *
  82. - * @Title: preloadAds
  83. - * @Description: preload ad with the type and idx
  84. - * @param @param adsType the type of ad
  85. - * @param @param idx
  86. - * @return void
  87. - */
  88. public void preloadAds(AdsType adsType, int idx = 1)
  89. {
  90. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  91. AnySDKAds_nativePreloadAds (adsType,idx);
  92. #else
  93. Debug.Log("This platform does not support!");
  94. #endif
  95. }
  96. /**
  97. *
  98. * @Title: queryPoints
  99. * @Description: query the ponits in the type of offerwall
  100. * @param @return
  101. * @return float
  102. */
  103. public float queryPoints()
  104. {
  105. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  106. return AnySDKAds_nativeQueryPoints ();
  107. #else
  108. Debug.Log("This platform does not support!");
  109. return 0;
  110. #endif
  111. }
  112. /**
  113. *
  114. * @Title: spendPoints
  115. * @Description: spend the ponits in the type of offerwall
  116. * @param @param points
  117. * @return void
  118. */
  119. public void spendPoints (int points)
  120. {
  121. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  122. AnySDKAds_nativeSpendPoints (points);
  123. #else
  124. Debug.Log("This platform does not support!");
  125. #endif
  126. }
  127. /**
  128. *
  129. * @Title: isAdTypeSupported
  130. * @Description: does the plugin support the type of ad
  131. * @param @param adsType
  132. * @param @return
  133. * @return boolean
  134. */
  135. public bool isAdTypeSupported(AdsType adType)
  136. {
  137. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  138. return AnySDKAds_nativeIsAdTypeSupported (adType);
  139. #else
  140. Debug.Log("This platform does not support!");
  141. return false;
  142. #endif
  143. }
  144. /**
  145. @brief Check function the plugin support or not
  146. */
  147. public bool isFunctionSupported (string functionName)
  148. {
  149. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  150. return AnySDKAds_nativeIsFunctionSupported (functionName);
  151. #else
  152. Debug.Log("This platform does not support!");
  153. return false;
  154. #endif
  155. }
  156. /**
  157. * set debugmode for plugin
  158. *
  159. */
  160. [Obsolete("This interface is obsolete!",false)]
  161. public void setDebugMode(bool bDebug)
  162. {
  163. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  164. AnySDKAds_nativeSetDebugMode (bDebug);
  165. #else
  166. Debug.Log("This platform does not support!");
  167. #endif
  168. }
  169. /**
  170. @brief set pListener The callback object for ads result
  171. @param the MonoBehaviour object
  172. @param the callback of function
  173. */
  174. public void setListener(MonoBehaviour gameObject,string functionName)
  175. {
  176. #if UNITY_ANDROID
  177. AnySDKUtil.registerActionCallback (AnySDKType.Ads, gameObject, functionName);
  178. #elif UNITY_IOS
  179. string gameObjectName = gameObject.gameObject.name;
  180. AnySDKAds_nativeSetListener(gameObjectName,functionName);
  181. #else
  182. Debug.Log("This platform does not support!");
  183. #endif
  184. }
  185. /**
  186. * Get Plugin version
  187. *
  188. * @return string
  189. */
  190. public string getPluginVersion()
  191. {
  192. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  193. StringBuilder version = new StringBuilder();
  194. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  195. AnySDKAds_nativeGetPluginVersion (version);
  196. return version.ToString();
  197. #else
  198. Debug.Log("This platform does not support!");
  199. return "";
  200. #endif
  201. }
  202. /**
  203. * Get Sdk version
  204. *
  205. * @return string
  206. */
  207. public string getSDKVersion()
  208. {
  209. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  210. StringBuilder version = new StringBuilder();
  211. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  212. AnySDKAds_nativeGetSDKVersion (version);
  213. return version.ToString();
  214. #else
  215. Debug.Log("This platform does not support!");
  216. return "";
  217. #endif
  218. }
  219. /**
  220. *@brief methods for reflections
  221. *@param function name
  222. *@param AnySDKParam* param
  223. *@return void
  224. */
  225. public void callFuncWithParam(string functionName, AnySDKParam param)
  226. {
  227. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  228. List<AnySDKParam> list = new List<AnySDKParam> ();
  229. list.Add (param);
  230. AnySDKAds_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  231. #else
  232. Debug.Log("This platform does not support!");
  233. #endif
  234. }
  235. /**
  236. *@brief methods for reflections
  237. *@param function name
  238. *@param List<AnySDKParam> params
  239. *@return void
  240. */
  241. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  242. {
  243. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  244. if (param == null)
  245. {
  246. AnySDKAds_nativeCallFuncWithParam (functionName, null, 0);
  247. } else {
  248. AnySDKAds_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  249. }
  250. #else
  251. Debug.Log("This platform does not support!");
  252. #endif
  253. }
  254. /**
  255. *@brief methods for reflections
  256. *@param function name
  257. *@param AnySDKParam param
  258. *@return int
  259. */
  260. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  261. {
  262. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  263. List<AnySDKParam> list = new List<AnySDKParam> ();
  264. list.Add (param);
  265. return AnySDKAds_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  266. #else
  267. Debug.Log("This platform does not support!");
  268. return -1;
  269. #endif
  270. }
  271. /**
  272. *@brief methods for reflections
  273. *@param function name
  274. *@param List<AnySDKParam> param
  275. *@return int
  276. */
  277. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  278. {
  279. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  280. if (param == null)
  281. {
  282. return AnySDKAds_nativeCallIntFuncWithParam (functionName, null, 0);
  283. } else {
  284. return AnySDKAds_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  285. }
  286. #else
  287. Debug.Log("This platform does not support!");
  288. return -1;
  289. #endif
  290. }
  291. /**
  292. *@brief methods for reflections
  293. *@param function name
  294. *@param AnySDKParam param
  295. *@return float
  296. */
  297. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  298. {
  299. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  300. List<AnySDKParam> list = new List<AnySDKParam> ();
  301. list.Add (param);
  302. return AnySDKAds_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  303. #else
  304. Debug.Log("This platform does not support!");
  305. return 0;
  306. #endif
  307. }
  308. /**
  309. *@brief methods for reflections
  310. *@param function name
  311. *@param List<AnySDKParam> param
  312. *@return float
  313. */
  314. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  315. {
  316. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  317. if (param == null)
  318. {
  319. return AnySDKAds_nativeCallFloatFuncWithParam (functionName, null, 0);
  320. } else {
  321. return AnySDKAds_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  322. }
  323. #else
  324. Debug.Log("This platform does not support!");
  325. return 0;
  326. #endif
  327. }
  328. /**
  329. *@brief methods for reflections
  330. *@param function name
  331. *@param AnySDKParam param
  332. *@return bool
  333. */
  334. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  335. {
  336. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  337. List<AnySDKParam> list = new List<AnySDKParam> ();
  338. list.Add (param);
  339. return AnySDKAds_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  340. #else
  341. Debug.Log("This platform does not support!");
  342. return false;
  343. #endif
  344. }
  345. /**
  346. *@brief methods for reflections
  347. *@param function name
  348. *@param List<AnySDKParam> param
  349. *@return bool
  350. */
  351. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  352. {
  353. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  354. if (param == null)
  355. {
  356. return AnySDKAds_nativeCallBoolFuncWithParam (functionName, null, 0);
  357. } else {
  358. return AnySDKAds_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  359. }
  360. #else
  361. Debug.Log("This platform does not support!");
  362. return false;
  363. #endif
  364. }
  365. /**
  366. *@brief methods for reflections
  367. *@param function name
  368. *@param AnySDKParam param
  369. *@return string
  370. */
  371. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  372. {
  373. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  374. List<AnySDKParam> list = new List<AnySDKParam> ();
  375. list.Add (param);
  376. StringBuilder value = new StringBuilder();
  377. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  378. AnySDKAds_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  379. return value.ToString ();
  380. #else
  381. Debug.Log("This platform does not support!");
  382. return "";
  383. #endif
  384. }
  385. /**
  386. *@brief methods for reflections
  387. *@param function name
  388. *@param List<AnySDKParam> param
  389. *@return string
  390. */
  391. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  392. {
  393. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  394. StringBuilder value = new StringBuilder();
  395. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  396. if (param == null)
  397. {
  398. AnySDKAds_nativeCallStringFuncWithParam (functionName, null, 0,value);
  399. } else {
  400. AnySDKAds_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  401. }
  402. return value.ToString ();
  403. #else
  404. Debug.Log("This platform does not support!");
  405. return "";
  406. #endif
  407. }
  408. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  409. private static extern void AnySDKAds_RegisterExternalCallDelegate(IntPtr functionPointer);
  410. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  411. private static extern void AnySDKAds_nativeSetListener(string gameName, string functionName);
  412. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  413. private static extern void AnySDKAds_nativeShowAds(AdsType adsType, int idx = 1);
  414. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  415. private static extern void AnySDKAds_nativeHideAds(AdsType adsType, int idx = 1);
  416. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  417. private static extern void AnySDKAds_nativePreloadAds(AdsType adsType, int idx = 1);
  418. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  419. private static extern float AnySDKAds_nativeQueryPoints();
  420. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  421. private static extern void AnySDKAds_nativeSpendPoints(int points);
  422. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  423. private static extern bool AnySDKAds_nativeIsAdTypeSupported(AdsType adsType);
  424. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  425. private static extern bool AnySDKAds_nativeIsFunctionSupported(string functionName);
  426. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  427. private static extern void AnySDKAds_nativeSetDebugMode(bool bDebug);
  428. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  429. private static extern void AnySDKAds_nativeGetPluginVersion(StringBuilder version);
  430. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  431. private static extern void AnySDKAds_nativeGetSDKVersion(StringBuilder version);
  432. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  433. private static extern void AnySDKAds_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  434. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  435. private static extern int AnySDKAds_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  436. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  437. private static extern float AnySDKAds_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  438. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  439. private static extern bool AnySDKAds_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  440. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  441. private static extern void AnySDKAds_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  442. }
  443. }