123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Text;
- using System;
- namespace anysdk {
- public enum ShareResultCode
- {
- kShareSuccess = 0,/**< enum value is callback of failing to sharing . */
- kShareFail,/**< enum value is callback of failing to share . */
- kShareCancel,/**< enum value is callback of canceling to share . */
- kShareNetworkError,/**< enum value is callback of network error . */
- kShareExtension = 10000 /**< enum value is extension code . */
- };
- public class AnySDKShare
- {
- private static AnySDKShare _instance;
-
- public static AnySDKShare getInstance() {
- if( null == _instance ) {
- _instance = new AnySDKShare();
- }
- return _instance;
- }
- /**
- @brief share information
- @param info The info of share, contains key:
- @warning Look at the manual of plugins.
- */
- public void share(Dictionary<string,string> shareInfo)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- string info = AnySDKUtil.dictionaryToString (shareInfo);
- Debug.Log("share " + info);
- AnySDKShare_nativeShare (info );
- #else
- Debug.Log("This platform does not support!");
- #endif
- }
- /**
- @brief Check function the plugin support or not
- */
-
- public bool isFunctionSupported (string functionName)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- return AnySDKShare_nativeIsFunctionSupported (functionName);
- #else
- Debug.Log("This platform does not support!");
- return false;
- #endif
- }
- /**
- * set debugmode for plugin
- *
- */
- [Obsolete("This interface is obsolete!",false)]
- public void setDebugMode(bool bDebug)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- AnySDKShare_nativeSetDebugMode (bDebug);
- #else
- Debug.Log("This platform does not support!");
- #endif
- }
- /**
- @brief set pListener The callback object for share result
- @param the MonoBehaviour object
- @param the callback of function
- */
- public void setListener(MonoBehaviour gameObject,string functionName)
- {
- #if !UNITY_EDITOR && UNITY_ANDROID
- AnySDKUtil.registerActionCallback (AnySDKType.Share, gameObject, functionName);
- #elif !UNITY_EDITOR && UNITY_IOS
- string gameObjectName = gameObject.gameObject.name;
- AnySDKShare_nativeSetListener(gameObjectName,functionName);
- #else
- Debug.Log("This platform does not support!");
- #endif
- }
- /**
- * Get Plugin version
- *
- * @return string
- */
- public string getPluginVersion()
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- StringBuilder version = new StringBuilder();
- version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
- AnySDKShare_nativeGetPluginVersion (version);
- return version.ToString();
- #else
- Debug.Log("This platform does not support!");
- return "";
- #endif
- }
-
- /**
- * Get SDK version
- *
- * @return string
- */
- public string getSDKVersion()
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- StringBuilder version = new StringBuilder();
- version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
- AnySDKShare_nativeGetSDKVersion (version);
- return version.ToString();
- #else
- Debug.Log("This platform does not support!");
- return "";
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param AnySDKParam param
- *@return void
- */
-
- public void callFuncWithParam(string functionName, AnySDKParam param)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- List<AnySDKParam> list = new List<AnySDKParam> ();
- list.Add (param);
- AnySDKShare_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
- #else
- Debug.Log("This platform does not support!");
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param List<AnySDKParam param
- *@return void
- */
- public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- if (param == null)
- {
- AnySDKShare_nativeCallFuncWithParam (functionName, null, 0);
-
- } else {
- AnySDKShare_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
- }
- #else
- Debug.Log("This platform does not support!");
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param AnySDKParam param
- *@return int
- */
- public int callIntFuncWithParam(string functionName, AnySDKParam param)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- List<AnySDKParam> list = new List<AnySDKParam> ();
- list.Add (param);
- return AnySDKShare_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
- #else
- Debug.Log("This platform does not support!");
- return -1;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param List<AnySDKParam param
- *@return int
- */
- public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- if (param == null)
- {
- return AnySDKShare_nativeCallIntFuncWithParam (functionName, null, 0);
-
- } else {
- return AnySDKShare_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
- }
- #else
- Debug.Log("This platform does not support!");
- return -1;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param AnySDKParam param
- *@return float
- */
- public float callFloatFuncWithParam(string functionName, AnySDKParam param)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- List<AnySDKParam> list = new List<AnySDKParam> ();
- list.Add (param);
- return AnySDKShare_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
- #else
- Debug.Log("This platform does not support!");
- return 0;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param List<AnySDKParam param
- *@return float
- */
- public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- if (param == null)
- {
- return AnySDKShare_nativeCallFloatFuncWithParam (functionName, null, 0);
-
- } else {
- return AnySDKShare_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
- }
- #else
- Debug.Log("This platform does not support!");
- return 0;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param AnySDKParam param
- *@return bool
- */
- public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- List<AnySDKParam> list = new List<AnySDKParam> ();
- list.Add (param);
- return AnySDKShare_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
- #else
- Debug.Log("This platform does not support!");
- return false;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param List<AnySDKParam param
- *@return bool
- */
- public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- if (param == null)
- {
- return AnySDKShare_nativeCallBoolFuncWithParam (functionName, null, 0);
-
- } else {
- return AnySDKShare_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
- }
- #else
- Debug.Log("This platform does not support!");
- return false;
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param AnySDKParam param
- *@return string
- */
- public string callStringFuncWithParam(string functionName, AnySDKParam param)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- List<AnySDKParam> list = new List<AnySDKParam> ();
- list.Add (param);
- StringBuilder value = new StringBuilder();
- value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
- AnySDKShare_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
- return value.ToString ();
- #else
- Debug.Log("This platform does not support!");
- return "";
- #endif
- }
- /**
- *@brief methods for reflections
- *@param function name
- *@param List<AnySDKParam param
- *@return string
- */
- public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
- {
- #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
- StringBuilder value = new StringBuilder();
- value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
- if (param == null)
- {
- AnySDKShare_nativeCallStringFuncWithParam (functionName, null, 0,value);
-
- } else {
- AnySDKShare_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
- }
- return value.ToString ();
- #else
- Debug.Log("This platform does not support!");
- return "";
- #endif
- }
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
- private static extern void AnySDKShare_RegisterExternalCallDelegate(IntPtr functionPointer);
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeSetListener(string gameName, string functionName);
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeShare(string info);
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern bool AnySDKShare_nativeIsFunctionSupported(string functionName);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeSetDebugMode(bool bDebug);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeGetPluginVersion(StringBuilder version);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeGetSDKVersion(StringBuilder version);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern int AnySDKShare_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern float AnySDKShare_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern bool AnySDKShare_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
-
- [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
- private static extern void AnySDKShare_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
- }
-
- }
|