wangguan
2020-10-22 7a007a8d1e7cd712fa4571efdbc3f2eba7a7e4d0
1
2
3
4
5
6
7
8
9
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
using UnityEngine;
#if UNITY_IPHONE
using System.Runtime.InteropServices;
#endif
 
 
public static class TDGAItem
{
#if UNITY_ANDROID
    private static readonly string ITEM_CLASS = "com.tendcloud.tenddata.TDGAItem";
    private static AndroidJavaClass itemClass;
#endif
 
#if UNITY_IPHONE
    [DllImport("__Internal")]
    private static extern void TDGAOnPurchase(string item, int itemNumber, double priceInVirtualCurrency);
 
    [DllImport("__Internal")]
    private static extern void TDGAOnUse(string item, int itemNumber);
#endif
 
    public static void OnPurchase(string item, int itemNumber, double priceInVirtualCurrency)
    {
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
#if UNITY_ANDROID
            if (itemClass == null)
            {
                itemClass = new AndroidJavaClass(ITEM_CLASS);
            }
            itemClass.CallStatic("onPurchase", item, itemNumber, priceInVirtualCurrency);
#endif
#if UNITY_IPHONE
            TDGAOnPurchase(item, itemNumber, priceInVirtualCurrency);
#endif
        }
    }
 
    public static void OnUse(string item, int itemNumber)
    {
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
#if UNITY_ANDROID
            if (itemClass == null)
            {
                itemClass = new AndroidJavaClass(ITEM_CLASS);
            }
            itemClass.CallStatic("onUse", item, itemNumber);
#endif
#if UNITY_IPHONE
            TDGAOnUse(item, itemNumber);
#endif
        }
    }
}