(出处: -【游戏蛮牛】-ar增强现实,虚拟现实,unity3d,unity3d教程下载首选u3d,unity3d官网)
前言:由于项目需要我接入苹果内购,但是我之前并没有接过任何SDK的经验,我是菜鸟一枚你懂得。所以只能各方求助、网上搜寻,谷歌百度能搜索就搜索。然后折腾3天,中间有点小插曲不然会更快,最后还是如愿弄出来啦。咱们还是记录一下,权当复习复习,而且网上的教程比较有点年头,有些比较复杂,正好我来发个简单点的方式~好像是 unity5 .3还是多少之后就集成了很多平台的内购,反正我用的是5.4.1,所以我们现在结这些内购接口还是很方便的!详情可以看看unity提供的官网文档
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
using
UnityEngine;
using
System.Collections;
using
UnityEngine.Purchasing;
public
class
PurchaseManager : MonoBehaviour, IStoreListener
{
public
BuyManager buyManager;
private
IStoreController controller;
void
Start()
{
var module = StandardPurchasingModule.Instance();
ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
builder.AddProduct(
"你设置的产品ID"
, ProductType.NonConsumable);
UnityPurchasing.Initialize(
this
, builder);
}
///
/// Called when Unity IAP is ready to make purchases.
///
public
void
OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
this
.controller = controller;
}
///
/// Called when Unity IAP encounters an unrecoverable initialization error.
///
/// Note that this will not be called if Internet is unavailable; Unity IAP
/// will attempt initialization until it becomes available.
///
public
void
OnInitializeFailed(InitializationFailureReason error)
{
}
///
/// Called when a purchase completes.
///
/// May be called at any time after OnInitialized().
///
public
PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
{
return
PurchaseProcessingResult.Complete;
}
///
/// Called when a purchase fails.
///
public
void
OnPurchaseFailed(Product item, PurchaseFailureReason r)
{
}
}
|
1
2
3
|
public void OnPurchaseClicked
(
string
productId
)
{
controller.InitiatePurchase
(
productId
)
;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
using
UnityEngine;
using
System.Collections;
using
UnityEngine.Purchasing;
public
class
PurchaseManager
:
MonoBehaviour
,
IStoreListener
{
public BuyManager buyManager;
private IStoreController controller;
void Start
(
)
{
var module
=
StandardPurchasingModule.Instance
(
)
;
ConfigurationBuilder builder
=
ConfigurationBuilder.Instance
(
module
)
;
builder.AddProduct
(
"com.Minesweeper.Init15"
,
ProductType.NonConsumable
)
;
builder.AddProduct
(
"com.Minesweeper.Init25"
,
ProductType.NonConsumable
)
;
UnityPurchasing.Initialize
(
this
,
builder
)
;
}
/
/
/
<
summary
>
/
/
/
Called when Unity IAP
is
ready
to
make
purchases.
/
/
/
<
/
summary
>
public void OnInitialized
(
IStoreController controller
,
IExtensionProvider extensions
)
{
this.controller
=
controller;
}
/
/
/
<
summary
>
/
/
/
Called when Unity IAP encounters an unrecoverable initialization
error
.
/
/
/
/
/
/
Note
that
this will
not
be called
if
Internet
is
unavailable; Unity IAP
/
/
/
will attempt initialization until
it
becomes available.
/
/
/
<
/
summary
>
public void OnInitializeFailed
(
InitializationFailureReason
error
)
{
}
/
/
/
<
summary
>
/
/
/
Called when a purchase completes.
/
/
/
/
/
/
May be called
at
any time
after
OnInitialized
(
)
.
/
/
/
<
/
summary
>
public PurchaseProcessingResult ProcessPurchase
(
PurchaseEventArgs e
)
{
return
PurchaseProcessingResult.Complete;
}
/
/
/
<
summary
>
/
/
/
Called when a purchase fails.
/
/
/
<
/
summary
>
public void OnPurchaseFailed
(
Product
item
,
PurchaseFailureReason r
)
{
}
public void OnPurchaseClicked
(
string
productId
)
{
controller.InitiatePurchase
(
productId
)
;
}
}
|