12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class VungleAdsManager : UnitySingleton<VungleAdsManager> {
- private string appID = "";
- private string placementID = "";
- private bool adInited = false;
- private System.Action finishCallback = null;
- Dictionary<string, bool> placements = new Dictionary<string, bool>();
- public void Init(System.Action finishCallback)
- {
- #if UNITY_IPHONE
- appID = "597a18ac6f7cda15620033e1";
- placementID = "DEFAULT19439";
- placements = new Dictionary<string, bool>
- {
- { placementID, false }
- };
- #elif UNITY_ANDROID
- appID = "597a181605724327620031ed";
- placementID = "DEFAULT72579";
- placements = new Dictionary<string, bool>
- {
- { placementID, false }
- };
- #endif
- string[] array = new string[placements.Keys.Count];
- placements.Keys.CopyTo(array, 0);
- Vungle.init(appID, array);
- Debug.Log("Vungle Inited. appID is "+appID);
- this.finishCallback = finishCallback;
- InitializeEventHandlers();
- }
- public void LoadAd(){
- Vungle.loadAd(placementID);
- Debug.Log("Vungle load ad ");
- }
- public bool CheckAd(){
- Debug.Log("Vungle isAdvertAvailable is "+Vungle.isAdvertAvailable(placementID));
- return Vungle.isAdvertAvailable(placementID);
- }
- public void PlayAd(){
- Vungle.playAd(placementID);
- Debug.Log("Vungle play ad");
- }
- private void InitializeEventHandlers() {
- Vungle.onAdStartedEvent += (placementID) => {
- Debug.Log ("Ad " + placementID + " is starting! Pause your game animation or sound here.");
- };
- Vungle.onAdFinishedEvent += (placementID, args) => {
- Debug.Log ("Ad finished - placementID " + placementID + ", was call to action clicked:" + args.WasCallToActionClicked + ", is completed view:"
- + args.IsCompletedView);
- if(args.IsCompletedView && finishCallback != null)
- finishCallback();
- };
- Vungle.adPlayableEvent += (placementID, adPlayable) => {
- Debug.Log ("Ad's playable state has been changed! placementID " + placementID + ". Now: " + adPlayable);
- };
- Vungle.onLogEvent += (log) => {
- Debug.Log ("Log: " + log);
- };
- Vungle.onInitializeEvent += () => {
- adInited = true;
- Debug.Log ("SDK initialized");
- //自动加载广告
- LoadAd();
- };
- }
- public bool IsAdInited(){
- return adInited;
- }
- void OnApplicationPause(bool pauseStatus) {
- if (pauseStatus) {
- Vungle.onPause();
- }
- else {
- Vungle.onResume();
- }
- }
- }
|