wangguan
2020-11-09 48daa4cb4b4484862ccf3db1e9ce4cbb38c17d04
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
56
57
58
59
60
61
62
63
using UnityEngine;
 
 
#if TDAA_STANDARD
public class TalkingDataShoppingCart
{
#if UNITY_ANDROID
    public AndroidJavaObject javaObj;
#endif
 
#if UNITY_IPHONE
    private string items = "";
#endif
 
    public static TalkingDataShoppingCart CreateShoppingCart()
    {
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
            TalkingDataShoppingCart shoppingCart = new TalkingDataShoppingCart();
#if UNITY_ANDROID
            AndroidJavaClass javaClass = new AndroidJavaClass("com.tendcloud.tenddata.ShoppingCart");
            shoppingCart.javaObj = javaClass.CallStatic<AndroidJavaObject>("createShoppingCart");
#endif
            return shoppingCart;
        }
        return null;
    }
 
    public TalkingDataShoppingCart AddItem(string itemId, string category, string name, int unitPrice, int amount)
    {
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
#if UNITY_ANDROID
            if (javaObj != null)
            {
                javaObj.Call<AndroidJavaObject>("addItem", itemId, category, name, unitPrice, amount);
            }
#endif
#if UNITY_IPHONE
            string item = "{\"itemId\":\"" + itemId + "\",\"category\":\"" + category + "\",\"name\":\"" + name + "\",\"unitPrice\":" + unitPrice + ",\"amount\":" + amount + "}";
            if (items.Length > 0)
            {
                items += ",";
            }
            items += item;
#endif
        }
        return this;
    }
 
#if UNITY_IPHONE
    public override string ToString()
    {
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
            string orderStr = "{\"items\":[" + items + "]}";
            return orderStr;
        }
        return null;
    }
#endif
}
#endif