playMaker

Author Topic: Hi i need help to make playmaker action  (Read 694 times)

rik

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Hi i need help to make playmaker action
« on: October 27, 2015, 08:19:28 AM »
Hi
Below script was designed to show ads on unity gui buttons press i want to use this script to show when show ads bool is true any one can do ?

Code: [Select]
using UnityEngine;
using System.Collections;
using ChartboostSDK;

public class AdNetworks : MonoBehaviour {
AdmobHandler admobHandler;
ApplovinHandler applovinHandler;
    ChartboostHandler chartboostHandler;

public bool InitializeNetworksOnStart = true;
public int LoadInterstitialEveryXCalls = 1;
static int interstitialCounter;

public BannersNetwork bannerNetwork;
public enum BannersNetwork {
Admob,Applovin,nothing
}

public InterstitialNetwork interstitialNetwork;
public enum InterstitialNetwork {
Admob,Applovin,Chartboost,nothing
}

public BannersPosition bannersPosition;
public enum BannersPosition {
Bottom,Top,BottomLeft,BottomRight,TopLeft,TopRight
}




public string Applovin_Sdk_KEY = "Yor Applovin SDK Key";

public string Admob_Banner_ID = "Your adMob Banner ID";
public string Admob_Interstitial_ID  = "Your adMob Interstitial ID";

public string Chartboost_App_ID = "Your ChartBoost App ID";
public string Chartboost_App_Signature = "Your ChartBoost App Signature";



int caseSwitchInteger;





// Use this for initialization
void Start () {
interstitialCounter = LoadInterstitialEveryXCalls;

admobHandler = gameObject.AddComponent<AdmobHandler> ();
applovinHandler = gameObject.AddComponent<ApplovinHandler> ();
chartboostHandler = gameObject.AddComponent<ChartboostHandler> ();

if (InitializeNetworksOnStart) {
InitializeNetworks ();
}


}



public void InitializeNetworks(){

// Initialize for Banners

switch (bannerNetwork) {
case BannersNetwork.Applovin:
applovinHandler.Initialize(Applovin_Sdk_KEY);
break;

case BannersNetwork.Admob:
admobHandler.Initialize(Admob_Banner_ID,Admob_Interstitial_ID,false);
break;
}

     
// Initialize for Interstitials

switch (interstitialNetwork) {

    case InterstitialNetwork.Applovin:
applovinHandler.Initialize(Applovin_Sdk_KEY);
break;

case InterstitialNetwork.Admob:
admobHandler.Initialize(Admob_Banner_ID,Admob_Interstitial_ID,true);
break;

case InterstitialNetwork.Chartboost:
chartboostHandler.Initialize(Chartboost_App_ID,Chartboost_App_Signature,this.gameObject);
    break;


}


}

public void ShowBanner(){

switch (bannerNetwork) {
case BannersNetwork.Applovin:
applovinHandler.ShowBanner(PositionBannerInteger());
break;

case BannersNetwork.Admob:
admobHandler.ShowBanner(PositionBannerInteger());
break;
}

}

public void HideBanner(){

switch (bannerNetwork) {
case BannersNetwork.Applovin:
applovinHandler.HideBanner();
break;

case BannersNetwork.Admob:
admobHandler.HideBanner();
break;

}
}



public void ShowInterstitial(){
if (interstitialCounter > 1) {
interstitialCounter--;
Debug.Log("Interstitial Ad will be called in the next " + interstitialCounter + " calls");
return;
}
interstitialCounter = LoadInterstitialEveryXCalls;


switch (interstitialNetwork) {
case InterstitialNetwork.Applovin:
applovinHandler.ShowInterstitial();
break;
case InterstitialNetwork.Admob:
admobHandler.ShowInterstitial();
break;
case InterstitialNetwork.Chartboost:
chartboostHandler.ShowInterstitial();
break;

}

}





//--------------------------------------------------------------------------------



int PositionBannerInteger(){
switch (bannersPosition) {
case BannersPosition.Bottom:
caseSwitchInteger=1;
break;
case BannersPosition.Top:
caseSwitchInteger=2;
break;
case BannersPosition.BottomLeft:
caseSwitchInteger=3;
break;
case BannersPosition.BottomRight:
caseSwitchInteger=4;
break;
case BannersPosition.TopLeft:
caseSwitchInteger=5;
break;
case BannersPosition.TopRight:
caseSwitchInteger=6;
break;

}
return caseSwitchInteger;


}










}
« Last Edit: October 28, 2015, 12:40:55 AM by rik »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Hi i need help to make playmaker action
« Reply #1 on: November 10, 2015, 05:07:28 AM »
Hi,

 That's pretty involving as your scripts covers a lot of ground.

I don't see any code that works for the button, but here is the thing, this script can be controlled and called from PlayMaker without any custom actions.

 simply use "SendMessage" targeting the gameobject where this script is attached. The message is "ShowBanner", it will call the function ShowBanner on that component.

send "HideBanner" message to turn it off.
send "ShowInterstitial" message to show interestitial.
send "InitializeNetworks" message to init if needed ( but it does it on start, so you shoudl be good without this)


that's all you need here :)


 Bye,

 Jean