美文网首页
unity添加友盟统计(支持Android和IOS)

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

作者: 下雨之後 | 来源:发表于2020-01-09 16:35 被阅读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

相关文章

网友评论

      本文标题:unity添加友盟统计(支持Android和IOS)

      本文链接:https://www.haomeiwen.com/subject/zroyactx.html