Initial commit: Unity WordConnect project
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00d9b8da9fd9484f96600e76d664e74c
|
||||
timeCreated: 1709532883
|
||||
@ -0,0 +1,56 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public class AdLifecycleManager : IAdLifecycleManager
|
||||
{
|
||||
private readonly AdsHandlerBase _adsHandler;
|
||||
|
||||
public AdLifecycleManager(AdsHandlerBase adsHandler)
|
||||
{
|
||||
_adsHandler = adsHandler;
|
||||
}
|
||||
|
||||
public void Load(AdUnit adUnit)
|
||||
{
|
||||
_adsHandler?.Load(adUnit);
|
||||
}
|
||||
|
||||
public void Show(AdUnit adUnit)
|
||||
{
|
||||
_adsHandler?.Show(adUnit);
|
||||
}
|
||||
|
||||
public void Hide(AdUnit adUnit)
|
||||
{
|
||||
_adsHandler?.Hide(adUnit);
|
||||
}
|
||||
|
||||
public bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
return _adsHandler != null && (_adsHandler.IsAvailable(adUnit) || adUnit.Loaded);
|
||||
}
|
||||
|
||||
public void Complete(AdUnit adUnit)
|
||||
{
|
||||
adUnit.OnShown?.Invoke(adUnit.PlacementId);
|
||||
}
|
||||
|
||||
public void Initialize(AdUnit adUnit)
|
||||
{
|
||||
adUnit.OnInitialized?.Invoke(adUnit.PlacementId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 572fd5f113dad43b6b492120fbd965ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,22 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AdReference", menuName ="WordConnectGameToolkit/Ads/AdReference")]
|
||||
public class AdReference : ScriptableObject
|
||||
{
|
||||
public EAdType adType;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8151ae330add46d49f409e031f774236
|
||||
timeCreated: 1709625749
|
||||
@ -0,0 +1,63 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public class AdUnit
|
||||
{
|
||||
public string PlacementId { get; }
|
||||
public AdReference AdReference { get; }
|
||||
public bool Loaded { get; set; }
|
||||
public Action<string> OnShown { get; set; }
|
||||
public Action<string> OnInitialized { get; set; }
|
||||
|
||||
public AdUnit(string placementId, AdReference adReference)
|
||||
{
|
||||
PlacementId = placementId;
|
||||
AdReference = adReference;
|
||||
}
|
||||
|
||||
public AdsHandlerBase AdsHandler { get; set; }
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
OnShown?.Invoke(PlacementId);
|
||||
}
|
||||
|
||||
public void Initialized()
|
||||
{
|
||||
OnInitialized?.Invoke(PlacementId);
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
AdsHandler?.Load(this);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
AdsHandler?.Show(this);
|
||||
}
|
||||
|
||||
public bool IsAvailable()
|
||||
{
|
||||
return AdsHandler != null && (AdsHandler.IsAvailable(this) || Loaded);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
AdsHandler?.Hide(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd76f366cfc84bfab6c025eb8ebc1b5e
|
||||
timeCreated: 1709541000
|
||||
@ -0,0 +1,28 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public abstract class AdsHandlerBase : ScriptableObject
|
||||
{
|
||||
public abstract void Init(string _id, bool adSettingTestMode, IAdsListener listener);
|
||||
public abstract void Show(AdUnit adUnit);
|
||||
public abstract void Load(AdUnit adUnit);
|
||||
|
||||
/// set false if adapter doesn't have availability method
|
||||
public abstract bool IsAvailable(AdUnit adUnit);
|
||||
|
||||
public abstract void Hide(AdUnit adUnit);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f71ea344e49b486dbea6a85fb3422111
|
||||
timeCreated: 1709485645
|
||||
@ -0,0 +1,21 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public enum EAdType
|
||||
{
|
||||
Banner,
|
||||
Interstitial,
|
||||
Rewarded
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b34f9ec5c8244b79a5b7eca99ddaee8
|
||||
timeCreated: 1709539401
|
||||
@ -0,0 +1,26 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public interface IAdLifecycleManager
|
||||
{
|
||||
void Load(AdUnit adUnit);
|
||||
void Show(AdUnit adUnit);
|
||||
void Hide(AdUnit adUnit);
|
||||
bool IsAvailable(AdUnit adUnit);
|
||||
void Complete(AdUnit adUnit);
|
||||
void Initialize(AdUnit adUnit);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15053b0564ace4fcdae31ceeb36d5e23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,27 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
{
|
||||
public interface IAdsListener
|
||||
{
|
||||
void Show(AdUnit adUnit);
|
||||
void OnAdsInitialized();
|
||||
void OnAdsLoaded(string placementId);
|
||||
void OnAdsLoadFailed();
|
||||
void OnAdsShowFailed();
|
||||
void OnAdsShowStart();
|
||||
void OnAdsShowClick();
|
||||
void OnAdsShowComplete();
|
||||
void OnInitFailed();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c85c74df67b4b7a928492e027e61311
|
||||
timeCreated: 1709539029
|
||||
@ -0,0 +1,94 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads
|
||||
{
|
||||
public class AdsListener : IAdsListener
|
||||
{
|
||||
private readonly List<AdUnit> adUnits;
|
||||
private readonly Dictionary<AdUnit, IAdLifecycleManager> lifecycleManagers;
|
||||
private bool available;
|
||||
private AdUnit _adUnit;
|
||||
|
||||
public AdsListener(List<AdUnit> adUnits, Dictionary<AdUnit, IAdLifecycleManager> lifecycleManagers)
|
||||
{
|
||||
this.adUnits = adUnits;
|
||||
this.lifecycleManagers = lifecycleManagers;
|
||||
}
|
||||
|
||||
public void Show(AdUnit adUnit)
|
||||
{
|
||||
Debug.Log("Show ad " + adUnit.PlacementId);
|
||||
_adUnit = adUnit;
|
||||
}
|
||||
|
||||
public void OnAdsInitialized()
|
||||
{
|
||||
Debug.Log("Ads initialized");
|
||||
foreach (var adUnit in adUnits)
|
||||
{
|
||||
lifecycleManagers[adUnit].Initialize(adUnit);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAdsLoaded(string placementId)
|
||||
{
|
||||
foreach (var adUnit in adUnits)
|
||||
{
|
||||
if (adUnit.PlacementId == placementId)
|
||||
{
|
||||
adUnit.Loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnInitFailed()
|
||||
{
|
||||
Debug.Log("Ads init failed, check assigned ad handler");
|
||||
}
|
||||
|
||||
public void OnAdsLoadFailed()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAdsShowFailed()
|
||||
{
|
||||
if (_adUnit != null)
|
||||
{
|
||||
_adUnit.Loaded = false;
|
||||
}
|
||||
|
||||
_adUnit = null;
|
||||
}
|
||||
|
||||
public void OnAdsShowStart()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAdsShowClick()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAdsShowComplete()
|
||||
{
|
||||
if (_adUnit != null)
|
||||
{
|
||||
lifecycleManagers[_adUnit].Complete(_adUnit);
|
||||
_adUnit = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5daba387c7ef452b807b7ca49155e6d8
|
||||
timeCreated: 1709532901
|
||||
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "CandySmith.Ads",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:ff6de30450f3748908ff580f6ec64d9a",
|
||||
"GUID:760a4c7888534400e882b82c5b3fba06"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.ads",
|
||||
"expression": "",
|
||||
"define": "UNITY_ADS"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.services.levelplay",
|
||||
"expression": "",
|
||||
"define": "IRONSOURCE"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00dd4a7ac8c24c898083910c81898ecc
|
||||
timeCreated: 1709468561
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f47475dce324490b55feb233fab1d19
|
||||
timeCreated: 1709621319
|
||||
@ -0,0 +1,139 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
#if ADMOB
|
||||
using GoogleMobileAds.Api;
|
||||
#endif
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AdmobBannerHandler", menuName ="WordConnectGameToolkit/Ads/AdmobBannerHandler")]
|
||||
public class AdmobBannerHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
#if ADMOB
|
||||
private BannerView _bannerView;
|
||||
#endif
|
||||
private bool _isInitialized = false;
|
||||
private bool _isBannerLoaded = false;
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
#if ADMOB
|
||||
_listener = listener;
|
||||
_isInitialized = true;
|
||||
Debug.Log("AdMob Banner Handler initialized.");
|
||||
_listener?.OnAdsInitialized();
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
_listener?.Show(adUnit);
|
||||
_bannerView?.Show();
|
||||
Debug.Log("Showing banner ad.");
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
if (!_isInitialized)
|
||||
{
|
||||
Debug.LogError("AdMob Banner Handler is not initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy any existing banner before creating a new one
|
||||
if (_bannerView != null)
|
||||
{
|
||||
_bannerView.Destroy();
|
||||
}
|
||||
|
||||
_bannerView = new BannerView(adUnit.PlacementId, AdSize.Banner, AdPosition.Bottom);
|
||||
|
||||
// Add event handlers
|
||||
_bannerView.OnBannerAdLoaded += () =>
|
||||
{
|
||||
_isBannerLoaded = true;
|
||||
Debug.Log("Banner ad loaded successfully.");
|
||||
_listener?.OnAdsLoaded(adUnit.PlacementId);
|
||||
};
|
||||
_bannerView.OnBannerAdLoadFailed += (LoadAdError error) =>
|
||||
{
|
||||
_isBannerLoaded = false;
|
||||
Debug.LogError($"Banner ad failed to load with error : {error.GetMessage()}");
|
||||
_listener?.OnAdsLoadFailed();
|
||||
};
|
||||
_bannerView.OnAdPaid += (AdValue adValue) => { Debug.Log($"Banner ad paid {adValue.Value} {adValue.CurrencyCode}"); };
|
||||
_bannerView.OnAdClicked += () =>
|
||||
{
|
||||
Debug.Log("Banner ad clicked.");
|
||||
_listener?.OnAdsShowClick();
|
||||
};
|
||||
_bannerView.OnAdImpressionRecorded += () =>
|
||||
{
|
||||
Debug.Log("Banner ad impression recorded.");
|
||||
_listener?.OnAdsShowStart();
|
||||
};
|
||||
|
||||
// Create an empty ad request
|
||||
AdRequest adRequest = new AdRequest();
|
||||
|
||||
// Load the banner with the request
|
||||
_bannerView.LoadAd(adRequest);
|
||||
Debug.Log("Requested banner ad load.");
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
return _isInitialized && _isBannerLoaded;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
if (_bannerView != null)
|
||||
{
|
||||
_bannerView.Hide();
|
||||
Debug.Log("Banner ad hidden.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void DestroyBanner()
|
||||
{
|
||||
#if ADMOB
|
||||
if (_bannerView != null)
|
||||
{
|
||||
_bannerView.Destroy();
|
||||
_bannerView = null;
|
||||
_isBannerLoaded = false;
|
||||
Debug.Log("Banner ad destroyed.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DestroyBanner();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3606b19b7f348cea65dc3082d89cafd
|
||||
timeCreated: 1726566442
|
||||
@ -0,0 +1,163 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
#if ADMOB
|
||||
using GoogleMobileAds.Api;
|
||||
#endif
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AdmobHandler", menuName ="WordConnectGameToolkit/Ads/AdmobHandler")]
|
||||
public class AdmobHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
#if ADMOB
|
||||
private InterstitialAd _interstitialAd;
|
||||
private RewardedAd _rewardedAd;
|
||||
#endif
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
#if ADMOB
|
||||
_listener = listener;
|
||||
MobileAds.RaiseAdEventsOnUnityMainThread = true;
|
||||
|
||||
MobileAds.Initialize(initstatus =>
|
||||
{
|
||||
if (initstatus == null)
|
||||
{
|
||||
Debug.LogError("Google Mobile Ads initialization failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If you use mediation, you can check the status of each adapter.
|
||||
var adapterStatusMap = initstatus.getAdapterStatusMap();
|
||||
if (adapterStatusMap != null)
|
||||
{
|
||||
foreach (var item in adapterStatusMap)
|
||||
{
|
||||
Debug.Log(string.Format("Adapter {0} is {1}",
|
||||
item.Key,
|
||||
item.Value.InitializationState));
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("Google Mobile Ads initialization complete.");
|
||||
_listener?.OnAdsInitialized();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
_listener?.Show(adUnit);
|
||||
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
if (_interstitialAd != null && _interstitialAd.CanShowAd())
|
||||
{
|
||||
Debug.Log("Showing interstitial ad.");
|
||||
_interstitialAd.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Interstitial ad is not ready yet.");
|
||||
}
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
if (_rewardedAd != null && _rewardedAd.CanShowAd())
|
||||
{
|
||||
_rewardedAd.Show(reward =>
|
||||
{
|
||||
Debug.Log(string.Format("Rewarded ad granted a reward: {0} {1}",
|
||||
reward.Amount,
|
||||
reward.Type));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Rewarded ad is not ready yet.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
#if ADMOB
|
||||
var adRequest = new AdRequest();
|
||||
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
InterstitialAd.Load(adUnit.PlacementId, adRequest, (ad, error) =>
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
Debug.LogError("Interstitial ad failed to load an ad with error : " + error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ad == null)
|
||||
{
|
||||
Debug.LogError("Unexpected error: Interstitial load event fired with null ad and null error.");
|
||||
return;
|
||||
}
|
||||
|
||||
_interstitialAd = ad;
|
||||
Debug.Log("Interstitial ad loaded with response : " + ad.GetResponseInfo());
|
||||
|
||||
ad.OnAdFullScreenContentClosed += () => _listener.OnAdsShowComplete();
|
||||
|
||||
_listener?.OnAdsLoaded(adUnit.PlacementId);
|
||||
});
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
RewardedAd.Load(adUnit.PlacementId, adRequest, (ad, error) =>
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
Debug.LogError("Rewarded ad failed to load an ad with error : " + error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ad == null)
|
||||
{
|
||||
Debug.LogError("Unexpected error: Rewarded load event fired with null ad and null error.");
|
||||
return;
|
||||
}
|
||||
|
||||
_rewardedAd = ad;
|
||||
|
||||
ad.OnAdFullScreenContentClosed += () => _listener.OnAdsShowComplete();
|
||||
|
||||
Debug.Log("Rewarded ad loaded with response : " + ad.GetResponseInfo());
|
||||
_listener?.OnAdsLoaded(adUnit.PlacementId);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00a645503e7646baac86d72a0b411f9e
|
||||
timeCreated: 1709647067
|
||||
@ -0,0 +1,149 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
[CreateAssetMenu(fileName = "IronsourceAdsHandler", menuName ="WordConnectGameToolkit/Ads/IronsourceAdsHandler")]
|
||||
public class IronsourceAdsHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
|
||||
private void Init(string _id)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
IronSource.Agent.setManualLoadRewardedVideo(true);
|
||||
IronSource.Agent.validateIntegration();
|
||||
IronSource.Agent.init(_id);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetListener(IAdsListener listener)
|
||||
{
|
||||
_listener = listener;
|
||||
Debug.Log(_listener);
|
||||
#if IRONSOURCE
|
||||
//Add Rewarded Video Events
|
||||
IronSourceInterstitialEvents.onAdReadyEvent += OnInterstitialAdReady;
|
||||
IronSourceInterstitialEvents.onAdLoadFailedEvent += InterstitialAdLoadFailedEvent;
|
||||
|
||||
IronSourceRewardedVideoEvents.onAdReadyEvent += OnRewardedVideoAdReady;
|
||||
IronSourceRewardedVideoEvents.onAdLoadFailedEvent += RewardedVideoAdShowFailedEvent;
|
||||
IronSourceRewardedVideoEvents.onAdRewardedEvent += Rewardeded;
|
||||
|
||||
IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if IRONSOURCE
|
||||
private void Rewardeded(IronSourcePlacement obj, IronSourceAdInfo ironSourceAdInfo)
|
||||
{
|
||||
Debug.Log("Ironsource Rewardeded");
|
||||
_listener?.OnAdsShowComplete();
|
||||
}
|
||||
|
||||
private void SdkInitializationCompletedEvent()
|
||||
{
|
||||
Debug.Log("Ironsource SdkInitializationCompletedEvent");
|
||||
_listener?.OnAdsInitialized();
|
||||
}
|
||||
|
||||
private void InterstitialAdLoadFailedEvent(IronSourceError obj)
|
||||
{
|
||||
Debug.Log("Ironsource InterstitialAdLoadFailedEvent " + obj.getCode() + " " + obj.getDescription());
|
||||
_listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void RewardedVideoAdShowFailedEvent(IronSourceError obj)
|
||||
{
|
||||
Debug.Log("1" + obj.getCode());
|
||||
Debug.Log("2" + obj.getDescription());
|
||||
Debug.Log("Ironsource RewardedVideoAdShowFailedEvent " + obj.getCode() + " " + obj.getDescription());
|
||||
Debug.Log(_listener);
|
||||
_listener?.OnAdsShowFailed();
|
||||
}
|
||||
|
||||
private void OnRewardedVideoAdReady(IronSourceAdInfo obj)
|
||||
{
|
||||
Debug.Log("Ironsource OnRewardedVideoAdReady");
|
||||
_listener?.OnAdsLoaded(obj.instanceId);
|
||||
}
|
||||
|
||||
private void OnInterstitialAdReady(IronSourceAdInfo obj)
|
||||
{
|
||||
Debug.Log("Ironsource OnInterstitialAdReady");
|
||||
_listener?.OnAdsLoaded(obj.instanceId);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
Debug.Log("Ironsource Init");
|
||||
Init(_id);
|
||||
Debug.Log("Ironsource SetListener");
|
||||
SetListener(listener);
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
IronSource.Agent.showInterstitial();
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
IronSource.Agent.showRewardedVideo();
|
||||
}
|
||||
|
||||
_listener?.Show(adUnit);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
IronSource.Agent.loadInterstitial();
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
IronSource.Agent.loadRewardedVideo();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
return IronSource.Agent.isInterstitialReady();
|
||||
}
|
||||
|
||||
if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
return IronSource.Agent.isRewardedVideoAvailable();
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8e3881626924945a6256e7be23a89b5
|
||||
timeCreated: 1709623544
|
||||
@ -0,0 +1,124 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
[CreateAssetMenu(fileName = "IronsourceBannerHandler", menuName ="WordConnectGameToolkit/Ads/IronsourceBannerHandler")]
|
||||
public class IronsourceBannerHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
|
||||
private void Init(string _id)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
IronSource.Agent.validateIntegration();
|
||||
IronSource.Agent.init(_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetListener(IAdsListener listener)
|
||||
{
|
||||
_listener = listener;
|
||||
#if IRONSOURCE
|
||||
IronSourceBannerEvents.onAdLoadedEvent += BannerAdLoadedEvent;
|
||||
IronSourceBannerEvents.onAdLoadFailedEvent += BannerAdLoadFailedEvent;
|
||||
IronSourceBannerEvents.onAdClickedEvent += BannerAdClickedEvent;
|
||||
IronSourceBannerEvents.onAdScreenPresentedEvent += BannerAdScreenPresentedEvent;
|
||||
IronSourceBannerEvents.onAdScreenDismissedEvent += BannerAdScreenDismissedEvent;
|
||||
IronSourceBannerEvents.onAdLeftApplicationEvent += BannerAdLeftApplicationEvent;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if IRONSOURCE
|
||||
private void BannerAdLoadedEvent(IronSourceAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad loaded");
|
||||
_listener?.OnAdsLoaded(adInfo.instanceId);
|
||||
}
|
||||
|
||||
private void BannerAdLoadFailedEvent(IronSourceError error)
|
||||
{
|
||||
Debug.Log($"IronSource Banner ad load failed. Error: {error.getCode()} - {error.getDescription()}");
|
||||
_listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void BannerAdClickedEvent(IronSourceAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad clicked");
|
||||
}
|
||||
|
||||
private void BannerAdScreenPresentedEvent(IronSourceAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad screen presented");
|
||||
}
|
||||
|
||||
private void BannerAdScreenDismissedEvent(IronSourceAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad screen dismissed");
|
||||
}
|
||||
|
||||
private void BannerAdLeftApplicationEvent(IronSourceAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad caused app to leave");
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
Debug.Log("IronSource Banner Init");
|
||||
Init(_id);
|
||||
SetListener(listener);
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
{
|
||||
IronSource.Agent.displayBanner();
|
||||
_listener?.Show(adUnit);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
{
|
||||
IronSourceBannerSize bannerSize = IronSourceBannerSize.BANNER;
|
||||
IronSource.Agent.loadBanner(bannerSize, IronSourceBannerPosition.BOTTOM);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
// IronSource doesn't provide a direct method to check if a banner is available
|
||||
// You might want to implement your own logic to track banner availability
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
{
|
||||
IronSource.Agent.hideBanner();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 229059528153459db318609c350eea5f
|
||||
timeCreated: 1726721377
|
||||
@ -0,0 +1,120 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
#if UNITY_ADS
|
||||
using UnityEngine.Advertisements;
|
||||
[CreateAssetMenu(fileName = "UnityAdsHandler", menuName ="WordConnectGameToolkit/Ads/UnityAdsHandler")]
|
||||
public class UnityAdsHandler : AdsHandlerBase, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
|
||||
{
|
||||
private bool rewardedLoaded;
|
||||
private bool initialized;
|
||||
private IAdsListener listener;
|
||||
|
||||
#region IAdsShowable Implementations
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
Advertisement.Initialize(_id, adSettingTestMode, this);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
Advertisement.Show(adUnit.PlacementId, this);
|
||||
listener.Show(adUnit);
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
Advertisement.Load(adUnit.PlacementId, this);
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Interface Implementations
|
||||
|
||||
public void OnInitializationComplete()
|
||||
{
|
||||
DebugLog("Init Success");
|
||||
listener.OnAdsInitialized();
|
||||
}
|
||||
|
||||
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
|
||||
{
|
||||
DebugLog($"Init Failed: [{error}]: {message}");
|
||||
listener.OnInitFailed();
|
||||
}
|
||||
|
||||
public void OnUnityAdsAdLoaded(string placementId)
|
||||
{
|
||||
DebugLog($"Load Success: {placementId}");
|
||||
listener.OnAdsLoaded(placementId);
|
||||
}
|
||||
|
||||
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
|
||||
{
|
||||
DebugLog($"Load Failed: [{error}:{placementId}] {message}");
|
||||
listener.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
|
||||
{
|
||||
DebugLog($"OnUnityAdsShowFailure: [{error}]: {message}");
|
||||
listener.OnAdsShowFailed();
|
||||
}
|
||||
|
||||
public void OnUnityAdsShowStart(string placementId)
|
||||
{
|
||||
DebugLog($"OnUnityAdsShowStart: {placementId}");
|
||||
listener.OnAdsShowStart();
|
||||
}
|
||||
|
||||
public void OnUnityAdsShowClick(string placementId)
|
||||
{
|
||||
DebugLog($"OnUnityAdsShowClick: {placementId}");
|
||||
listener.OnAdsShowClick();
|
||||
}
|
||||
|
||||
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
|
||||
{
|
||||
if (showCompletionState == UnityAdsShowCompletionState.COMPLETED)
|
||||
{
|
||||
DebugLog($"OnUnityAdsShowComplete: {placementId}");
|
||||
listener.OnAdsShowComplete();
|
||||
}
|
||||
}
|
||||
|
||||
//wrapper around debug.log to allow broadcasting log strings to the UI
|
||||
private void DebugLog(string msg)
|
||||
{
|
||||
Debug.Log(msg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d639e25c5eb64e8689f8fa30e7839258
|
||||
timeCreated: 1709468744
|
||||
@ -0,0 +1,111 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
#if UNITY_ADS
|
||||
using UnityEngine.Advertisements;
|
||||
[CreateAssetMenu(fileName = "UnityBannerAdsHandler", menuName ="WordConnectGameToolkit/Ads/UnityBannerAdsHandler")]
|
||||
public class UnityBannerAdsHandler : AdsHandlerBase
|
||||
{
|
||||
private bool initialized;
|
||||
private IAdsListener listener;
|
||||
private readonly BannerPosition bannerPosition = BannerPosition.BOTTOM_CENTER;
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
DebugLog("Unity Ads not initialized. Cannot show banner.");
|
||||
return;
|
||||
}
|
||||
|
||||
Advertisement.Banner.SetPosition(bannerPosition);
|
||||
Advertisement.Banner.Show(adUnit.PlacementId, new BannerOptions
|
||||
{
|
||||
clickCallback = OnBannerClicked,
|
||||
hideCallback = OnBannerHidden,
|
||||
showCallback = OnBannerShown
|
||||
});
|
||||
listener?.Show(adUnit);
|
||||
}
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
DebugLog("Unity Ads not initialized. Cannot load banner.");
|
||||
return;
|
||||
}
|
||||
|
||||
Advertisement.Banner.Load(adUnit.PlacementId, new BannerLoadOptions
|
||||
{
|
||||
loadCallback = () => OnBannerLoaded(adUnit.PlacementId),
|
||||
errorCallback = OnBannerError
|
||||
});
|
||||
}
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
return initialized && Advertisement.Banner.isLoaded;
|
||||
}
|
||||
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
Advertisement.Banner.Hide();
|
||||
}
|
||||
|
||||
private void OnBannerLoaded(string placementId)
|
||||
{
|
||||
DebugLog($"Banner loaded: {placementId}");
|
||||
listener?.OnAdsLoaded(placementId);
|
||||
}
|
||||
|
||||
private void OnBannerError(string message)
|
||||
{
|
||||
DebugLog($"Banner load error: {message}");
|
||||
listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void OnBannerClicked()
|
||||
{
|
||||
DebugLog("Banner clicked");
|
||||
listener?.OnAdsShowClick();
|
||||
}
|
||||
|
||||
private void OnBannerShown()
|
||||
{
|
||||
DebugLog("Banner shown");
|
||||
listener?.OnAdsShowStart();
|
||||
}
|
||||
|
||||
private void OnBannerHidden()
|
||||
{
|
||||
DebugLog("Banner hidden");
|
||||
}
|
||||
|
||||
private void DebugLog(string msg)
|
||||
{
|
||||
Debug.Log($"[UnityBannerAdsHandler] {msg}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60d7b8cc66824f168db82afe8c22a4b4
|
||||
timeCreated: 1726563264
|
||||
Reference in New Issue
Block a user