示例#1
0
                    // instance constructor
                    public static void createInstance()
                    {
                        // create just one static instance for ever!
                        if (staticInstance == null)
                        {
                            GameObject obj = new GameObject();
                            staticInstance      = obj.AddComponent <SAInterstitialAd> ();
                            staticInstance.name = "SAInterstitialAd";
                            DontDestroyOnLoad(staticInstance);

                            //
                            // set native version
                            SAVersion.setVersionInNative();

#if (UNITY_IPHONE && !UNITY_EDITOR)
                            SAInterstitialAd.SuperAwesomeUnitySAInterstitialAdCreate();
#elif (UNITY_ANDROID && !UNITY_EDITOR)
                            var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                            var context    = unityClass.GetStatic <AndroidJavaObject> ("currentActivity");

                            context.Call("runOnUiThread", new AndroidJavaRunnable(() => {
                                var saplugin = new AndroidJavaClass("tv.superawesome.plugins.publisher.unity.SAUnityInterstitialAd");
                                saplugin.CallStatic("SuperAwesomeUnitySAInterstitialAdCreate", context);
                            }));
#else
                            Debug.Log("SAInterstitialAd Create");
#endif
                        }
                    }
                    // create method
                    public static SABannerAd createInstance()
                    {
                        GameObject obj   = new GameObject();
                        SABannerAd adObj = obj.AddComponent <SABannerAd> ();

                        adObj.name = "SABannerAd_" + (++SABannerAd.index);
                        DontDestroyOnLoad(obj);

                        //
                        // set native version
                        SAVersion.setVersionInNative();

#if (UNITY_IPHONE && !UNITY_EDITOR)
                        SABannerAd.SuperAwesomeUnitySABannerAdCreate(adObj.name);
#elif (UNITY_ANDROID && !UNITY_EDITOR)
                        var nameL = adObj.name;

                        var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                        var context    = unityClass.GetStatic <AndroidJavaObject> ("currentActivity");

                        context.Call("runOnUiThread", new AndroidJavaRunnable(() => {
                            var saplugin = new AndroidJavaClass("tv.superawesome.plugins.publisher.unity.SAUnityBannerAd");
                            saplugin.CallStatic("SuperAwesomeUnitySABannerAdCreate", context, nameL);
                        }));
#else
                        Debug.Log(adObj.name + " Create");
#endif

                        return(adObj);
                    }