Recently integrated Fyber SDK, recorded here:
Background configuration aspects of the content is that others have done, I did not participate, so here is not discussed, there is a need to directly refer to the official documents can:
Https://unity.fyber.com/docs/welcome
1. Download the Unity package:
Https://unity.fyber.com/docs/download-unity-plugin
Click the bottom button to download
After the download is a unity package, double-click the Import Project.
2. Download the corresponding AD package
Https://unity.fyber.com/docs/med-network-details
Note that the front is the iOS package, followed by the Android package
3. Import all packages to unity
4. Modify the Androidmanifest file under the Plugins/android folder
If there is no file created by yourself, I will give the full code of my file later.
Enter this connection:
Https://unity.fyber.com/docs/adding-the-bundles#Android Setupadmob https://unity.fyber.com/docs/ Adding-the-bundles#android Setupadmob
Select the ad you want to access:
When selected, the corresponding configuration code is given below:
Add the code to our Androidmanifest file.
Here is my androidmanifest file:
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.unity3d.player "xmlns:tools=" Http://schemas.android.com/tools "android:installlocation=" Preferexternal "android:versioncode=" 1 "android:versionname=" 1.0 "> <supports-screens android:smallscreens=" True "android:normalscreens=" true "android:largescreens=" true "android:xlargescreens=" true "android:anydensity=" True "/> <application android:theme=" @style/unitythemeselector "android:icon=" @drawable/app_icon "Android: Label= "@string/app_name" > <activity android:name= "com.unity3d.player.UnityPlayerActivity" android:label= "@ String/app_name "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> <categ Ory android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> <meta-data android:name= "Unityp Layer. Unityactivity "android:value=" true "/> </activity> <activity anDroid:name= "com.vungle.publisher.VideoFullScreenAdActivity" android:configchanges= "Orientation|screensize"/> <activity android:name= "com.tapjoy.TJAdUnitActivity" android:configchanges= "Orientation|screensize"/> < Activity android:name= "com.tapjoy.TJContentActivity" android:configchanges= "Orientation|screensize"/> <acti Vity android:name= "Com.tapjoy.mraid.view.ActionHandler" android:configchanges= "Orientation|screensize"/> <a Ctivity android:name= "Com.tapjoy.mraid.view.Browser" android:configchanges= "Orientation|screensize"/> <act
Ivity android:name= "com.unity3d.ads.adunit.AdUnitActivity" android:configchanges= "Orientation|screensize"/> <activity android:name= "com.fyber.unity.ads.OfferWallUnityActivity" android:configchanges= "orientation| ScreenSize "/> <activity android:name=" com.fyber.unity.ads.RewardedVideoUnityActivity "android:configchanges = "Screensize|orientation" android:theme= "@android: StylE/theme.translucent "android:hardwareaccelerated=" true "/> <activity android:name=" Com.fyber.ads.interstitials.InterstitialActivity "android:configchanges=" Screensize|orientation "Android:theme=" @android: Style/theme.translucent "/> <activity android:name=" com.fyber.utils.testsuite.TestSuiteActivity " android:label= "Integration Test Suite"/> <service android:name= "Com.fyber.cache.CacheVideoDownloadService" Android:exported= "false"/> </application> <uses-permission android:name= "Android.permission.INTERNET" /> <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/> </manifest>
Show ads
Here I have encapsulated the advertising-related methods:
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
namespace fyberplugin{public delegate void Addelegate (fybermanager.enadcallbackstate State, adformat format); <summary>//************//CREATE by Liufeng on 180104///************///All advertising related methods encapsulated in this class, convenient Different projects use///the effects of each ad refer to the Official document///reference: Https://unity.fyber.com/docs/integrating-sdk#section-android-manifest//* * * * Step 1: Call Initfyber When the game starts, initialize the SDK///2: All ads must first call the appropriate request method to load the ad///3: The load success will go to the callback method, more back Determine if the parameter is successful///4: After loading successfully, you can call the appropriate method to display the advertisement///************////NOTE:///This SDK only supports iOS and Android platforms and cannot be tested in the Unity editor
</summary> public static class Fybermanager {public enum enadcallbackstate {
--------Offerwall-----------Ready = 0x00000010,//ad is finished getfail = 0x00000011,//AD acquisition failed Showfail = 0x00000012,//Display failed Start = 0x00000013,//wideStart finished = 0x00000014,//ad is finished finishedaborted = 0x00000015,//the ad is closed}// /<summary>////related configuration Parameters//* * * * * * * * * * * * * * * * * * * * * *
T string app_id = "123456";
Private Const string Security_token = "ABCD"; <summary>///When the game starts, this method should be called to initialize the SDK///Initialize the ad plugin///C #-Start the Fyber Unity Plugin (RE Commended method)///</summary>//<param name= "mode" >//</param> PU Blic static void Initfyber () {//the securitytoken and appId is required, and can be found in the Set
Tings of your app in the Dashboard. Fyber.with (app_id). Withsecuritytoken (Security_token). Start (). Notifyuseronreward (False).
Notifyuseroncompletion (FALSE);
}//<summary>//Please note! First YOU request, then you display it. </summary>////***********************offerwall************************** static ADRe
Questcallback offerwallrequestcallback = new Adrequestcallback (); Prepare your ad in advance public static void Offerwallrequest (Addelegate d) {offerwallrequestcallback.setdelegate (d
); Offerwallrequester.create (). Withcallback (Offerwallrequestcallback).
Request ();
}//Display advertisement public static void Offerwallshow (Addelegate d) {Showad (offerwallrequestcallback,d); }//***********************rewardedvideo************************** static Adrequestcallback Rewar
Dedvideorequestcallback = new Adrequestcallback (); Prepare your ad in advance public static void Rewardedvideorequest (Addelegate d) {rewardedvideorequestcallb Ack.
Setdelegate (d); Rewardedvideorequester.create (). Withcallback (Rewardedvideorequestcallback). Request (); }//Display advertisement public static void Rewardedvideoshow (Addelegate d) {Showad (rewardedvideorequ
Estcallback, D); }//***********************interstitials************************** static Adrequestcallback Interstitials
Requestcallback = new Adrequestcallback (); Prepare your ad in advance public static void Interstitialsrequest (Addelegate d) {interstitialsrequestcallb Ack.
Setdelegate (d); Interstitialrequester.create (). Withcallback (Interstitialsrequestcallback).
Request (); }//Display advertisement public static void Interstitialsshow (Addelegate d) {Showad (interstitialsrequ
Estcallback, D); }//***********************banners************************** static Adrequestcallback BannersRequestCallba
ck = new Adrequestcallback (); Prepare your ad in advance public static void Bannersrequest (Addelegate d) {BANNERSREQUESTCALLBACK.SEtdelegate (d); Bannerrequester.create (). Withcallback (Bannersrequestcallback).
Request (); }//Display advertisement public static void Bannersshow (Addelegate d) {Showad (Bannersrequestcallback,
D); }//hiding and showing a started banner public static void Bannersactivity (bool isshow) {if (b Annersrequestcallback.ad = = null) {Debug.Log ("Bannersrequestcallback is null!!
Plase call the bannersrequest. ");
Return
} Bannerad Bannerad = Bannersrequestcallback.ad as Bannerad;
if (isshow) {bannerad.show ();
}else{bannerad.hide (); }}//destroying the banner public static void Bannersdestroy () {if (bannersrequestcal Lback. Ad = = null) {Debug.Log ("Bannersrequestcallback is null!!
Plase call the bannersrequest. ");
Return
} Bannerad Bannerad = bannersrequestcallback.ad as Bannerad;
Bannerad.destroy ();
Bannersrequestcallback.ad = null;
}//******************* display ad ******************* static void Showad (Adrequestcallback reqcb,addelegate D) {
if (REQCB = = null) {Debug.Log ("needs to be initialized before advertising needs to be played");
D (FyberManager.enAdCallBackState.ShowFail, Adformat.unknown);
Return
} adplaycallback adcallback = new Adplaycallback (); BOOL Isshow = REQCB.
Show (Adcallback);
if (isshow) {adcallback.setdelegate (d);
} else {d (FyberManager.enAdCallBackState.ShowFail, Adformat.unknown);
}}}//handling the asynchronous response after requesting the offer Wall//offerwall CALLBACK
public class Adrequestcallback:requestcallback { public ad AD;
Addelegate addelegate = null;
public void Setdelegate (Addelegate d) {addelegate = D;
} public void Onadavailable (AD AD) {//store ad ad = AD; if (addelegate! = null) addelegate (Fybermanager.enadcallbackstate.ready,ad.
Adformat);
} public void Onadnotavailable (Adformat adformat) {//Discard previous stored ad
Ad = null;
if (addelegate! = null) addelegate (Fybermanager.enadcallbackstate.getfail,adformat); } public void Onrequesterror (Requesterror error) {//Process error Debug.Log (' on Requesterror: "+ error.
Description);
if (addelegate! = null) addelegate (Fybermanager.enadcallbackstate.getfail,adformat.unknown); } public bool Show (Adplaycallback CB) {if (Ad! = null) {Ad.with Callback (CB). STart ();
Ad = null;
return true; } else {NGUIDebug.Log ("the ad data has not been acquired yet.
");
} return false;
}} public class Adplaycallback:adcallback {addelegate addelegate = null;
public void Setdelegate (Addelegate d) {addelegate = D; public void onadstarted (AD AD) {//This is where you mute the sound and toggle buttons if Necessary Debug.Log ("onadstarted. Ad "+ AD.
Adformat + "has started"); if (addelegate! = null) addelegate (Fybermanager.enadcallbackstate.start,ad.
Adformat); } public void onadfinished (Adresult result) {//This is the place where can resume the s Ound//reenable buttons, etc Debug.Log ("onadfinished. Ad "+ result. Adformat + "finished with status:" + result.
Status + "and message:" + result.
Message);
if (addelegate = = null) return; if (result. Message = = "Close_finished") {addelegate (FyberManager.enAdCallBackState.Finished, result.
Adformat); }else{addelegate (FyberManager.enAdCallBackState.FinishedAborted, result.
Adformat);
}
}
}
}
Remember to set app_id and Security_token as your backstage content.
Here are the test methods:
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
Using Fyberplugin;
[Executeineditmode] public class Adtest:monobehaviour {const int height = 70;
const int width = 200;
BOOL isOK = false;
Use the this for initialization void Start () {fybermanager.initfyber ();
Fyberlogger.enablelogging (TRUE);
Fybercallback.nativeerror + = ONNATIVEEXCEPTIONRECEIVEDFROMSDK;
Invoke ("Initfyber", 15f);
} void Initfyber () {isOK = true;
SDK initialization NGUIDebug.Log ("Fyber init finished!!!");
} int high;
void Ongui () {if (!isok) return;
High = 10;
if (createbtn ("Test")) {integrationanalyzer.showtestsuite ();
}//******************offerwall********************* if (createbtn ("Offerwall Request")) {
Fybermanager.offerwallrequest (Adcallback);
} if (Createbtn ("Offerwall Show")) {fybermanager.offerwallshow (adcallback);
}//******************rewardedvideo********************* if (createbtn ("Rewardedvideo Request"))
{fybermanager.rewardedvideorequest (adcallback);
} if (Createbtn ("Rewardedvideo Show")) {fybermanager.rewardedvideoshow (adcallback);
}//******************interstitials********************* if (createbtn ("interstitials Request"))
{fybermanager.interstitialsrequest (adcallback);
} if (Createbtn ("interstitials Show")) {fybermanager.interstitialsshow (adcallback);
}//******************banners********************* if (createbtn ("Banners Request")) {
Fybermanager.bannersrequest (Adcallback);
} if (Createbtn ("Banners Show")) {fybermanager.bannersshow (adcallback); } if (CreaTEBTN ("Banners Showing")) {fybermanager.bannersactivity (true);
} if (Createbtn ("Banners hiding")) {fybermanager.bannersactivity (false);
} if (Createbtn ("Banners destroying")) {Fybermanager.bannersdestroy (); }} public bool Createbtn (string btnname) {bool b = GUI.
Button (New Rect (SCREEN.WIDTH/2-WIDTH/2, high, width, height), btnname);
High + + height + 5;
return b; The public void Adcallback (fybermanager.enadcallbackstate State, Adformat format) {NGUIDebug.Log ("Adcallback:
"+ state +" format: "+ format);
Debug.Log ("Adcallback:" + state);
public void Onnativeexceptionreceivedfromsdk (String message) {NGUIDebug.Log ("message:" + message);
} void Ondisable () {fybercallback.nativeerror-= ONNATIVEEXCEPTIONRECEIVEDFROMSDK;
}
}
Every kind of advertisement is the same, the first request advertisement, the request succeeds only then can show.
It is normal to note that ad requests fail here, because sometimes the ad volume is too short to be assigned, if the request fails, just regain it.