AnySDKAds.cs 29 KB

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