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网站并创建一个帐户(它是免费的,只需几分钟)。 登录后,您将看到广告仪表板。 要开始通过项目获利,请单击“开始获利”(您也可以单击左侧的“游戏”菜单项,然后单击“添加新游戏”)。

Monetize Users

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.

然后将提示您输入有关项目的一些基本信息。 继续并指定您的目标平台和项目名称。 如果您的项目已经部署到市场上,则可以进行查找。 如果您的项目仍在开发中,请不要担心。 您可以单击底部的链接,以将开发版本添加到您的帐户。

Screen Shot 2015-03-31 at 1.15.46 PM

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是我们控制展示的广告以及获得用户提供的任何观看次数或点击次数的功劳的方式。

Screen Shot 2015-03-31 at 1.17.29 PM

(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上传的,因此无害。 当前仅存在是为了向后兼容。

Screen Shot 2015-03-31 at 2.32.14 PM

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整合物体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值