/// <summary> /// Displays an interstitial from the requested advertiser, if the requested advertiser is not available, another interstitial will be displayed based on your mediation settings /// </summary> /// <param name="advertiser">advertiser from which ad will be displayed if available</param> /// <param name="InterstitialClosed">callback triggered when interstitial video is closed</param> public void ShowInterstitial(SupportedAdvertisers advertiser, UnityAction InterstitialClosed = null) { //if ads are disabled by user -> do nothing if (CanShowAds() == false) { return; } Advertiser selected = GetInterstitialAdvertisers().First(cond => cond.advertiser == advertiser); if (selected.advertiserScript.IsInterstitialAvailable()) { if (debug) { Debug.Log("Interstitial from " + advertiser + " is available"); ScreenWriter.Write("Interstitial from " + advertiser + " is available"); } selected.advertiserScript.ShowInterstitial(InterstitialClosed); } else { if (debug) { Debug.Log("Interstitial from " + advertiser + " is NOT available"); ScreenWriter.Write("Interstitial from " + advertiser + " is NOT available"); } ShowInterstitial(InterstitialClosed); } }
/// <summary> /// Receipt validation method /// </summary> /// <param name="productName"></param> /// <param name="receipt"></param> /// <param name="exception"></param> /// <returns>true if receipt is valid</returns> bool ReceiptIsValid(string productName, string receipt, out IAPSecurityException exception) { exception = null; bool validPurchase = true; #if GleyUseValidation #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX CrossPlatformValidator validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier); try { validator.Validate(receipt); if (debug) { Debug.Log(this + " Receipt is valid for " + productName); ScreenWriter.Write(this + " Receipt is valid for " + productName); } } catch (IAPSecurityException ex) { exception = ex; if (debug) { Debug.Log(this + " Receipt is NOT valid for " + productName); ScreenWriter.Write(this + " Receipt is NOT valid for " + productName); } validPurchase = false; } #endif #endif return(validPurchase); }
/// <summary> /// Initialize store products, Call this method once at the beginning of your game /// </summary> /// <param name="InitComplete">callback method, returns a list of all store products, use this method for initializations</param> public void InitializeIAPManager(UnityAction <IAPOperationStatus, string, List <StoreProduct> > InitComplete) { if (IsInitialized()) { return; } IAPSettings settings = Resources.Load <IAPSettings>("IAPData"); if (settings == null) { Debug.LogError("No products available -> Go to Window->Gley->Easy IAP and define your products"); return; } shopProducts = settings.shopProducts; debug = settings.debug; if (debug) { Debug.Log(this + "Initialization Started"); ScreenWriter.Write(this + "Initialization Started"); } if (m_StoreController == null) { OnInitComplete = InitComplete; InitializePurchasing(); } }
private void BannerDisplayedResult(bool succesfullyDisplayed, BannerPosition position, BannerType bannerType) { if (succesfullyDisplayed == false) { if (debug) { Debug.Log("Banner failed to load -> trying another advertiser"); ScreenWriter.Write("Banner failed to load -> trying another advertiser hideBanners=" + hideBanners); } if (hideBanners == false) { LoadBanner(position, bannerType, false); } else { Debug.Log("Stop Loading Banners"); ScreenWriter.Write("Stop Loading Banners"); } } else { isBannerOnScreen = true; if (debug) { Debug.Log("Banner is on screen"); ScreenWriter.Write("Banner is on screen"); } } }
/// <summary> /// Actual loading of external file /// </summary> /// <param name="url">the url to the config file</param> /// <returns></returns> private IEnumerator LoadFile(string url) { if (debug) { Debug.Log("URL: " + url); ScreenWriter.Write("URL: " + url); } FileLoader fileLoader = new FileLoader(); yield return(StartCoroutine(fileLoader.LoadFile(url, debug))); try { string result = fileLoader.GetResult(); AdOrder adOrder = JsonUtility.FromJson <AdOrder>(result); Debug.Log(adOrder.interstitialMediation); UpdateSettings(adOrder); } catch { if (debug) { Debug.LogWarning("File was not in correct format"); ScreenWriter.Write("File was not in correct format"); } } }
/// <summary> /// refreshes the settings after a config file was read /// </summary> /// <param name="adOrder">settings file</param> private void UpdateSettings(AdOrder adOrder) { bannerMediation = adOrder.bannerMediation; interstitialMediation = adOrder.interstitialMediation; rewardedMediation = adOrder.rewardedMediation; for (int i = 0; i < adOrder.advertisers.Count; i++) { for (int j = 0; j < allAdvertisers.Count; j++) { if (allAdvertisers[j].mediationSettings.GetAdvertiser() == adOrder.advertisers[i].GetAdvertiser()) { allAdvertisers[j].mediationSettings = adOrder.advertisers[i]; } } } if (debug) { Debug.Log("File Config Loaded"); ScreenWriter.Write("File Config Loaded"); } ApplySettings(); }
/// <summary> /// /// </summary> /// <param name="arg"></param> private static void Run(string arg) { #region Reading // Read the file // Read a text file line by line. Reader reader = new FileReader(arg); PersonList personList = new PersonList(reader); IList <Person> persons = personList.ReadAllPeople(); #endregion #region Sorting Features.Sorting.IPersonSorter <Person> Sorter = new Features.Sorting.PersonSorter(persons); IList <Person> sortedList = Sorter.SortByName(); #endregion #region Output //Output Writer WriteToScreen = new ScreenWriter(sortedList); Writer WriteToFile = new FileWriter(sortedList); WriteToScreen.display(); WriteToFile.display(); #endregion }
/// <summary> /// IStoreListener event handler called when initialization fails /// </summary> /// <param name="error"></param> public void OnInitializeFailed(InitializationFailureReason error) { if (debug) { Debug.Log("OnInitializeFailed"); ScreenWriter.Write("OnInitializeFailed"); } OnInitComplete(IAPOperationStatus.Fail, error.ToString(), null); }
/// <summary> /// IStoreListener event handler called after initialization is done /// </summary> /// <param name="controller"></param> /// <param name="extensions"></param> public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { if (debug) { Debug.Log("OnInitialized"); ScreenWriter.Write("OnInitialized"); } m_StoreController = controller; m_StoreExtensionProvider = extensions; for (int i = 0; i < shopProducts.Count; i++) { Product product = m_StoreController.products.WithID(shopProducts[i].GetStoreID()); if (debug) { Debug.Log(this + product.metadata.localizedTitle + " is available " + product.availableToPurchase); ScreenWriter.Write(this + product.metadata.localizedTitle + " is available " + product.availableToPurchase); } if (shopProducts[i].productType == ProductType.Subscription) { if (product != null && product.hasReceipt) { IAPSecurityException exception; if (ReceiptIsValid(shopProducts[i].productName, product.receipt, out exception)) { shopProducts[i].active = true; string introJson = null; SubscriptionManager p = new SubscriptionManager(product, introJson); shopProducts[i].subscriptionInfo = p.getSubscriptionInfo(); } } } if (shopProducts[i].productType == ProductType.NonConsumable) { if (product != null && product.hasReceipt) { IAPSecurityException exception; if (ReceiptIsValid(shopProducts[i].productName, product.receipt, out exception)) { shopProducts[i].active = true; } } } if (product != null && product.availableToPurchase) { shopProducts[i].localizedPriceString = product.metadata.localizedPriceString; shopProducts[i].price = System.Decimal.ToInt32(product.metadata.localizedPrice); shopProducts[i].isoCurrencyCode = product.metadata.isoCurrencyCode; shopProducts[i].localizedDescription = product.metadata.localizedDescription; shopProducts[i].localizedTitle = product.metadata.localizedTitle; } } OnInitComplete(IAPOperationStatus.Success, "Success", shopProducts); }
/// <summary> /// Loads banner for display /// </summary> /// <param name="position"></param> /// <param name="bannerType"></param> private void LoadBanner(BannerPosition position, BannerType bannerType, bool specificAdvertiser, SupportedAdvertisers advertiser = SupportedAdvertisers.Admob) { if (specificAdvertiser) { Advertiser selected = GetBannerAdvertisers().FirstOrDefault(cond => cond.advertiser == advertiser); if (selected != null) { if (debug) { Debug.Log("Specific banner loaded from " + selected); ScreenWriter.Write("Specific banner loaded from " + selected); } selected.advertiserScript.ShowBanner(position, bannerType, BannerDisplayedResult); return; } else { if (debug) { Debug.Log(selected + " has no banner ads"); ScreenWriter.Write(selected + " has no banner ads"); } } } ICustomAds selectedAdvertiser = null; if (bannerMediation == SupportedMediation.OrderMediation) { selectedAdvertiser = UseOrder(bannerAdvertisers, SupportedAdTypes.Banner); } else { selectedAdvertiser = UsePercent(bannerAdvertisers, SupportedAdTypes.Banner); } if (selectedAdvertiser != null) { if (debug) { Debug.Log("Banner loaded from " + selectedAdvertiser); ScreenWriter.Write("Banner loaded from " + selectedAdvertiser); } selectedAdvertiser.ShowBanner(position, bannerType, BannerDisplayedResult); } else { isBannerOnScreen = false; if (debug) { Debug.Log("No Banners Available"); ScreenWriter.Write("No Banners Available"); } } }
/// <summary> /// IStoreListener event handler called when a purchase fails /// </summary> /// <param name="product"></param> /// <param name="reason"></param> public void OnPurchaseFailed(Product product, PurchaseFailureReason reason) { if (debug) { Debug.Log(this + "Buy Product failed for " + product.metadata.localizedTitle + " Failed. Reason: " + reason); ScreenWriter.Write(this + "Buy Product failed for " + product.metadata.localizedTitle + " Failed. Reason: " + reason); } if (OnCompleteMethod != null) { OnCompleteMethod(IAPOperationStatus.Fail, product.metadata.localizedTitle + " Failed. Reason: " + reason, null); } }
/// <summary> /// Hides the active banner /// </summary> public void HideBanner() { if (debug) { Debug.Log("Hide Banners"); ScreenWriter.Write("Hide banners"); } hideBanners = true; for (int i = 0; i < allAdvertisers.Count; i++) { allAdvertisers[i].advertiserScript.HideBanner(); } isBannerOnScreen = false; }
public void Test1() { var sr = new ScreenWriter(); var sut = new Mock <IScreenWriter>(); var listOfNames = new List <string>() { "Dwight Schrute", "Jim Halpert", "Pam Beesly", "Michael Scott" }; sut.Setup(s => s.WriteListOfNamesToConsole(listOfNames)).Callback(() => sr.WriteListOfNamesToConsole(listOfNames)); sut.Object.WriteListOfNamesToConsole(listOfNames); sut.Verify(s => s.WriteStringToConsole(It.IsAny <string>()), Times.AtLeastOnce); }
/// <summary> /// call this method to buy a product /// </summary> /// <param name="productName">An enum member generated from Settings Window</param> /// <param name="OnCompleteMethod">callback method that returns the bought product details for initializations</param> public void BuyProduct(ShopProductNames productName, UnityAction <IAPOperationStatus, string, StoreProduct> OnCompleteMethod) { if (debug) { Debug.Log(this + "Buy Process Started for " + productName); ScreenWriter.Write(this + "Buy Process Started for " + productName); } this.OnCompleteMethod = OnCompleteMethod; for (int i = 0; i < shopProducts.Count; i++) { if (shopProducts[i].productName == productName.ToString()) { BuyProductID(shopProducts[i].GetStoreID()); } } }
/// <summary> /// initializes the buy product process /// </summary> /// <param name="productId"></param> private void BuyProductID(string productId) { if (debug) { Debug.Log(this + "Buy product with id: " + productId); ScreenWriter.Write(this + "Buy product with id: " + productId); } if (IsInitialized()) { Product product = m_StoreController.products.WithID(productId); if (product != null && product.availableToPurchase) { m_StoreController.InitiatePurchase(product); } else { if (debug) { Debug.Log(this + "BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); ScreenWriter.Write(this + "BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); } if (OnCompleteMethod != null) { OnCompleteMethod(IAPOperationStatus.Fail, "Not purchasing product, either is not found or is not available for purchase", null); } } } else { if (debug) { Debug.Log(this + "BuyProductID FAIL. Store not initialized."); ScreenWriter.Write(this + "BuyProductID FAIL. Store not initialized."); } if (OnCompleteMethod != null) { OnCompleteMethod(IAPOperationStatus.Fail, "Store not initialized.", null); } } }
/// <summary> /// Displays an interstitial video based on your mediation settings /// </summary> /// <param name="InterstitialClosed">callback triggered when interstitial video is closed also returns the publisher</param> public void ShowInterstitial(UnityAction <string> InterstitialClosed) { //if ads are disabled by user -> do nothing if (CanShowAds() == false) { return; } ICustomAds selectedAdvertiser = GetInterstitialAdvertiser(); if (selectedAdvertiser != null) { if (debug) { Debug.Log("Interstitial loaded from " + selectedAdvertiser); ScreenWriter.Write("Interstitial loaded from " + selectedAdvertiser); } selectedAdvertiser.ShowInterstitial(InterstitialClosed); } }
static void Main(string[] args) { ScreenWriter.Initialize(110, 52); var map = MapLoader.LoadMap("Map01.txt"); var player = new Player(); player.Initialize(map); var projectionFrame = new Frame(0, 0, 100, 50, true, WindowsConsoleEngine.ConsoleColor.Cyan); //Controls while (true) { var input = Console.KeyAvailable ? Console.ReadKey() : new ConsoleKeyInfo(); if (input.Key == ConsoleKey.DownArrow) { player.MoveForward(-0.1f); } else if (input.Key == ConsoleKey.UpArrow) { player.MoveForward(0.1f); } else if (input.Key == ConsoleKey.LeftArrow) { player.Turn(-3f); } else if (input.Key == ConsoleKey.RightArrow) { player.Turn(3f); } var projection = player.GeneratePlayerView(map, 100, 50); projectionFrame.WriteCharacterArray(0, 0, projection); projectionFrame.WriteString(1, 1, "PlayerX = " + player.posX, WindowsConsoleEngine.ConsoleColor.Cyan); projectionFrame.WriteString(1, 2, "PlayerY = " + player.posY, WindowsConsoleEngine.ConsoleColor.Cyan); projectionFrame.WriteString(1, 3, "PlayerA = " + player.viewingAngle, WindowsConsoleEngine.ConsoleColor.Cyan); ScreenWriter.Refresh(); } }
/// <summary> /// Restore previously bought products (Only required on iOS) /// </summary> /// <param name="OnCompleteMethod">called when the restore process is done</param> public void RestorePurchases(UnityAction <IAPOperationStatus, string, StoreProduct> OnCompleteMethod) { if (!IsInitialized()) { if (debug) { Debug.Log(this + "RestorePurchases FAIL. Not initialized."); ScreenWriter.Write(this + "RestorePurchases FAIL. Not initialized."); } return; } if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXPlayer) { if (debug) { Debug.Log(this + "RestorePurchases started ..."); ScreenWriter.Write(this + "RestorePurchases started ..."); } this.OnCompleteMethod = OnCompleteMethod; var apple = m_StoreExtensionProvider.GetExtension <IAppleExtensions>(); apple.RestoreTransactions((result) => { if (debug) { Debug.Log(this + "RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore."); ScreenWriter.Write(this + "RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore."); } }); } else { if (debug) { Debug.Log(this + "RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform); ScreenWriter.Write(this + "RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform); } } }
/// <summary> /// Displays a rewarded video based on your mediation settings /// </summary> /// <param name="CompleteMethod">callback triggered when video reward finished - if bool param is true => video was not skipped, also the advertiser name is sent to callback method</param> public void ShowRewardedVideo(UnityAction <bool, string> CompleteMethod) { ICustomAds selectedAdvertiser = null; if (rewardedMediation == SupportedMediation.OrderMediation) { selectedAdvertiser = UseOrder(rewardedAdvertisers, SupportedAdTypes.Rewarded); } else { selectedAdvertiser = UsePercent(rewardedAdvertisers, SupportedAdTypes.Rewarded); } if (selectedAdvertiser != null) { if (debug) { Debug.Log("Rewarded video loaded from " + selectedAdvertiser); ScreenWriter.Write("Rewarded video loaded from " + selectedAdvertiser); } selectedAdvertiser.ShowRewardVideo(CompleteMethod); } }
/// <summary> /// Initializes Unity IAP /// </summary> private void InitializePurchasing() { if (IsInitialized()) { OnInitComplete(IAPOperationStatus.Success, "Already initialized", null); return; } builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); for (int i = 0; i < shopProducts.Count; i++) { builder.AddProduct(shopProducts[i].GetStoreID(), shopProducts[i].GetProductType()); } if (debug) { Debug.Log("InitializePurchasing"); ScreenWriter.Write("InitializePurchasing"); } UnityPurchasing.Initialize(this, builder); }
/// <summary> /// Displays a rewarded video based on advertiser sent as parameter, if the requested advertiser is not available selected mediation settings are used /// </summary> /// <param name="advertiser">the advertiser from which you want to display the rewarded video</param> /// <param name="CompleteMethod">callback triggered when video reward finished - if bool param is true => video was not skipped</param> public void ShowRewardedVideo(SupportedAdvertisers advertiser, UnityAction <bool> CompleteMethod) { Advertiser selected = GetRewardedAdvertisers().First(cond => cond.advertiser == advertiser); if (selected.advertiserScript.IsRewardVideoAvailable()) { if (debug) { Debug.Log("Rewarded Video from " + advertiser + " is available"); ScreenWriter.Write("Rewarded Video from " + advertiser + " is available"); } selected.advertiserScript.ShowRewardVideo(CompleteMethod); } else { if (debug) { Debug.Log("Rewarded Video from " + advertiser + " is NOT available"); ScreenWriter.Write("Rewarded Video from " + advertiser + " is NOT available"); } ShowRewardedVideo(CompleteMethod); } }
/// <summary> /// IStoreListener event handler called when a purchase is done /// </summary> /// <param name="e"></param> /// <returns></returns> public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { if (debug) { Debug.Log(this + "Product bought " + e.purchasedProduct.definition.id); ScreenWriter.Write(this + "Product bought " + e.purchasedProduct.definition.id); } for (int i = 0; i < shopProducts.Count; i++) { if (String.Equals(e.purchasedProduct.definition.id, shopProducts[i].GetStoreID(), StringComparison.Ordinal)) { IAPSecurityException exception; bool validPurchase = ReceiptIsValid(shopProducts[i].productName, e.purchasedProduct.receipt, out exception); if (validPurchase) { if (shopProducts[i].productType == ProductType.Subscription || shopProducts[i].productType == ProductType.NonConsumable) { shopProducts[i].active = true; } if (OnCompleteMethod != null) { OnCompleteMethod(IAPOperationStatus.Success, "Purchase Successful", shopProducts[i]); } } else { if (OnCompleteMethod != null) { OnCompleteMethod(IAPOperationStatus.Fail, "Invalid Receipt " + exception.Message + exception.Data, null); } } break; } } return(PurchaseProcessingResult.Complete); }
/// <summary> /// saves the new settings /// </summary> private void ApplySettings() { if (debug) { Debug.Log("Banner mediation type: " + bannerMediation); ScreenWriter.Write("Banner mediation type: " + bannerMediation); Debug.Log("Interstitial mediation type: " + interstitialMediation); ScreenWriter.Write("Interstitial mediation type: " + interstitialMediation); Debug.Log("Rewarded mediation type: " + rewardedMediation); ScreenWriter.Write("Rewarded mediation type: " + rewardedMediation); } bannerAdvertisers = new List <Advertiser>(); interstitialAdvertisers = new List <Advertiser>(); rewardedAdvertisers = new List <Advertiser>(); for (int i = 0; i < allAdvertisers.Count; i++) { if (bannerMediation == SupportedMediation.OrderMediation) { if (allAdvertisers[i].mediationSettings.bannerSettings.Order != 0) { bannerAdvertisers.Add(allAdvertisers[i]); } } else { if (allAdvertisers[i].mediationSettings.bannerSettings.Weight != 0) { bannerAdvertisers.Add(allAdvertisers[i]); } } if (interstitialMediation == SupportedMediation.OrderMediation) { Debug.Log(allAdvertisers[i].mediationSettings.interstitialSettings.Order); if (allAdvertisers[i].mediationSettings.interstitialSettings.Order != 0) { interstitialAdvertisers.Add(allAdvertisers[i]); } } else { if (allAdvertisers[i].mediationSettings.interstitialSettings.Weight != 0) { interstitialAdvertisers.Add(allAdvertisers[i]); } } if (rewardedMediation == SupportedMediation.OrderMediation) { if (allAdvertisers[i].mediationSettings.rewardedSettings.Order != 0) { rewardedAdvertisers.Add(allAdvertisers[i]); } } else { if (allAdvertisers[i].mediationSettings.rewardedSettings.Weight != 0) { rewardedAdvertisers.Add(allAdvertisers[i]); } } } if (bannerMediation == SupportedMediation.OrderMediation) { bannerAdvertisers = bannerAdvertisers.OrderBy(cond => cond.mediationSettings.bannerSettings.Order).ToList(); } else { bannerAdvertisers = bannerAdvertisers.OrderByDescending(cond => cond.mediationSettings.bannerSettings.Weight).ToList(); } if (interstitialMediation == SupportedMediation.OrderMediation) { interstitialAdvertisers = interstitialAdvertisers.OrderBy(cond => cond.mediationSettings.interstitialSettings.Order).ToList(); } else { interstitialAdvertisers = interstitialAdvertisers.OrderByDescending(cond => cond.mediationSettings.interstitialSettings.Weight).ToList(); } if (rewardedMediation == SupportedMediation.OrderMediation) { rewardedAdvertisers = rewardedAdvertisers.OrderBy(cond => cond.mediationSettings.rewardedSettings.Order).ToList(); } else { rewardedAdvertisers = rewardedAdvertisers.OrderByDescending(cond => cond.mediationSettings.rewardedSettings.Weight).ToList(); } }
public SPW() { graphics = new GraphicsDeviceManager( this ); Content.RootDirectory = "Content"; this.IsMouseVisible = true; #region creating and adding the game component objects Controller, ScreenWriter, Logger, and Windowing // instantiate the Controller c = new Controller( this ); // add it as a component so ITS Update() // function will AUTOMATICALLY be called // everytime this class's does. this.Components.Add( c ); // OK Hoooooold on. Did that "component" // stuff make any sense? // Looking at the definition of // the Controller class, notice how it says: // public class Controller : GameComponent // This reads "public class Controller is-a GameComponent" // So what does that mean? // Well, it just means that the Controller promises // to have an 'Update()' method within it. // Remember how our XNA game rapidly does the following: /* while( true ) { Update() ; Draw() ; } */ // When you add a GameComponent object to the Components // collection however, this is kind of (very roughly) what happens: /* while( true ) { Update() ; foreach( GameComponent component in this.Components ) component.Update() ; Draw() ; } */ // The Update() and Draw() functions that will get called // by the XNA framework, will normally only be the Update() // and Draw() functions of THIS class (the main game class). // Ok so what's this? // Add a few more components. sw = new ScreenWriter( this ); this.Components.Add( sw ); // Here's one that's a bit different! // Notice that the ScreenWriter IS-A "DRAWABLEGAMECOMPONENT" // public class ScreenWriter : DrawableGameComponent // So this is KIND OF what happens then: /* while( true ) { Update() ; foreach( GameComponent component in this.Components ) component.Update() ; Draw() ; foreach( DrawableGameComponent drawable in this.Components ) { drawable.Draw() ; } } */ // This obviously isn't exactly what happens but I think it // communicates the idea. // Using GameComponents and DrawableGameComponents // are great because they tie up ALL the code // to do with one "COMPONENT" of the game into one file. logger = new Logger( this, true ); this.Components.Add( logger ); // Create the Windowing object. // The source code for this system // by 'Aaron MacDougall', is on codeplex // http://www.codeplex.com/wsx/ windowing = new Windowing( this ); #endregion // Initialize the game state gameState = GameState.TitleScreen; // let game start @ title screen netState = NetState.Disconnected; // // create the world object world = new World(); // set width and height of the backbuffer this.graphics.PreferredBackBufferHeight = world.ScreenHeight; this.graphics.PreferredBackBufferWidth = world.ScreenWidth; // Tell player about how to toggle debug Color tBlueViolet = Color.BlueViolet; tBlueViolet.A = 0; sw[ "more" ] = new StringItem( "Press '8' to toggle debug messages", 40, world.ScreenHeight - 40, 5.0f, Color.Red, tBlueViolet ); // Start with debug messages not being displayed on screen // (press '8' to toggle) //ToggleDebug(); }
/// <summary> /// Percent mediation method /// A random number between 0 and 100 is generated /// the corresponding advertiser will be displayed based on your Settings Window setup /// </summary> /// <param name="advertisers">list of all advertisers</param> /// <param name="adType">type of advertiser that wants to be displayed</param> /// <returns></returns> private ICustomAds UsePercent(List <Advertiser> advertisers, SupportedAdTypes adType) { List <Advertiser> tempList = new List <Advertiser>(); List <int> thresholds = new List <int>(); int sum = 0; for (int i = 0; i < advertisers.Count; i++) { switch (adType) { case SupportedAdTypes.Banner: if (advertisers[i].advertiserScript.IsBannerAvailable() && !advertisers[i].advertiserScript.BannerAlreadyUsed()) { tempList.Add(advertisers[i]); sum += advertisers[i].mediationSettings.bannerSettings.Weight; thresholds.Add(sum); } break; case SupportedAdTypes.Interstitial: if (advertisers[i].advertiserScript.IsInterstitialAvailable()) { tempList.Add(advertisers[i]); sum += advertisers[i].mediationSettings.interstitialSettings.Weight; thresholds.Add(sum); } break; case SupportedAdTypes.Rewarded: if (advertisers[i].advertiserScript.IsRewardVideoAvailable()) { tempList.Add(advertisers[i]); sum += advertisers[i].mediationSettings.rewardedSettings.Weight; thresholds.Add(sum); } break; } } int index = UnityEngine.Random.Range(0, sum); if (debug) { for (int i = 0; i < tempList.Count; i++) { ScreenWriter.Write(tempList[i].advertiser + " weight " + thresholds[i]); Debug.Log(tempList[i].advertiser + " weight " + thresholds[i]); } } for (int i = 0; i < thresholds.Count; i++) { if (index < thresholds[i]) { if (debug) { ScreenWriter.Write("SHOW AD FROM: " + tempList[i].advertiser + " weight " + index); Debug.Log("SHOW AD FROM: " + tempList[i].advertiser + " weight " + index); } return(tempList[i].advertiserScript); } } return(null); }
/// <summary> /// Initializes all the advertisers from the plugin /// Should be called only once at the beginning of your app /// </summary> public void Initialize() { if (initialized == false) { adSettings = Resources.Load <AdSettings>("AdSettingsData"); if (adSettings == null) { Debug.LogError("Gley Ads Plugin is not properly configured. Go to Window->Gley->Ads to set up the plugin. See the documentation"); return; } bannerMediation = adSettings.bannerMediation; interstitialMediation = adSettings.interstitialMediation; rewardedMediation = adSettings.rewardedMediation; debug = adSettings.debugMode; initialized = true; AdvertiserSettings currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Admob); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomAdmob>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Admob), adSettings.GetPlaftormSettings(SupportedAdvertisers.Admob))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Vungle); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomVungle>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Vungle), adSettings.GetPlaftormSettings(SupportedAdvertisers.Vungle))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.AdColony); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomAdColony>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.AdColony), adSettings.GetPlaftormSettings(SupportedAdvertisers.AdColony))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Chartboost); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomChartboost>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Chartboost), adSettings.GetPlaftormSettings(SupportedAdvertisers.Chartboost))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Unity); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomUnityAds>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Unity), adSettings.GetPlaftormSettings(SupportedAdvertisers.Unity))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Heyzap); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomHeyzap>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Heyzap), adSettings.GetPlaftormSettings(SupportedAdvertisers.Heyzap))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.AppLovin); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomAppLovin>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.AppLovin), adSettings.GetPlaftormSettings(SupportedAdvertisers.AppLovin))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.Facebook); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomFacebook>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.Facebook), adSettings.GetPlaftormSettings(SupportedAdvertisers.Facebook))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.MoPub); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomMoPub>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.MoPub), adSettings.GetPlaftormSettings(SupportedAdvertisers.MoPub))); } } currentAdvertiser = adSettings.advertiserSettings.FirstOrDefault(cond => cond.advertiser == SupportedAdvertisers.IronSource); if (currentAdvertiser != null) { if (currentAdvertiser.useSDK) { allAdvertisers.Add(new Advertiser(go.AddComponent <CustomIronSource>(), adSettings.GetAdvertiserSettings(SupportedAdvertisers.IronSource), adSettings.GetPlaftormSettings(SupportedAdvertisers.IronSource))); } } if (debug) { ScreenWriter.Write("User GDPR consent is set to: " + GetConsent(userConsent)); ScreenWriter.Write("User CCPA consent is set to: " + GetConsent(ccpaConsent)); } for (int i = 0; i < allAdvertisers.Count; i++) { allAdvertisers[i].advertiserScript.InitializeAds(GetConsent(userConsent), GetConsent(ccpaConsent), allAdvertisers[i].platformSettings); } ApplySettings(); LoadFile(); } }