예제 #1
0
        // -------------------------------------------------------------------------------------------------------------------------
        // Unity <> Android Magic


        /// <summary> Generic function to call any function with various inputs / return values. </summary>
        /// <param name="funcName"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static bool CallFunctionGet <T>(string funcName, out T res, object[] parameters = null)
        {
            //#if !UNITY_EDITOR && UNITY_ANDROID
            if (SG_IAndroid.instance.senseComClass != null)
            {
                if (parameters == null)
                {
                    parameters = new object[] { };
                }
                try
                {
                    Log("Attempting to call " + funcName);
                    res = instance.senseComClass.CallStatic <T>(funcName, parameters);
                    Log("Done calling " + funcName);
                    return(true);
                }
                catch (System.Exception ex)
                {
                    SG_IAndroid.Log(ex.Message + "\r\n\r\n" + ex.StackTrace);
                }
            }
            //#endif
            res = default(T);
            return(false);
        }
예제 #2
0
        //----------------------------------------------------------------------------------------------------
        // Initalization / Disposing of Android Resources.

        /// <summary> Initialized the Android Library is we haven't already </summary>
        /// <remarks> This function could be called every time we switch scenes, and thatshouldn't break things. </remarks>
        private static void Andr_TryInitialize()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (SGCore.Library.GetBackEndType() == SGCore.Library.BackEndType.AndroidStrings)
            {
                if (!classLinked)
                {
                    classLinked = SG_IAndroid.SetupLink();
                    if (classLinked)
                    {
                        Log("Android Bridge Succesful!");
                    }
                    else
                    {
                        Log("Could not link Android resources. SGConnect.aar might be missing or broken.");
                    }
                }
                if (classLinked && libraryInit != 1)                 //we've not yet initialized the Android library!
                {
                    libraryInit = SG_IAndroid.Andr_Init();
                    Log("Initialized Android Back-End with code " + libraryInit);
                    if (libraryInit == 1)
                    {
                        SGCore.Util.SGConnect_Android.An_Init();                         //let our C# back-end know we succeeded.
                    }
                }
            }
            else
            {
                Log("C# Library does not support Android back-end! It supports " + SGCore.Library.GetBackEndType().ToString());
            }
#endif
        }
예제 #3
0
        /// <summary> Links the Android Library to our Unity Process. Only works on Android builds, otherwise it throws an error. Once called, you should call Dispose when your process terminates. </summary>
        /// <returns></returns>
        public static bool SetupLink()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (instance.senseComClass == null)
            {
                try
                {
                    instance.senseComClass = new AndroidJavaClass(clientClassLocation);
                    return(true);
                }
                catch (System.Exception ex)
                {
                    SG_IAndroid.Log(ex.Message + "\r\n\r\n" + ex.StackTrace);
                }
            }
#endif
            return(false);
        }