AnySDKCustom.cs 9.8 KB

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