AnySDKShare.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 ShareResultCode
  9. {
  10. kShareSuccess = 0,/**< enum value is callback of failing to sharing . */
  11. kShareFail,/**< enum value is callback of failing to share . */
  12. kShareCancel,/**< enum value is callback of canceling to share . */
  13. kShareNetworkError,/**< enum value is callback of network error . */
  14. kShareExtension = 10000 /**< enum value is extension code . */
  15. };
  16. public class AnySDKShare
  17. {
  18. private static AnySDKShare _instance;
  19. public static AnySDKShare getInstance() {
  20. if( null == _instance ) {
  21. _instance = new AnySDKShare();
  22. }
  23. return _instance;
  24. }
  25. /**
  26. @brief share information
  27. @param info The info of share, contains key:
  28. @warning Look at the manual of plugins.
  29. */
  30. public void share(Dictionary<string,string> shareInfo)
  31. {
  32. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  33. string info = AnySDKUtil.dictionaryToString (shareInfo);
  34. Debug.Log("share " + info);
  35. AnySDKShare_nativeShare (info );
  36. #else
  37. Debug.Log("This platform does not support!");
  38. #endif
  39. }
  40. /**
  41. @brief Check function the plugin support or not
  42. */
  43. public bool isFunctionSupported (string functionName)
  44. {
  45. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  46. return AnySDKShare_nativeIsFunctionSupported (functionName);
  47. #else
  48. Debug.Log("This platform does not support!");
  49. return false;
  50. #endif
  51. }
  52. /**
  53. * set debugmode for plugin
  54. *
  55. */
  56. [Obsolete("This interface is obsolete!",false)]
  57. public void setDebugMode(bool bDebug)
  58. {
  59. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  60. AnySDKShare_nativeSetDebugMode (bDebug);
  61. #else
  62. Debug.Log("This platform does not support!");
  63. #endif
  64. }
  65. /**
  66. @brief set pListener The callback object for share result
  67. @param the MonoBehaviour object
  68. @param the callback of function
  69. */
  70. public void setListener(MonoBehaviour gameObject,string functionName)
  71. {
  72. #if !UNITY_EDITOR && UNITY_ANDROID
  73. AnySDKUtil.registerActionCallback (AnySDKType.Share, gameObject, functionName);
  74. #elif !UNITY_EDITOR && UNITY_IOS
  75. string gameObjectName = gameObject.gameObject.name;
  76. AnySDKShare_nativeSetListener(gameObjectName,functionName);
  77. #else
  78. Debug.Log("This platform does not support!");
  79. #endif
  80. }
  81. /**
  82. * Get Plugin version
  83. *
  84. * @return string
  85. */
  86. public string getPluginVersion()
  87. {
  88. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  89. StringBuilder version = new StringBuilder();
  90. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  91. AnySDKShare_nativeGetPluginVersion (version);
  92. return version.ToString();
  93. #else
  94. Debug.Log("This platform does not support!");
  95. return "";
  96. #endif
  97. }
  98. /**
  99. * Get SDK version
  100. *
  101. * @return string
  102. */
  103. public string getSDKVersion()
  104. {
  105. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  106. StringBuilder version = new StringBuilder();
  107. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  108. AnySDKShare_nativeGetSDKVersion (version);
  109. return version.ToString();
  110. #else
  111. Debug.Log("This platform does not support!");
  112. return "";
  113. #endif
  114. }
  115. /**
  116. *@brief methods for reflections
  117. *@param function name
  118. *@param AnySDKParam param
  119. *@return void
  120. */
  121. public void callFuncWithParam(string functionName, AnySDKParam param)
  122. {
  123. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  124. List<AnySDKParam> list = new List<AnySDKParam> ();
  125. list.Add (param);
  126. AnySDKShare_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  127. #else
  128. Debug.Log("This platform does not support!");
  129. #endif
  130. }
  131. /**
  132. *@brief methods for reflections
  133. *@param function name
  134. *@param List<AnySDKParam param
  135. *@return void
  136. */
  137. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  138. {
  139. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  140. if (param == null)
  141. {
  142. AnySDKShare_nativeCallFuncWithParam (functionName, null, 0);
  143. } else {
  144. AnySDKShare_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  145. }
  146. #else
  147. Debug.Log("This platform does not support!");
  148. #endif
  149. }
  150. /**
  151. *@brief methods for reflections
  152. *@param function name
  153. *@param AnySDKParam param
  154. *@return int
  155. */
  156. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  157. {
  158. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  159. List<AnySDKParam> list = new List<AnySDKParam> ();
  160. list.Add (param);
  161. return AnySDKShare_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  162. #else
  163. Debug.Log("This platform does not support!");
  164. return -1;
  165. #endif
  166. }
  167. /**
  168. *@brief methods for reflections
  169. *@param function name
  170. *@param List<AnySDKParam param
  171. *@return int
  172. */
  173. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  174. {
  175. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  176. if (param == null)
  177. {
  178. return AnySDKShare_nativeCallIntFuncWithParam (functionName, null, 0);
  179. } else {
  180. return AnySDKShare_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  181. }
  182. #else
  183. Debug.Log("This platform does not support!");
  184. return -1;
  185. #endif
  186. }
  187. /**
  188. *@brief methods for reflections
  189. *@param function name
  190. *@param AnySDKParam param
  191. *@return float
  192. */
  193. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  194. {
  195. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  196. List<AnySDKParam> list = new List<AnySDKParam> ();
  197. list.Add (param);
  198. return AnySDKShare_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  199. #else
  200. Debug.Log("This platform does not support!");
  201. return 0;
  202. #endif
  203. }
  204. /**
  205. *@brief methods for reflections
  206. *@param function name
  207. *@param List<AnySDKParam param
  208. *@return float
  209. */
  210. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  211. {
  212. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  213. if (param == null)
  214. {
  215. return AnySDKShare_nativeCallFloatFuncWithParam (functionName, null, 0);
  216. } else {
  217. return AnySDKShare_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  218. }
  219. #else
  220. Debug.Log("This platform does not support!");
  221. return 0;
  222. #endif
  223. }
  224. /**
  225. *@brief methods for reflections
  226. *@param function name
  227. *@param AnySDKParam param
  228. *@return bool
  229. */
  230. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  231. {
  232. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  233. List<AnySDKParam> list = new List<AnySDKParam> ();
  234. list.Add (param);
  235. return AnySDKShare_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  236. #else
  237. Debug.Log("This platform does not support!");
  238. return false;
  239. #endif
  240. }
  241. /**
  242. *@brief methods for reflections
  243. *@param function name
  244. *@param List<AnySDKParam param
  245. *@return bool
  246. */
  247. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  248. {
  249. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  250. if (param == null)
  251. {
  252. return AnySDKShare_nativeCallBoolFuncWithParam (functionName, null, 0);
  253. } else {
  254. return AnySDKShare_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  255. }
  256. #else
  257. Debug.Log("This platform does not support!");
  258. return false;
  259. #endif
  260. }
  261. /**
  262. *@brief methods for reflections
  263. *@param function name
  264. *@param AnySDKParam param
  265. *@return string
  266. */
  267. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  268. {
  269. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  270. List<AnySDKParam> list = new List<AnySDKParam> ();
  271. list.Add (param);
  272. StringBuilder value = new StringBuilder();
  273. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  274. AnySDKShare_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  275. return value.ToString ();
  276. #else
  277. Debug.Log("This platform does not support!");
  278. return "";
  279. #endif
  280. }
  281. /**
  282. *@brief methods for reflections
  283. *@param function name
  284. *@param List<AnySDKParam param
  285. *@return string
  286. */
  287. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  288. {
  289. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  290. StringBuilder value = new StringBuilder();
  291. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  292. if (param == null)
  293. {
  294. AnySDKShare_nativeCallStringFuncWithParam (functionName, null, 0,value);
  295. } else {
  296. AnySDKShare_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  297. }
  298. return value.ToString ();
  299. #else
  300. Debug.Log("This platform does not support!");
  301. return "";
  302. #endif
  303. }
  304. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  305. private static extern void AnySDKShare_RegisterExternalCallDelegate(IntPtr functionPointer);
  306. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  307. private static extern void AnySDKShare_nativeSetListener(string gameName, string functionName);
  308. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  309. private static extern void AnySDKShare_nativeShare(string info);
  310. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  311. private static extern bool AnySDKShare_nativeIsFunctionSupported(string functionName);
  312. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  313. private static extern void AnySDKShare_nativeSetDebugMode(bool bDebug);
  314. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  315. private static extern void AnySDKShare_nativeGetPluginVersion(StringBuilder version);
  316. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  317. private static extern void AnySDKShare_nativeGetSDKVersion(StringBuilder version);
  318. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  319. private static extern void AnySDKShare_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  320. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  321. private static extern int AnySDKShare_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  322. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  323. private static extern float AnySDKShare_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  324. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  325. private static extern bool AnySDKShare_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  326. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  327. private static extern void AnySDKShare_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  328. }
  329. }