简体 EN 繁体

Get Start For Unity 1.8.4

Index

1、Import TGSDK to project

First, download the latest and TGSDK official version from Yomob Official Website SDK Download Page. After decompression, you can import TGSDK.unity.x.x.x.x.x.unitypackage file into your Unity project. Currently, we only support Unity version over 5.x. Please contact us if you need to use Unity 4.x and older version.

Note: Currently, we only support Unity version over 5.x. Please contact us if you need to use Unity 4.x and older version.

Android set initializing Activity

Note:Please set the default Activity class in Assets/Plugins/Android/AndroidManifest.xml as below:

com.soulgame.sgsdk.tgsdklib.unity.TGSDKUnityActivity

Please also ensure your project’s initializing Activity Class is the same as the above Class or its sub-Class. If you have self defined your own initializing Activity Class, you need to add the below methods into your own Activity Class:

Note: If you are not extending TGSDK Activity and use yours, please don't forget to call the method with same name of TGSDK in the callback method of Activity during its life cycle.

class YourCustomActivity extends UnityPlayerActivity {

    @Override
    protected void onStart() {
        TGSDK.onStart(this);
        super.onStart();
    }

    @Override
    protected void onStop() {
        TGSDK.onStop(this);
        super.onStop();
    }

    @Override
    protected void onPause() {
        TGSDK.onPause(this);
        super.onPause();
    }

