unity添加友盟统计(支持Android和IOS)

2020-01-09  本文已影响0人  下雨之後
using UnityEngine;
using System.Collections;
using Umeng;
public class UmengManager : MonoBehaviour
{
    static string appkey;

    void Awake()
    {
        DontDestroyOnLoad (transform.gameObject);
    }
    // Use this for initialization  
    void Start()
    {
#if UNITY_ANDROID
        //导入app key 标识应用 (Android)  
        appkey = "$$$$$$$$$$$$$$$$$$$$$$$";
#elif UNITY_IPHONE
         //导入app key 标识应用 (ios)  
        appkey = "$$$$$$$$$$$$$$$$$$$$$$$";
#endif

        //设置Umeng Appkey    
        GA.StartWithAppKeyAndChannelId(appkey, "App Store");

        //调试时开启日志 发布时设置为false  
        GA.SetLogEnabled(false);

        //触发统计事件 开始关卡         
        GA.StartLevel("your level ID");
    }

    // Update is called once per frame  
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            //结束程序  
            GA.FinishLevel("your level ID");
            Application.Quit();
        }
    }
#if UNITY_ANDROID

    void OnApplicationPause(bool isPause)
    {
        
        //Debug.Log("Umeng:OnApplicationPause" + isPause);
        if (isPause){
            //Debug.Log("Umeng:----onPause");
            GA.onPause();
        }
        else{
            //Debug.Log("Umeng:----onResume");
            GA.onResume();
        }
    }
    void OnApplicationQuit()
    {
        //Debug.Log("Umeng:OnApplicationQuit");
        GA.onKillProcess();
    }
    #endif 
}

参考:http://www.mamicode.com/info-detail-2137630.html

上一篇 下一篇

猜你喜欢

热点阅读