Firstborn/Library/PackageCache/com.unity.ads@4.4.2/Samples~/Scripts/UnityAdsManager.cs
Schaken-Mods 9092858a58 updated to the latest editor
I updated everything to the latest Unity Editor. Also realized I had the wrong shaders on my hairs, those are fixed and the hairs look MUCH better!
2023-05-07 17:43:11 -05:00

126 lines
3.3 KiB
C#

using System;
using System.Collections;
using UnityEngine.Advertisements;
using UnityEngine;
public class UnityAdsManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
public string GAME_ID = "3003911"; //replace with your gameID from dashboard. note: will be different for each platform.
private const string BANNER_PLACEMENT = "banner";
private const string VIDEO_PLACEMENT = "video";
private const string REWARDED_VIDEO_PLACEMENT = "rewardedVideo";
[SerializeField] private BannerPosition bannerPosition = BannerPosition.BOTTOM_CENTER;
private bool testMode = true;
private bool showBanner = false;
//utility wrappers for debuglog
public delegate void DebugEvent(string msg);
public static event DebugEvent OnDebugLog;
public void Initialize()
{
if (Advertisement.isSupported)
{
DebugLog(Application.platform + " supported by Advertisement");
}
Advertisement.Initialize(GAME_ID, testMode, this);
}
public void ToggleBanner()
{
showBanner = !showBanner;
if (showBanner)
{
Advertisement.Banner.SetPosition(bannerPosition);
Advertisement.Banner.Show(BANNER_PLACEMENT);
}
else
{
Advertisement.Banner.Hide(false);
}
}
public void LoadRewardedAd()
{
Advertisement.Load(REWARDED_VIDEO_PLACEMENT, this);
}
public void ShowRewardedAd()
{
Advertisement.Show(REWARDED_VIDEO_PLACEMENT, this);
}
public void LoadNonRewardedAd()
{
Advertisement.Load(VIDEO_PLACEMENT, this);
}
public void ShowNonRewardedAd()
{
Advertisement.Show(VIDEO_PLACEMENT, this);
}
#region Interface Implementations
public void OnInitializationComplete()
{
DebugLog("Init Success");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
DebugLog($"Init Failed: [{error}]: {message}");
}
public void OnUnityAdsAdLoaded(string placementId)
{
DebugLog($"Load Success: {placementId}");
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
DebugLog($"Load Failed: [{error}:{placementId}] {message}");
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
DebugLog($"OnUnityAdsShowFailure: [{error}]: {message}");
}
public void OnUnityAdsShowStart(string placementId)
{
DebugLog($"OnUnityAdsShowStart: {placementId}");
}
public void OnUnityAdsShowClick(string placementId)
{
DebugLog($"OnUnityAdsShowClick: {placementId}");
}
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
DebugLog($"OnUnityAdsShowComplete: [{showCompletionState}]: {placementId}");
}
#endregion
public void OnGameIDFieldChanged(string newInput)
{
GAME_ID = newInput;
}
public void ToggleTestMode(bool isOn)
{
testMode = isOn;
}
//wrapper around debug.log to allow broadcasting log strings to the UI
void DebugLog(string msg)
{
OnDebugLog?.Invoke(msg);
Debug.Log(msg);
}
}