wangguan
2020-10-27 06430ef49a970c718e10c1ef8154d969e9906401
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
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using UnityEngine;
 
public class GA_SDK_Manager : MonoBehaviour
{
    private static GA_SDK_Manager _Ins;
    public static GA_SDK_Manager Ins
    {
        get
        {
            return _Ins;
        }
    }
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        _Ins = this;
    }
 
    public string GetDeviceId()
    {
        return TalkingDataGA.GetDeviceId();
    }
 
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="channelId">渠道id</param>
    public void SDKInit(string channelId)
    {
        Debug.Log("Unity SDK  init begin channelId:" + channelId);
        TalkingDataGA.BackgroundSessionEnabled();
        TalkingDataGA.OnStart("B220F5C737384030947B202F19E32086", channelId);//appID是定死的
        Debug.Log("Unity SDK  init completed ");
    }
 
    TDGAAccount account;//当前账户
 
    /// <summary>
    /// 登录,使用自定义的
    /// </summary>
    /// <param name="deviceID"></param>
    public void Login(string deviceID)
    {
        account = TDGAAccount.SetAccount(TalkingDataGA.GetDeviceId());
        account.SetAccountType(AccountType.ANONYMOUS);
    }
 
 
    /// <summary>
    /// 使用自定义事件
    /// </summary>
    /// <param name="actionId">事件名称</param>
    /// <param name="dic">需要传递的值</param>
    public void OnEvent(string actionId, Dictionary<string, object> dic)
    {
        //示例:
        // Dictionary<string, object> dic = new Dictionary<string, object>
        // {
        //     { "StringValue", "Pi" },
        //     { "NumberValue", 3.14 }
        // };
        // TalkingDataGA.OnEvent("action_id", dic);
 
        TalkingDataGA.OnEvent(actionId, dic);
    }
 
    private void OnDestroy()
    {
        Debug.Log("onDestroy");
        TalkingDataGA.OnEnd();
    }
}