Skip to content

Commit

Permalink
Merge pull request #31 from unity-package/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VirtueSky authored Dec 24, 2024
2 parents e4754cf + a8aae90 commit 4bf4550
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 153 deletions.
7 changes: 5 additions & 2 deletions Core/Runtime/MonoGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void OnApplicationFocus(bool hasFocus)
private void OnApplicationPause(bool pauseStatus)
{
OnGamePause?.Invoke(pauseStatus);
if (pauseStatus)
if (pauseStatus && GameData.IsAutoSave)
{
GameData.Save();
}
Expand All @@ -136,7 +136,10 @@ private void OnApplicationPause(bool pauseStatus)
private void OnApplicationQuit()
{
OnGameQuit?.Invoke();
GameData.Save();
if (GameData.IsAutoSave)
{
GameData.Save();
}
}

#endregion
Expand Down
48 changes: 46 additions & 2 deletions Module/Advertising/Runtime/Admob/AdmobClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
using GoogleMobileAds.Api;
#endif
using System;
using VirtueSky.Core;

namespace VirtueSky.Ads
Expand Down Expand Up @@ -43,10 +42,55 @@ public override void Initialize()
LoadRewardedInterstitial();
LoadAppOpen();
LoadNativeOverlay();
LoadBanner();
#endif
}

void LoadNativeOverlay()
public override AdUnit InterstitialAdUnit() => AdSettings.AdmobInterstitialAdUnit;

public override void LoadInterstitial()
{
if (!AdSettings.AdmobInterstitialAdUnit.IsReady()) AdSettings.AdmobInterstitialAdUnit.Load();
}

public override AdUnit RewardAdUnit() => AdSettings.AdmobRewardAdUnit;

public override void LoadRewarded()
{
if (!AdSettings.AdmobRewardAdUnit.IsReady()) AdSettings.AdmobRewardAdUnit.Load();
}

public override AdUnit RewardedInterstitialAdUnit() => AdSettings.AdmobRewardedInterstitialAdUnit;

public override void LoadRewardedInterstitial()
{
if (!AdSettings.AdmobRewardedInterstitialAdUnit.IsReady())
AdSettings.AdmobRewardedInterstitialAdUnit.Load();
}

public override AdUnit AppOpenAdUnit() => AdSettings.AdmobAppOpenAdUnit;

public override void LoadAppOpen()
{
if (!AdSettings.AdmobAppOpenAdUnit.IsReady()) AdSettings.AdmobAppOpenAdUnit.Load();
}

public override void ShowAppOpen()
{
if (statusAppOpenFirstIgnore) AdSettings.AdmobAppOpenAdUnit.Show();
statusAppOpenFirstIgnore = true;
}

public override AdUnit BannerAdUnit() => AdSettings.AdmobBannerAdUnit;

public override void LoadBanner()
{
AdSettings.AdmobBannerAdUnit.Load();
}

public override AdUnit NativeOverlayAdUnit() => AdSettings.AdmobNativeOverlayAdUnit;

