AnySDKSocial.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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 SocialRetCode
  9. {
  10. // code for leaderboard feature
  11. kScoreSubmitSucceed =1,/**< enum value is callback of succeeding in submiting. */
  12. kScoreSubmitfail,/**< enum value is callback of failing to submit . */
  13. // code for achievement feature
  14. kAchUnlockSucceed,/**< enum value is callback of succeeding in unlocking. */
  15. kAchUnlockFail,/**< enum value is callback of failing to unlock. */
  16. kSocialSignInSucceed,/**< enum value is callback of succeeding to login. */
  17. kSocialSignInFail,/**< enum value is callback of failing to login. */
  18. kSocialSignOutSucceed,/**< enum value is callback of succeeding to login. */
  19. kSocialSignOutFail,/**< enum value is callback of failing to login. */
  20. kSocialGetGameFriends,/**< enum value is callback of getGameFriends. */
  21. kSocialExtensionCode = 20000 /**< enum value is extension code . */
  22. } ;
  23. public class AnySDKSocial
  24. {
  25. private static AnySDKSocial _instance;
  26. public static AnySDKSocial getInstance() {
  27. if( null == _instance ) {
  28. _instance = new AnySDKSocial();
  29. }
  30. return _instance;
  31. }
  32. /**
  33. @brief user signIn
  34. */
  35. public void signIn()
  36. {
  37. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  38. AnySDKSocial_nativeSignIn ();
  39. #else
  40. Debug.Log("This platform does not support!");
  41. #endif
  42. }
  43. /**
  44. @brief user signOut
  45. */
  46. public void signOut()
  47. {
  48. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  49. AnySDKSocial_nativeSignOut ();
  50. #else
  51. Debug.Log("This platform does not support!");
  52. #endif
  53. }
  54. /**
  55. @brief submit the score
  56. @param leaderboardID
  57. @param the score
  58. */
  59. public void submitScore(string leadboardID, long score)
  60. {
  61. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  62. AnySDKSocial_nativeSubmitScore (leadboardID, score);
  63. #else
  64. Debug.Log("This platform does not support!");
  65. #endif
  66. }
  67. /**
  68. @brief show the id of Leaderboard page
  69. @param leaderboardID
  70. */
  71. public void showLeaderboard(string leadboardID)
  72. {
  73. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  74. AnySDKSocial_nativeShowLeaderboard (leadboardID);
  75. #else
  76. Debug.Log("This platform does not support!");
  77. #endif
  78. }
  79. /**
  80. @brief methods of achievement feature
  81. @param the info of achievement
  82. */
  83. public void unlockAchievement (Dictionary<string,string> achInfo)
  84. {
  85. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  86. string info = AnySDKUtil.dictionaryToString (achInfo);
  87. AnySDKSocial_nativeUnlockAchievement (info);
  88. #else
  89. Debug.Log("This platform does not support!");
  90. #endif
  91. }
  92. /**
  93. @brief show the page of achievements
  94. */
  95. public void showAchievements ()
  96. {
  97. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  98. AnySDKSocial_nativeShowAchievements ();
  99. #else
  100. Debug.Log("This platform does not support!");
  101. #endif
  102. }
  103. /**
  104. * set debugmode for plugin
  105. *
  106. */
  107. [Obsolete("This interface is obsolete!",false)]
  108. public void setDebugMode(bool bDebug)
  109. {
  110. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  111. AnySDKSocial_nativeSetDebugMode (bDebug);
  112. #else
  113. Debug.Log("This platform does not support!");
  114. #endif
  115. }
  116. /**
  117. @brief set pListener The callback object for social result
  118. @param the MonoBehaviour object
  119. @param the callback of function
  120. */
  121. public void setListener(MonoBehaviour gameObject,string functionName)
  122. {
  123. #if !UNITY_EDITOR && UNITY_ANDROID
  124. AnySDKUtil.registerActionCallback (AnySDKType.Social, gameObject, functionName);
  125. #elif !UNITY_EDITOR && UNITY_IOS
  126. string gameObjectName = gameObject.gameObject.name;
  127. AnySDKSocial_nativeSetListener(gameObjectName,functionName);
  128. #else
  129. Debug.Log("This platform does not support!");
  130. #endif
  131. }
  132. /**
  133. @brief Check function the plugin support or not
  134. */
  135. public bool isFunctionSupported (string functionName)
  136. {
  137. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  138. return AnySDKSocial_nativeIsFunctionSupported (functionName);
  139. #else
  140. Debug.Log("This platform does not support!");
  141. return false;
  142. #endif
  143. }
  144. /**
  145. * Get Plugin version
  146. *
  147. * @return string
  148. */
  149. public string getPluginVersion()
  150. {
  151. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  152. StringBuilder version = new StringBuilder();
  153. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  154. AnySDKSocial_nativeGetPluginVersion (version);
  155. return version.ToString();
  156. #else
  157. Debug.Log("This platform does not support!");
  158. return "";
  159. #endif
  160. }
  161. /**
  162. * Get Plugin version
  163. *
  164. * @return string
  165. */
  166. public string getSDKVersion()
  167. {
  168. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  169. StringBuilder version = new StringBuilder();
  170. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  171. AnySDKSocial_nativeGetSDKVersion (version);
  172. return version.ToString();
  173. #else
  174. Debug.Log("This platform does not support!");
  175. return "";
  176. #endif
  177. }
  178. /**
  179. *@brief methods for reflections
  180. *@param function name
  181. *@param AnySDKParam param
  182. *@return void
  183. */
  184. public void callFuncWithParam(string functionName, AnySDKParam param)
  185. {
  186. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  187. List<AnySDKParam> list = new List<AnySDKParam> ();
  188. list.Add (param);
  189. AnySDKSocial_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  190. #else
  191. Debug.Log("This platform does not support!");
  192. #endif
  193. }
  194. /**
  195. *@brief methods for reflections
  196. *@param function name
  197. *@param List<AnySDKParam> param
  198. *@return void
  199. */
  200. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  201. {
  202. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  203. if (param == null)
  204. {
  205. AnySDKSocial_nativeCallFuncWithParam (functionName, null, 0);
  206. } else {
  207. AnySDKSocial_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  208. }
  209. #else
  210. Debug.Log("This platform does not support!");
  211. #endif
  212. }
  213. /**
  214. *@brief methods for reflections
  215. *@param function name
  216. *@param AnySDKParam param
  217. *@return int
  218. */
  219. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  220. {
  221. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  222. List<AnySDKParam> list = new List<AnySDKParam> ();
  223. list.Add (param);
  224. return AnySDKSocial_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  225. #else
  226. Debug.Log("This platform does not support!");
  227. return -1;
  228. #endif
  229. }
  230. /**
  231. *@brief methods for reflections
  232. *@param function name
  233. *@param List<AnySDKParam> param
  234. *@return int
  235. */
  236. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  237. {
  238. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  239. if (param == null)
  240. {
  241. return AnySDKSocial_nativeCallIntFuncWithParam (functionName, null, 0);
  242. } else {
  243. return AnySDKSocial_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  244. }
  245. #else
  246. Debug.Log("This platform does not support!");
  247. return -1;
  248. #endif
  249. }
  250. /**
  251. *@brief methods for reflections
  252. *@param function name
  253. *@param AnySDKParam param
  254. *@return float
  255. */
  256. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  257. {
  258. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  259. List<AnySDKParam> list = new List<AnySDKParam> ();
  260. list.Add (param);
  261. return AnySDKSocial_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  262. #else
  263. Debug.Log("This platform does not support!");
  264. return 0;
  265. #endif
  266. }
  267. /**
  268. *@brief methods for reflections
  269. *@param function name
  270. *@param List<AnySDKParam> param
  271. *@return float
  272. */
  273. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  274. {
  275. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  276. if (param == null)
  277. {
  278. return AnySDKSocial_nativeCallFloatFuncWithParam (functionName, null, 0);
  279. } else {
  280. return AnySDKSocial_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  281. }
  282. #else
  283. Debug.Log("This platform does not support!");
  284. return 0;
  285. #endif
  286. }
  287. /**
  288. *@brief methods for reflections
  289. *@param function name
  290. *@param AnySDKParam param
  291. *@return bool
  292. */
  293. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  294. {
  295. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  296. List<AnySDKParam> list = new List<AnySDKParam> ();
  297. list.Add (param);
  298. return AnySDKSocial_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  299. #else
  300. Debug.Log("This platform does not support!");
  301. return false;
  302. #endif
  303. }
  304. /**
  305. *@brief methods for reflections
  306. *@param function name
  307. *@param List<AnySDKParam> param
  308. *@return bool
  309. */
  310. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  311. {
  312. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  313. if (param == null)
  314. {
  315. return AnySDKSocial_nativeCallBoolFuncWithParam (functionName, null, 0);
  316. } else {
  317. return AnySDKSocial_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  318. }
  319. #else
  320. Debug.Log("This platform does not support!");
  321. return false;
  322. #endif
  323. }
  324. /**
  325. *@brief methods for reflections
  326. *@param function name
  327. *@param AnySDKParam param
  328. *@return string
  329. */
  330. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  331. {
  332. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  333. List<AnySDKParam> list = new List<AnySDKParam> ();
  334. list.Add (param);
  335. StringBuilder value = new StringBuilder();
  336. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  337. AnySDKSocial_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  338. return value.ToString ();
  339. #else
  340. Debug.Log("This platform does not support!");
  341. return "";
  342. #endif
  343. }
  344. /**
  345. *@brief methods for reflections
  346. *@param function name
  347. *@param List<AnySDKParam> param
  348. *@return string
  349. */
  350. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  351. {
  352. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  353. StringBuilder value = new StringBuilder();
  354. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  355. if (param == null)
  356. {
  357. AnySDKSocial_nativeCallStringFuncWithParam (functionName, null, 0,value);
  358. } else {
  359. AnySDKSocial_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  360. }
  361. return value.ToString ();
  362. #else
  363. Debug.Log("This platform does not support!");
  364. return "";
  365. #endif
  366. }
  367. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  368. private static extern void AnySDKSocial_RegisterExternalCallDelegate(IntPtr functionPointer);
  369. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  370. private static extern void AnySDKSocial_nativeSetListener(string gameName, string functionName);
  371. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  372. private static extern void AnySDKSocial_nativeSignIn();
  373. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  374. private static extern void AnySDKSocial_nativeSignOut();
  375. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  376. private static extern void AnySDKSocial_nativeShowLeaderboard(string leadboardID);
  377. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  378. private static extern bool AnySDKSocial_nativeSubmitScore(string leadboardID, long score);
  379. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  380. private static extern bool AnySDKSocial_nativeUnlockAchievement(string info);
  381. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  382. private static extern bool AnySDKSocial_nativeShowAchievements();
  383. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  384. private static extern bool AnySDKSocial_nativeIsFunctionSupported(string functionName);
  385. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  386. private static extern void AnySDKSocial_nativeSetDebugMode(bool bDebug);
  387. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  388. private static extern void AnySDKSocial_nativeGetPluginVersion(StringBuilder version);
  389. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  390. private static extern void AnySDKSocial_nativeGetSDKVersion(StringBuilder version);
  391. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  392. private static extern void AnySDKSocial_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  393. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  394. private static extern int AnySDKSocial_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  395. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  396. private static extern float AnySDKSocial_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  397. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  398. private static extern bool AnySDKSocial_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  399. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  400. private static extern void AnySDKSocial_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  401. }
  402. }