天天看點

unity整合物體_整合Unity廣告

unity整合物體_整合Unity廣告

unity整合物體

In this post we are going to look at Unity’s new ad service as well as how to integrate it into your current projects. Our goal is to make it easy to make money using your current (or hopefully future) player base with very little overhead and maintenance. We will see exactly what you need to do to integrate advertisements in your project (trust me, it’s not a lot), as well as some of the “gotchas” that might slow you down along the way.

在本文中,我們将研究Unity的新廣告服務以及如何将其內建到目前項目中。 我們的目标是讓您輕松利用目前(或希望将來)的玩家群賺錢,而所需的維護和維護卻很少。 我們将确切地看到您需要做些什麼來将廣告內建到您的項目中(相信我,并不多),以及一些可能使您放慢速度的“陷阱”。

建立您的帳戶 (Creating Your Account)

Setting up ads in a project is really only a couple of steps. The first thing you will need to do is go to the Unity Ads website and create an account (it’s free and only takes a few minutes). Once you are logged in, you will be presented with the Ads Dashboard. To begin monetizing your project, click “Start Monetizing” (you could also click the “Games” menu item on the left and then “Add New Game”).

在項目中設定廣告實際上僅需幾個步驟。 您需要做的第一件事是通路Unity Ads網站并建立一個帳戶(它是免費的,隻需幾分鐘)。 登入後,您将看到廣告儀表闆。 要開始通過項目獲利,請單擊“開始獲利”(您也可以單擊左側的“遊戲”菜單項,然後單擊“添加新遊戲”)。

unity整合物體_整合Unity廣告

You will then be prompted for some basic information regarding your project. Go ahead and specify your target platform and your project name. If your project is already deployed to market you can look it up. If your project is still in development, don’t worry. There is a link at the bottom you can click to add the development version to your account.

然後将提示您輸入有關項目的一些基本資訊。 繼續并指定您的目标平台和項目名稱。 如果您的項目已經部署到市場上,則可以進行查找。 如果您的項目仍在開發中,請不要擔心。 您可以單擊底部的連結,以将開發版本添加到您的帳戶。

unity整合物體_整合Unity廣告

An interesting takeaway here is that if your game is for both iOS and Android, you will create two different game profiles for the same game in your account. This means that you will have different ad IDs for both versions and thus will be able to track and manage your ads per platform instead of all together.

這裡有趣的一點是,如果您的遊戲同時适用于iOS和Android,則将為您的帳戶中的同一遊戲建立兩個不同的遊戲配置檔案。 這意味着您将在兩個版本中使用不同的廣告ID,進而能夠在每個平台上(而不是一起)跟蹤和管理廣告。

Now that your game is added to your Unity Ads account, you will be presented with your game dashboard. There are a lot of controls, options, and information panels here, but we are only going to concern ourselves with the “Game ID”. This ID is how we can control the ads shown as well as get the credit for any views or clicks our users provide.

現在您的遊戲已添加到Unity Ads帳戶中,您将看到遊戲儀表闆。 這裡有很多控件,選項和資訊面闆,但是我們隻關心“遊戲ID”。 此ID是我們控制展示的廣告以及獲得使用者提供的任何觀看次數或點選次數的功勞的方式。

unity整合物體_整合Unity廣告

(This image is from a sample game I have created for this article. I highly recommend you create your own account and game and not use my sample Game ID or else I will get all of the monetization credit for your games. That being said, if you feel like using my Game ID, I won’t stop you. Who doesn’t like free money?)

(此圖檔來自我為本文建立的示例遊戲。我強烈建議您建立自己的帳戶和遊戲,而不要使用示例遊戲ID,否則,我将獲得您遊戲的所有獲利點。如果您想使用我的遊戲ID,我不會阻止您。誰不喜歡免費的錢?)

将廣告整合到您的項目中 (Integrating Ads into Your Project)

Now that you have your Unity Ads account set up, you can begin showing ads in your project. From within Unity, navigate to the Asset Store (Window->Asset Store) and download and import the Unity Ads package. NOTE: currently there will be a warning if you are trying to download the package with Unity 5. This warning is due to the package being uploaded from Unity 4 and is harmless. It just exists currently for backwards compatibility.

現在,您已經設定了Unity Ads帳戶,您可以開始在項目中展示廣告。 從Unity内,導航到資産商店(“視窗”->“資産商店”),然後下載下傳并導入Unity Ads包。 注意:如果您嘗試使用Unity 5下載下傳軟體包,目前會出現警告。此警告是由于軟體包是從Unity 4上傳的,是以無害。 目前僅存在是為了向後相容。

unity整合物體_整合Unity廣告

