AnySDKREC.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 RECResultCode
  9. {
  10. kRECInitSuccess = 0,/**< enum value is callback of succeeding in initing sdk . */
  11. kRECInitFail,/**< enum value is callback of failing to init sdk. */
  12. kRECStartRecording,/**< enum value is callback of starting to record. */
  13. kRECStopRecording,/**< enum value is callback of stoping to record. */
  14. kRECPauseRecording,/**< enum value is callback of pausing to record. */
  15. kRECResumeRecording,/**< enum value is callback of resuming to record. */
  16. kRECEnterSDKPage,/**< enum value is callback of failing to init sdk. */
  17. kRECQuitSDKPage,/**< enum value is callback of entering SDK`s page. */
  18. kRECShareSuccess,/**< enum value is callback of quiting SDK`s page. */
  19. kRECShareFail,/**< enum value is callback of failing to share. */
  20. kRECExtension = 90000 /**< enum value is extension code . */
  21. };
  22. public class AnySDKREC
  23. {
  24. private static AnySDKREC _instance;
  25. public static AnySDKREC getInstance() {
  26. if( null == _instance ) {
  27. _instance = new AnySDKREC();
  28. }
  29. return _instance;
  30. }
  31. /**
  32. @brief Start to record
  33. */
  34. public void startRecording()
  35. {
  36. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  37. AnySDKREC_nativeStartRecording ();
  38. #else
  39. Debug.Log("This platform does not support!");
  40. #endif
  41. }
  42. /**
  43. @brief Stop a session.
  44. @warning This interface only worked on android
  45. */
  46. public void stopRecording()
  47. {
  48. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  49. AnySDKREC_nativeStopRecording ();
  50. #else
  51. Debug.Log("This platform does not support!");
  52. #endif
  53. }
  54. /**
  55. @brief share video
  56. @param info The info of share, contains key:
  57. @warning Look at the manual of plugins.
  58. */
  59. public void share(Dictionary<string,string> shareInfo)
  60. {
  61. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  62. string info = AnySDKUtil.dictionaryToString (shareInfo);
  63. Debug.Log("share " + info);
  64. AnySDKREC_nativeShare (info );
  65. #else
  66. Debug.Log("This platform does not support!");
  67. #endif
  68. }
  69. /**
  70. @brief Check function the plugin support or not
  71. */
  72. public bool isFunctionSupported (string functionName)
  73. {
  74. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  75. return AnySDKREC_nativeIsFunctionSupported (functionName);
  76. #else
  77. Debug.Log("This platform does not support!");
  78. return false;
  79. #endif
  80. }
  81. /**
  82. * set debugmode for plugin
  83. *
  84. */
  85. [Obsolete("This interface is obsolete!",false)]
  86. public void setDebugMode(bool bDebug)
  87. {
  88. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  89. AnySDKREC_nativeSetDebugMode (bDebug);
  90. #else
  91. Debug.Log("This platform does not support!");
  92. #endif
  93. }
  94. /**
  95. @brief set pListener The callback object for share result
  96. @param the MonoBehaviour object
  97. @param the callback of function
  98. */
  99. public void setListener(MonoBehaviour gameObject,string functionName)
  100. {
  101. #if !UNITY_EDITOR && UNITY_ANDROID
  102. AnySDKUtil.registerActionCallback (AnySDKType.REC, gameObject, functionName);
  103. #elif !UNITY_EDITOR && UNITY_IOS
  104. string gameObjectName = gameObject.gameObject.name;
  105. AnySDKREC_nativeSetListener(gameObjectName,functionName);
  106. #else
  107. Debug.Log("This platform does not support!");
  108. #endif
  109. }
  110. /**
  111. * Get Plugin version
  112. *
  113. * @return string
  114. */
  115. public string getPluginVersion()
  116. {
  117. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  118. StringBuilder version = new StringBuilder();
  119. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  120. AnySDKREC_nativeGetPluginVersion (version);
  121. return version.ToString();
  122. #else
  123. Debug.Log("This platform does not support!");
  124. return "";
  125. #endif
  126. }
  127. /**
  128. * Get SDK version
  129. *
  130. * @return string
  131. */
  132. public string getSDKVersion()
  133. {
  134. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  135. StringBuilder version = new StringBuilder();
  136. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  137. AnySDKREC_nativeGetSDKVersion (version);
  138. return version.ToString();
  139. #else
  140. Debug.Log("This platform does not support!");
  141. return "";
  142. #endif
  143. }
  144. /**
  145. *@brief methods for reflections
  146. *@param function name
  147. *@param AnySDKParam param
  148. *@return void
  149. */
  150. public void callFuncWithParam(string functionName, AnySDKParam param)
  151. {
  152. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  153. List<AnySDKParam> list = new List<AnySDKParam> ();
  154. list.Add (param);
  155. AnySDKREC_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  156. #else
  157. Debug.Log("This platform does not support!");
  158. #endif
  159. }
  160. /**
  161. *@brief methods for reflections
  162. *@param function name
  163. *@param List<AnySDKParam param
  164. *@return void
  165. */
  166. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  167. {
  168. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  169. if (param == null)
  170. {
  171. AnySDKREC_nativeCallFuncWithParam (functionName, null, 0);
  172. } else {
  173. AnySDKREC_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  174. }
  175. #else
  176. Debug.Log("This platform does not support!");
  177. #endif
  178. }
  179. /**
  180. *@brief methods for reflections
  181. *@param function name
  182. *@param AnySDKParam param
  183. *@return int
  184. */
  185. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  186. {
  187. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  188. List<AnySDKParam> list = new List<AnySDKParam> ();
  189. list.Add (param);
  190. return AnySDKREC_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  191. #else
  192. Debug.Log("This platform does not support!");
  193. return -1;
  194. #endif
  195. }
  196. /**
  197. *@brief methods for reflections
  198. *@param function name
  199. *@param List<AnySDKParam param
  200. *@return int
  201. */
  202. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  203. {
  204. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  205. if (param == null)
  206. {
  207. return AnySDKREC_nativeCallIntFuncWithParam (functionName, null, 0);
  208. } else {
  209. return AnySDKREC_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  210. }
  211. #else
  212. Debug.Log("This platform does not support!");
  213. return -1;
  214. #endif
  215. }
  216. /**
  217. *@brief methods for reflections
  218. *@param function name
  219. *@param AnySDKParam param
  220. *@return float
  221. */
  222. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  223. {
  224. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  225. List<AnySDKParam> list = new List<AnySDKParam> ();
  226. list.Add (param);
  227. return AnySDKREC_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  228. #else
  229. Debug.Log("This platform does not support!");
  230. return 0;
  231. #endif
  232. }
  233. /**
  234. *@brief methods for reflections
  235. *@param function name
  236. *@param List<AnySDKParam param
  237. *@return float
  238. */
  239. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  240. {
  241. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  242. if (param == null)
  243. {
  244. return AnySDKREC_nativeCallFloatFuncWithParam (functionName, null, 0);
  245. } else {
  246. return AnySDKREC_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  247. }
  248. #else
  249. Debug.Log("This platform does not support!");
  250. return 0;
  251. #endif
  252. }
  253. /**
  254. *@brief methods for reflections
  255. *@param function name
  256. *@param AnySDKParam param
  257. *@return bool
  258. */
  259. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  260. {
  261. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  262. List<AnySDKParam> list = new List<AnySDKParam> ();
  263. list.Add (param);
  264. return AnySDKREC_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  265. #else
  266. Debug.Log("This platform does not support!");
  267. return false;
  268. #endif
  269. }
  270. /**
  271. *@brief methods for reflections
  272. *@param function name
  273. *@param List<AnySDKParam param
  274. *@return bool
  275. */
  276. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  277. {
  278. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  279. if (param == null)
  280. {
  281. return AnySDKREC_nativeCallBoolFuncWithParam (functionName, null, 0);
  282. } else {
  283. return AnySDKREC_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  284. }
  285. #else
  286. Debug.Log("This platform does not support!");
  287. return false;
  288. #endif
  289. }
  290. /**
  291. *@brief methods for reflections
  292. *@param function name
  293. *@param AnySDKParam param
  294. *@return string
  295. */
  296. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  297. {
  298. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  299. List<AnySDKParam> list = new List<AnySDKParam> ();
  300. list.Add (param);
  301. StringBuilder value = new StringBuilder();
  302. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  303. AnySDKREC_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  304. return value.ToString ();
  305. #else
  306. Debug.Log("This platform does not support!");
  307. return "";
  308. #endif
  309. }
  310. /**
  311. *@brief methods for reflections
  312. *@param function name
  313. *@param List<AnySDKParam param
  314. *@return string
  315. */
  316. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  317. {
  318. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  319. StringBuilder value = new StringBuilder();
  320. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  321. if (param == null)
  322. {
  323. AnySDKREC_nativeCallStringFuncWithParam (functionName, null, 0,value);
  324. } else {
  325. AnySDKREC_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  326. }
  327. return value.ToString ();
  328. #else
  329. Debug.Log("This platform does not support!");
  330. return "";
  331. #endif
  332. }
  333. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  334. private static extern void AnySDKREC_RegisterExternalCallDelegate(IntPtr functionPointer);
  335. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  336. private static extern void AnySDKREC_nativeStartRecording();
  337. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  338. private static extern void AnySDKREC_nativeStopRecording();
  339. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  340. private static extern void AnySDKREC_nativeShare(string info);
  341. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  342. private static extern void AnySDKREC_nativeSetListener(string gameName, string functionName);
  343. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  344. private static extern bool AnySDKREC_nativeIsFunctionSupported(string functionName);
  345. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  346. private static extern void AnySDKREC_nativeSetDebugMode(bool bDebug);
  347. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  348. private static extern void AnySDKREC_nativeGetPluginVersion(StringBuilder version);
  349. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  350. private static extern void AnySDKREC_nativeGetSDKVersion(StringBuilder version);
  351. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  352. private static extern void AnySDKREC_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  353. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  354. private static extern int AnySDKREC_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  355. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  356. private static extern float AnySDKREC_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  357. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  358. private static extern bool AnySDKREC_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  359. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  360. private static extern void AnySDKREC_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  361. }
  362. }