public override void Dispose()
 {
     if (NativePtr == IntPtr.Zero)
     {
         return;
     }
     InitializationListenerDestroy(NativePtr);
     NativePtr = IntPtr.Zero;
     m_UnityAdsInternalListener = null;
     m_UserListener             = null;
 }
Beispiel #2
0
        public void Initialize(string gameId, bool testMode, bool enablePerPlacementLoad, IUnityAdsInitializationListener initializationListener)
        {
            if (m_StartedInitialization)
            {
                return;
            }
            m_StartedInitialization = true;
            m_LoadEnabled           = enablePerPlacementLoad;
            m_GameId = gameId;
            if (m_Platform.DebugMode)
            {
                Debug.Log("UnityAdsEditor: Initialize(" + gameId + ", " + testMode + ", " + enablePerPlacementLoad + ");");
            }

#if ASSET_STORE
            Debug.LogWarning("Please consider upgrading to the Packman Distribution of the Unity Ads SDK.  The Asset Store distribution will not longer be supported after Unity 2018.3");
#endif

            var placeHolderGameObject = new GameObject("UnityAdsEditorPlaceHolderObject")
            {
                hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector
            };

            GameObject.DontDestroyOnLoad(placeHolderGameObject);
            m_Placeholder           = placeHolderGameObject.AddComponent <Placeholder>();
            m_Placeholder.OnFinish += (sender, e) =>
            {
                m_Platform.UnityAdsDidFinish(e.placementId, e.showResult);

                if (!m_LoadEnabled)
                {
                    m_Platform.UnityLifecycleManager.Post(() => {
                        var placementIds = new List <string>(m_PlacementMap.Keys);
                        foreach (var placementId in placementIds)
                        {
                            foreach (var listener in GetClonedHashSet(m_Platform.Listeners))
                            {
                                listener?.OnUnityAdsReady(placementId);
                            }
                        }
                    });
                }
            };

            var configurationUrl = string.Join("/", new string[]
            {
                k_BaseUrl,
                gameId,
                string.Join("&", new string[]
                {
                    "configuration?platform=editor",
                    "unityVersion=" + Uri.EscapeDataString(Application.unityVersion),
                    "sdkVersionName=" + Uri.EscapeDataString(m_Platform.Version)
                })
            });
            var request = WebRequest.Create(configurationUrl);
            request.BeginGetResponse(result =>
            {
                try
                {
                    var response     = request.EndGetResponse(result);
                    var reader       = new StreamReader(response.GetResponseStream() ?? throw new Exception("Null response stream fetching configuration"));
                    var responseBody = reader.ReadToEnd();
                    try
                    {
                        m_Configuration = new Configuration(responseBody);
                        if (!m_Configuration.enabled)
                        {
                            Debug.LogWarning("gameId " + gameId + " is not enabled");
                        }

                        //Add placements to load list
                        foreach (var placement in m_Configuration.placements)
                        {
                            m_PlacementMap.Add(placement.Key, !m_LoadEnabled);
                        }

                        m_Initialized = true;
                        initializationListener?.OnInitializationComplete();

                        foreach (var placement in m_Configuration.placements)
                        {
                            if (m_LoadEnabled)
                            {
                                foreach (var queuedPlacementId in m_QueuedLoads)
                                {
                                    Load(queuedPlacementId, null);
                                }
                            }
                            else
                            {
                                m_Platform.UnityAdsReady(placement.Key);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Debug.LogError($"Failed to parse configuration for gameId: {gameId}");
                        Debug.Log(responseBody);
                        Debug.LogError(exception.Message);
                        m_Platform.UnityAdsDidError($"Failed to parse configuration for gameId: {gameId}");
                        initializationListener?.OnInitializationFailed(UnityAdsInitializationError.INTERNAL_ERROR, $"Failed to parse configuration for gameId: {gameId}");
                    }
                    reader.Close();
                    response.Close();
                }
                catch (Exception exception)
                {
                    Debug.LogError($"Invalid configuration request for gameId: {gameId}");
                    Debug.LogError(exception.Message);
                    m_Platform.UnityAdsDidError($"Invalid configuration request for gameId: {gameId}");
                    initializationListener?.OnInitializationFailed(UnityAdsInitializationError.INTERNAL_ERROR, $"Invalid configuration request for gameId: {gameId}");
                }
            }, new object());
        }
Beispiel #3
0
 public void Initialize(string gameId, bool testMode, bool enablePerPlacementLoad, IUnityAdsInitializationListener initializationListener)
 {
     new PurchasingPlatform().Initialize();
     UnityAdsInitialize(gameId, testMode, enablePerPlacementLoad, new IosInitializationListener(this, initializationListener).NativePtr);
 }
 public IosInitializationListener(IUnityAdsInitializationListener unityAdsInternalListener, IUnityAdsInitializationListener userListener)
 {
     NativePtr = InitializationListenerCreate(OnInitializationComplete, OnInitializationFailed);
     m_UnityAdsInternalListener = unityAdsInternalListener;
     m_UserListener             = userListener;
 }
Beispiel #5
0
 public void Initialize(string gameId, bool testMode, bool enablePerPlacementLoad, IUnityAdsInitializationListener initializationListener)
 {
     m_UnityAdsPurchase = new Purchase();
     m_UnityAdsPurchase?.Initialize(this);
     m_UnityAds?.CallStatic("initialize", m_CurrentActivity, gameId, testMode, enablePerPlacementLoad, new AndroidInitializationListener(m_Platform, initializationListener));
 }
Beispiel #6
0
 public void Initialize(string gameId, bool testMode, bool enablePerPlacementLoad, IUnityAdsInitializationListener initializationListener)
 {
 }
Beispiel #7
0
 public AndroidInitializationListener(IPlatform platform, IUnityAdsInitializationListener initializationListener) : base("com.unity3d.ads.IUnityAdsInitializationListener")
 {
     m_Platform        = platform;
     m_ManagedListener = initializationListener;
 }