Once the assets are imported into your project, initializing and showing ads is very simple.

将資産導入項目後,初始化和顯示廣告非常簡單。

NOTE: Since ads are currently only supported for iOS and Android, your editor will have to be targeting one of those platforms in order to see any test ads. Before going further you may want to switch your platform to either iOS or Android in the Unity build settings (File->Build Settings).

注意 :由于目前僅iOS和Android支援廣告,是以您的編輯器必須定位到這些平台之一才能檢視任何測試廣告。 在繼續之前,您可能需要在Unity建構設定(檔案->建構設定)中将平台切換到iOS或Android。

In a project, ads are controlled through scripts and there are three lines of code that are absolutely required (and one line of code that should be considered required). The first line is where we give our script access to the Advertisements namespace:

在一個項目中,廣告是通過腳本控制的,并且絕對需要三行代碼(而應該考慮一行代碼)。 第一行是讓腳本通路Advertisements命名空間的位置:

[csharp]using UnityEngine.Advertisements;[/csharp]

[csharp]使用UnityEngine.Advertisements; [/ csharp]

Next we must initialize our ads. This can be done anywhere you like, but it must be done before you attempt to show any ads. The first argument of the Initialize() function is the Game ID we got from the Unity Ads website (remember, use your own and not mine). The second argument is whether or not your game is in “test mode”. Generally speaking, while your game is in development you should always leave this as true. We will discuss this more later.

接下來,我們必須初始化廣告。 您可以在任何喜歡的地方進行此操作,但是必須先完成,然後再嘗試展示任何廣告。 Initialize()函數的第一個參數是我們從Unity Ads網站獲得的遊戲ID(請記住,請使用您自己的而不是我的)。 第二個參數是您的遊戲是否處于“測試模式”。 一般來說,在開發遊戲時,應始終将其保留為真。 我們将在後面讨論。

[csharp]Advertisement.Initialize ("29239", true);[/csharp]

[csharp] Advertisement.Initialize(“ 29239”,是); [/ csharp]

Finally we show an advertisement. If we are running our project in the editor we will see a generic billboard ad. If we are running this on device and test mode is set to true (see above) then we will see a placeholder ad. Finally, if we are on device and test mode is false we will see a real live ad.

最後,我們展示一個廣告。 如果我們在編輯器中運作項目,我們将看到一個通用的廣告牌廣告。 如果我們在裝置上運作此代碼,并且測試模式設定為true(請參見上文),那麼我們将看到一個占位符廣告。 最後,如果我們在裝置上并且測試模式為假,我們将看到一個真實的實時廣告。

[csharp]Advertisement.Show ();[/csharp]

[csharp] Advertisement.Show(); [/ csharp]

Now, initializing the ad system isn’t instantaneous, so you will want to ensure that an ad is ready before attempting to show it. Doing so can prevent errors or bugs that may otherwise plague your experience. You can check that an ad is ready to be shown by using the function isReady()

現在,初始化廣告系統不是立即進行的,是以您将需要確定在準備展示廣告之前準備好廣告。 這樣做可以防止可能會困擾您的體驗的錯誤或錯誤。 您可以使用isReady()函數檢查廣告是否已準備好展示

[csharp]Advertisement.isReady ();[/csharp]

[csharp] Advertisement.isReady(); [/ csharp]

So putting everything together, a simple script to just show an ad when your game starts up could look like this:

是以,将所有内容放在一起,一個簡單的腳本就可以在遊戲啟動時顯示廣告,如下所示:

[csharp]using UnityEngine; using UnityEngine.Advertisements; using System.Collections;

[csharp]使用UnityEngine; 使用UnityEngine.Advertisements; 使用System.Collections;

public class SimpleAdScript : MonoBehaviour { void Start () { Advertisement.Initialize ("29239", true);

公共類SimpleAdScript:MonoBehaviour {void Start(){Advertisement.Initialize(“ 29239”,true);

StartCoroutine (ShowAdWhenReady ()); }

StartCoroutine(ShowAdWhenReady()); }

IEnumerator ShowAdWhenReady() { while (!Advertisement.isReady ()) yield return null;

IEnumerator ShowAdWhenReady(){while(!Advertisement.isReady())yield return null;

Advertisement.Show (); } }[/csharp]

Advertisement.Show(); }} [/ csharp]

In the next post we will discuss more advanced ways of using ads as well as how we can build an ad structure using the concepts demonstrated here.

在下一篇文章中,我們将讨論使用廣告的更進階方法,以及如何使用此處示範的概念來建構廣告結構。

翻譯自: https://blogs.unity3d.com/2015/04/09/integrating-unity-ads/

unity整合物體