    @Override
    protected void onResume() {
        TGSDK.onResume(this);
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        TGSDK.onDestroy(this);
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int reqCode, int resCode, Intent data) {
        TGSDK.onActivityResult(this, reqCode, resCode, data);
        super.onActivityResult(reqCode, resCode, data);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

        TGSDK.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

Add support for Google Play Service

If your App is for Google Play Store. Then you need to import Google Play Services since some Ads networks require the support for this service.

For the detail regarding Google Play Services integration, please refer to Google Official Developer Guides.

Note: you don't need to import all Google Play Services library into your project. The libraries required are as below:

com.google.android.gms:play-services-ads-15.0.1

com.google.android.gms:play-services-ads-base-15.0.1

com.google.android.gms:play-services-ads-identifier-15.0.1
com.google.android.gms:play-services-ads-lite-15.0.1
com.google.android.gms:play-services-location-15.0.1
com.google.android.gms:play-services-basement-15.0.1

How to add Google Play Services into Unity projects

Google Official Developer GuidesGoogle official developer document does not describe how to add its service into Unity project in detail. Please manually download aar file from here copy and paste required aar files into the libs folder under TGSDK folder as below:

Assets/Plugins/Android/libs

Add Android Support V4 library

Note: Android Support v4 is forced dependency,please include it into your project. The version of the Android Support v4 lib has to be above v26, or else the build might have issue!

Some Ad networks require android.support.v4 library. Therefore, please import the library into your project. The import steps are the same as Google Play Service. You just need to copy and paste the android.support.v4 library from below path of the Android SDK folder into your own project.

Your-Android-SDK-Path/extras/android/m2repository/com/android/support/support-v4

You can also copy and paste the aar file of android.support.v4 into TGSDK libs folder as below:

Assets/Plugins/Android/libs

The TGSDK version v1.6.2 or above v4 support lib by default。If you use TGSDK version below v1.6.2,you have to add v4 support lib manually. You can find the aar library under Android SDK with path below:

Your-Android-SDK-Path/extras/android/m2repository/com/android/support/support-v4

About Android 7.0 permissions

1.Modify ${applicationId} to the package name of the app in the Application tab in AndroidManifest.xml

2.Add up to the proguard configuration file:

-keep class android.support.v4.**{ *;}

Avoid FileProvider code confusion in support-V4 packages.

iOS Project BitCode Support

Since version 1.6.1 for iOS(Include Unity)的TGSDK supports iOS BitCode technology,developers can enable BitCode support in your project.

Note: Support BitCode will increase the size of TGSDK as well as the build package,however the App download size from Apple App Store will be more less then original size. Therefore, developers can safely enable BitCode support once needed

2、Initialize TGSDK

After registering account and creating your App on Yomob Official Website, you will acquire the corresponding product AppID from the website, and then use this parameter to initialize TGSDK

If you need to launch your App in mainland China within different Chinese Android App Stores, please follow the steps of 《Launch on Chinese Android Channels》 for initialization.

using Together;

TGSDK.Initialize("Your application ID from yomob");

3、Preload Ads Resources

To have enough time to load ads resources, it is recommended to call the preload API to load ads as early as possible. You can even call the preload API to load ads as soon as you initialize TGSDK.  

using Together;

TGSDK.PreloadAd();

Note: The package name or Bundle ID must match with the one you have registered under the App config in YoMob. Or else, you might not be able to load and play the ads

4、Play Ads

First, please create ad scenes for the registered App via Yomob Official Website. After acquiring the corresponding Ad scene ID, you can use it to verify whether the ads are ready. If the ads of the corresponding scene are ready, the video ads play API can be called to play the ads.

using Together;

if (TGSDK.CouldShowAd("Your scene ID from yomob")) {
    TGSDK.ShowAd("Your scene ID from yomob");
}

5、Banner Ad Play

For the specificity of banner ads, you need to set the type and location of the banner ad in advance:

TGSDK.SetBannerConfig(String scene, string type, 
                      float x, float y, 
                      float width, float height, 
                      int interval);

Parameter explanation:

  • scene Banner ad corresponds to the registered ad scene ID

  • type Banner ad size type, which is divided into three types:

String corresponding to the Banner type Banner Size
TGBannerNormal 320*50
TGBannerLarge 320*90
TGBannerMediumRectangle 300*250
  • x, y Banner The X coordinate and Y coordinate of the position where the position is placed, in px

  • width, height Banner The width and height of the ad reserved placement, in px

  • interval Banner The interval between ad rotations to switch ad content, in seconds

The coordinates are zero in the upper left corner of the screen, and the interval is the carousel time in seconds. It is recommended to be in the range of 30-120. Show Banner ads:

if (TGSDK.CouldShowAd("Your scene ID from yomob")) {
    TGSDK.ShowAd("Your scene ID from yomob");
}

You can also turn off Banner ads when needed:

TGSDK.CloseBanner("Scene ID");

[Note] When you don't need to show Banner ads or the view that displays Banner ads is turned off, please call the [TGSDK closeBanner:@"Scene ID"] method to manually close the Banner ad, otherwise it will affect the next Once the banner advertisement is displayed normally.

6、Advanced Usage

Enable Debug mode

After enabling Debug mode, you can view the output of much more logs. This is convenient for locating problems.

Note: Do not use Debug mode under a production environment. In addition, if it is necessary to enable Debug mode, set Debug mode enabled before calling the initialization API.

using Together;

TGSDK.SetDebugModel(true);

Set monitoring on ads preload event

PreloadAd method can generate some event notifications during ads loading process via Callback. For instance:

// Use lambda expression
// PreloadAd method Callback success
TGSDK.PreloadAdSuccessCallback = (string ret) => {
};
// PreloadAd method Callback fail
TGSDK.PreloadAdFailedCallback = (string error) => {
};
// AwardVideo is ready
TGSDK.AwardVideoLoadedCallback = (string ret) => {
};
// InterstitialVideo is ready
TGSDK.InterstitialVideoLoadedCallback = (string ret) => {
};
// Interstitial is ready
TGSDK.InterstitialLoadedCallback = (string ret) => {
};


// Use Action<string>
public void OnPreloadAdSuccess(string ret) {
}
TGSDK.PreloadAdSuccessCallback = OnPreloadAdSuccess;

public void OnPreloadAdFailed(string error) {
}
TGSDK.PreloadAdFailedCallback = OnPreloadAdFailed;

public void OnAwardVideoLoadedCallback(string ret) {
}
TGSDK.AwardVideoLoadedCallback = OnAwardVideoLoadedCallback;

public void OnInterstitialVideoLoadedCallback(string ret) {
}
TGSDK.InterstitialVideoLoadedCallback = OnInterstitialVideoLoadedCallback;

public void OnInterstitialLoadedCallback(string ret) {
}
TGSDK.InterstitialLoadedCallback = OnInterstitialLoadedCallback;

You can monitor the loading process of your ad with a delegate.

Set monitoring on ads playing behavior event

ShowAd method can generate some event notifications during ads loading process via Callback. For instance:

// Use lambda expression
// Ads play success Callback
TGSDK.AdShowSuccessCallback = (string scene, string name) => {
};
// Ad playback failure callback
TGSDK.AdShowFailedCallback = (string scene, string name, string error) => {
};
// The ad closes the callback, and whether the reward is in the third parameter award
TGSDK.AdCloseCallback = (string scene, string name, bool award) => {
};
// The callback of the ad clicked by the user
TGSDK.AdClickCallback = (string scene, string name) => {
};

// 使用 Action<string>
public void OnAdShowSuccess(string scene, string name) {
}
TGSDK.AdShowSuccessCallback = OnAdShowSuccess;

public void OnAdShowFailed(string scene, string name, string error) {
}
TGSDK.AdShowFailedCallback = OnAdShowFailed;

public void OnAdClose(string scene, string name, bool award) {
}
TGSDK.AdCloseCallback = OnAdClose;

public void OnAdClick(string scene, string name) {
}
TGSDK.AdClickCallback = OnAdClick;

[Note] TGSDK.AdShowFailedCallback After the callback, the Banner ad failed to load, the ad is not displayed properly, you need to manually call TGSDK.CloseBanner to close the currently displayed Banner, and then try to call TGSDK.ShowAd again. Banner advertisement.

Ads Test Tool

This functionality is only available in TGSDK with version 1.6.5 or above,we recommend you to upgrade your TGSDK for better experience

Please do not use this function in production environment. It is only for testing

During test phase, you can use APIs provided by Ads Test Tool instead of original ads API to better test your in App ads view logic.

Use Ads Test Tool API

TGSDK.ShowTestView("Your scene id from Yomob");

Instead of useing original API

TGSDK.ShowAd("Your scene id from Yomob");

The below UI will popup,you can test the Ads plugins included by test watching the available ads provided by these Ads networks included.

TGSDK_showTestView TGSDK_showTestView

Report users ads watching behavior

To better analyze users ad watching behaviors, optimize ad viewing experience, and improve ad revenues of the products, we recommend that the data of the ads watching behaviors can be reported actively via related APIs to enhance users’ ad viewing experience.

Report ads presentation behavior

TGSDK iOS Report Ads Presentation Behavior

As shown in the figure above, if the user has noticed that the product will have ads playing behavior via product UI or the product presents the controls that can be used by the user to choose whether to play the ads or not via UI, the corresponding behavior should be reported to TGSDK. For example, the product shown in the figure above presents the ads playing button, then the user can choose whether to play the ads in order to acquire bonus. At this time, this behavior should be reported to TGSDK.

TGSDK.ShowAdScene("Your scene ID from yomob");

Report ads watching rejection behavior of users

TGSDK iOS Ads Watching Rejection Behavior

As shown in the figure above, if the user has noticed that the product will have ads playing behavior, and then the user rejects or gives up on playing the ads, the corresponding behavior can be reported to TGSDK at this time. For example, the user views the ads playing button UI and knows that the bonus can be acquired via watching an ads, but the user gives up. At this time, this behavior should be reported to the TGSDK.

TGSDK.ReportAdRejected("Your scene ID from yomob");

Launch on Chinese Android Channels

Chinese Android App Stores are very complicated. If you need to launch your App on Chinese Android App Stores, you should pass specific ChannelId during your initialization step. The ChannelId can be found on YoMob App Setting or Chinese Android Channel List

using Together;

#if UNITY_IOS && !UNITY_EDITOR
TGSDK.Initialize("Your application id from yomob");
#elif UNITY_ANDROID && !UNITY_EDITOR
TGSDK.Initialize("Your application id", "Your Channel id");
#endif

In order to make the initialization step easier when generating a different APK for different Chinese Android App Stores, we support initialization from AndroidManifest.xml file to get AppID and ChannelID. You need to add the below two settings in the AndroidManifest.xml file of your project.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.soulgame.tgsdksampleapp.android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!-- Initialize TGSDK -->
        <meta-data android:name="TGSDK_APPID" android:value="Your application id from Yomob" />
        <meta-data android:name="TGSDK_CHANNELID" android:value="Your channel id of app store" />

        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

Once you have set AppID and ChannelID in your AndroidManifest.xml file, then you don't need to pass in both two parameters during TGSDK initialization phase.

using Together

#if UNITY_IOS && !UNITY_EDITOR
TGSDK.Initialize("Your application id from yomob");
#elif UNITY_ANDROID && !UNITY_EDITOR
TGSDK.Initialize();
#endif

Note: Since Unity also supports iOS, you can follow the below steps to add two settings in Info.plist file if you still need to initialize TGSDK without passing in AppID and ChannelID on the iOS platform

<key>TGSDK_APPID</key>
<string>Your application id from Yomob</string>
<key>TGSDK_CHANNELID</key>
<string>10006</string>

Chinese Android App Store Channels

Channel IDName
10000Official Web
10010360 Mobile Assistant
10040Myapp
10009Xiaomi App Store
10041Baidu Mobile Assistant
10029Huawei App Stpre
10042HiMarket
10024Vivo
10035GooglePlay
10023Oppo Store
10037Wandoujia
10017Anzhi Market
10043Meizu App Store
1000491 Mobile Assistant
10034China Unicom Wostore
10012Lenovo Store
10026Coolpad Store
10028Sogou Mobile Assistant
10044Gionee Anzhuoapk
10032China Telecom Tianyi Store
10033China Mobile Store
10001Kuaiyong Sotre:
10003PP Assistant
10002Tongbutui
10005iToos
10008Yiwan
10011Muzhiwan
10013Kingsoft App Store
10015Haima
10016Dangle
10018UC Web Store
10030Youku
10038Zhuoyi Market
10045Mobile QQ
10046Wechat Game
10047Tencent Mobile Game
100484399 Game
10049Letv Game
10050Tiantian Game
10021Yingyonghui
10051Sina Game
10052Netease Game
10053Taptap
10054Kuan
10055CCPlay
10056Pengyouwan
10057Youpinwei