public override void LoadNativeOverlay()
{
if (!AdSettings.AdmobNativeOverlayAdUnit.IsReady())
{
Expand Down
155 changes: 15 additions & 140 deletions Module/Advertising/Runtime/General/AdClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,150 +2,25 @@ namespace VirtueSky.Ads
{
public abstract class AdClient
{
private bool statusAppOpenFirstIgnore;
protected bool statusAppOpenFirstIgnore;


public abstract void Initialize();

#region Inter Ad

public AdUnit InterstitialAdUnit()
{
return AdSettings.CurrentAdNetwork switch
{
AdNetwork.Max => AdSettings.MaxInterstitialAdUnit,
AdNetwork.Admob => AdSettings.AdmobInterstitialAdUnit,
_ => AdSettings.IronSourceInterstitialAdUnit,
};
}

protected virtual bool IsInterstitialReady()
{
return InterstitialAdUnit().IsReady();
}

public virtual void LoadInterstitial()
{
if (InterstitialAdUnit() == null) return;
if (!IsInterstitialReady()) InterstitialAdUnit().Load();
}

#endregion

#region Reward Ad

public AdUnit RewardAdUnit()
{
return AdSettings.CurrentAdNetwork switch
{
AdNetwork.Max => AdSettings.MaxRewardAdUnit,
AdNetwork.Admob => AdSettings.AdmobRewardAdUnit,
_ => AdSettings.IronSourceRewardAdUnit,
};
}

protected virtual bool IsRewardedReady()
{
return RewardAdUnit().IsReady();
}

public virtual void LoadRewarded()
{
if (RewardAdUnit() == null) return;
if (!IsRewardedReady()) RewardAdUnit().Load();
}

#endregion

#region Reward Inter Ad

public AdUnit RewardedInterstitialAdUnit()
{
return AdSettings.CurrentAdNetwork switch
{
AdNetwork.Max => AdSettings.MaxRewardedInterstitialAdUnit,
AdNetwork.Admob => AdSettings.AdmobRewardedInterstitialAdUnit,
_ => null
};
}

protected virtual bool IsRewardedInterstitialReady()
{
return RewardedInterstitialAdUnit().IsReady();
}

public virtual void LoadRewardedInterstitial()
{
if (RewardedInterstitialAdUnit() == null) return;
if (!IsRewardedInterstitialReady()) RewardedInterstitialAdUnit().Load();
}

#endregion

#region AppOpen Ad

public AdUnit AppOpenAdUnit()
{
return AdSettings.CurrentAdNetwork switch
{
AdNetwork.Max => AdSettings.MaxAppOpenAdUnit,
AdNetwork.Admob => AdSettings.AdmobAppOpenAdUnit,
_ => null
};
}

protected virtual bool IsAppOpenReady()
{
return AppOpenAdUnit().IsReady();
}

public virtual void LoadAppOpen()
{
if (AppOpenAdUnit() == null) return;
if (!IsAppOpenReady()) AppOpenAdUnit().Load();
}

public virtual void ShowAppOpen()
{
if (statusAppOpenFirstIgnore) AppOpenAdUnit().Show();
statusAppOpenFirstIgnore = true;
}

#endregion

#region Banner Ad

public AdUnit BannerAdUnit()
{
return AdSettings.CurrentAdNetwork switch
{
AdNetwork.Max => AdSettings.MaxBannerAdUnit,
AdNetwork.Admob => AdSettings.AdmobBannerAdUnit,
_ => AdSettings.IronSourceBannerAdUnit
};
}

#endregion

#region Native Overlay Ad
public abstract AdUnit InterstitialAdUnit();
public abstract void LoadInterstitial();
public abstract AdUnit RewardAdUnit();
public abstract void LoadRewarded();
public abstract AdUnit RewardedInterstitialAdUnit();
public abstract void LoadRewardedInterstitial();
public abstract AdUnit AppOpenAdUnit();
public abstract void LoadAppOpen();
public abstract void ShowAppOpen();
public abstract AdUnit BannerAdUnit();

public abstract void LoadBanner();

// Native overlay only for admob
public AdUnit NativeOverlayAdUnit()
{
return AdSettings.AdmobNativeOverlayAdUnit;
}

protected virtual bool IsNativeOverlayAdReady()
{
return NativeOverlayAdUnit().IsReady();
}

public virtual void LoadNativeOverlayAd()
{
if (NativeOverlayAdUnit() == null) return;
if (!IsNativeOverlayAdReady()) NativeOverlayAdUnit().Load();
}

#endregion
public abstract AdUnit NativeOverlayAdUnit();
public abstract void LoadNativeOverlay();
}
}
53 changes: 53 additions & 0 deletions Module/Advertising/Runtime/IronSource/IronSourceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,59 @@ public override void Initialize()
#endif
LoadInterstitial();
LoadRewarded();
LoadBanner();
}

public override AdUnit InterstitialAdUnit() => AdSettings.IronSourceInterstitialAdUnit;

public override void LoadInterstitial()
{
if (!AdSettings.IronSourceInterstitialAdUnit.IsReady()) AdSettings.IronSourceInterstitialAdUnit.Load();
}

public override AdUnit RewardAdUnit() => AdSettings.IronSourceRewardAdUnit;

public override void LoadRewarded()
{
if (!AdSettings.IronSourceRewardAdUnit.IsReady()) AdSettings.IronSourceRewardAdUnit.Load();
}

public override AdUnit RewardedInterstitialAdUnit()
{
return null;
}

public override void LoadRewardedInterstitial()
{
}

public override AdUnit AppOpenAdUnit()
{
return null;
}

public override void LoadAppOpen()
{
}

public override void ShowAppOpen()
{
}

public override AdUnit BannerAdUnit() => AdSettings.IronSourceBannerAdUnit;

public override void LoadBanner()
{
AdSettings.IronSourceBannerAdUnit.Load();
}

public override AdUnit NativeOverlayAdUnit()
{
return null;
}

public override void LoadNativeOverlay()
{
}
#if VIRTUESKY_ADS && VIRTUESKY_IRONSOURCE
private void ImpressionDataReadyEvent(IronSourceImpressionData impressionData)
Expand Down
52 changes: 52 additions & 0 deletions Module/Advertising/Runtime/Max/MaxAdClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,60 @@ public override void Initialize()
LoadRewarded();
LoadRewardedInterstitial();
LoadAppOpen();
LoadBanner();
#endif
}

public override AdUnit InterstitialAdUnit() => AdSettings.MaxInterstitialAdUnit;

public override void LoadInterstitial()
{
if (!AdSettings.MaxInterstitialAdUnit.IsReady()) AdSettings.MaxInterstitialAdUnit.Load();
}

public override AdUnit RewardAdUnit() => AdSettings.MaxRewardAdUnit;

public override void LoadRewarded()
{
if (!AdSettings.MaxRewardAdUnit.IsReady()) AdSettings.MaxRewardAdUnit.Load();
}

public override AdUnit RewardedInterstitialAdUnit() => AdSettings.MaxRewardedInterstitialAdUnit;

public override void LoadRewardedInterstitial()
{
if (!AdSettings.MaxRewardedInterstitialAdUnit.IsReady()) AdSettings.MaxRewardedInterstitialAdUnit.Load();
}

public override AdUnit AppOpenAdUnit() => AdSettings.MaxAppOpenAdUnit;

public override void LoadAppOpen()
{
if (!AdSettings.MaxAppOpenAdUnit.IsReady()) AdSettings.MaxAppOpenAdUnit.Load();
}

public override void ShowAppOpen()
{
if (statusAppOpenFirstIgnore) AdSettings.MaxAppOpenAdUnit.Show();
statusAppOpenFirstIgnore = true;
}

public override AdUnit BannerAdUnit() => AdSettings.MaxBannerAdUnit;

public override void LoadBanner()
{
AdSettings.MaxBannerAdUnit.Load();
}

public override AdUnit NativeOverlayAdUnit()
{
return null;
}

public override void LoadNativeOverlay()
{
}

#if VIRTUESKY_ADS && VIRTUESKY_APPLOVIN
private void OnAppStateChange(bool pauseStatus)
{
Expand Down
Loading

0 comments on commit 4bf4550

Please sign in to comment.