﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System ;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using herousdk;
using herousdk.SimpleJSON;

public class EventHandle : HeroUSDKListener {

	public Text messageText ;
	
	private float time = 0;
	

	//截图屏幕图片进行保存
	public static string CameraShootAndSave()
	{
		string path = Application.persistentDataPath + "/" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
		Fun(Camera.main, path);
		Debug.LogError("截图成功,存放路径：" + Path.GetFullPath(path));
		return Path.GetFullPath(path);
	}
	public static void Fun(Camera m_Camera, string filename)
	{
		RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 16);
		m_Camera.targetTexture = rt;
		m_Camera.Render();

		RenderTexture.active = rt;
		Texture2D t = new Texture2D(Screen.width, Screen.height);
		t.ReadPixels(new Rect(0, 0, t.width, t.height), 0, 0);
		t.Apply();

		System.IO.File.WriteAllBytes(filename, t.EncodeToPNG());

		m_Camera.targetTexture = null;
		m_Camera.Render();
	}
	

	void showLog(string title, string message)
	{
		Debug.Log ("title: " + title + ", message: " + message);
		string messageString = "title: " + title + ", message: " + message + " \n\n" ;
		messageText.text += messageString ;
	}

	private void OnEnable()
	{
		
		
	}

	
	// Use this for initialization
	void Start () {

		showLog("lyy  start " ,"");

        HeroUSDK.getInstance ().setListener (this);
        
        HeroUProject project = new HeroUProject();
        project.usdkProductId = "12345678";
        project.usdkProductKey = "12345678";
        

#if UNITY_EDITOR_OSX || (UNITY_STANDALONE_OSX && !UNITY_EDITOR) || UNITY_STANDALONE_WIN
		
        HeroGameChannelProject channelProject = new HeroGameChannelProject();
        channelProject.productId = "D10385A";
        channelProject.projectId = "P37708A";
        channelProject.serverId = "M1375A";
        channelProject.appKey = "2WaqYKXAp4ojBG4GVdvv";
        channelProject.appSecret = "hwSL3Io21h0VlFEHdC9X";
        channelProject.cid = "237";
        
        // channelProject.productId = "D10309A";
        // channelProject.projectId = "P34345A";
        // channelProject.serverId = "M1257A";
        // channelProject.appKey = "VlZdSWMHVjgaxgVfaGl9";
        // channelProject.appSecret = "YFS3LsBe8sf3UvDiaYqd";
        // channelProject.cid = "199";
        channelProject.gameName = "PC测试游戏";
        channelProject.pkg = "com.hero.pc.sdk";
        project.gameChannelProject = channelProject;

        // HeroGlobalChannelProject globalChannelProject = new HeroGlobalChannelProject();
        /*
         * 测试环境参数
        globalChannelProject.gid = "2";
        globalChannelProject.pcode = "91";
        globalChannelProject.pk = "com.hero.pc.sdk";
        globalChannelProject.projectId = "10089";
        globalChannelProject.dn = SystemInfo.deviceUniqueIdentifier;
        globalChannelProject.appKey = "yukeeshatj9uk7khp310";
        globalChannelProject.cid = "251";
         */
         
        // globalChannelProject.gid = "32";
        // globalChannelProject.pcode = "305";
        // globalChannelProject.pk = "com.hero.pc.sdk";
        // globalChannelProject.projectId = "10302";
        // globalChannelProject.dn = SystemInfo.deviceUniqueIdentifier;
        // globalChannelProject.appKey = "km0qh5j9rtefm6pi67fx";
        // globalChannelProject.cid = "240";
        // globalChannelProject.facebookID = "803296624202545";
        // globalChannelProject.googleID = "21961700496-0ce3abad6s0ipblv4tn3jt8j8ajqhsic.apps.googleusercontent.com";
        // globalChannelProject.gameName = "全球PCDemo";
        // globalChannelProject.gameLogo = "https://img2.baidu.com/it/u=4285270887,923030815&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500";
        // globalChannelProject.globalServerUrl = "https://hgsdkcdn.herogame.com/hgsrv/";
        // project.globalChannelProject = globalChannelProject;
   
#endif
		//初始化SDK
		HeroUSDK.getInstance().initWithHeroUSDK(project);
		
		//USDK埋点回调
		HeroUSDK.getInstance().trackEventDataCallback();

#if UNITY_IOS && !UNITY_EDITOR

			//游戏播放完过渡视频上报闪屏
			HeroUSDK.getInstance().postSplashScreenEndSuccess();

#endif

		//屏蔽市场融合SDK默认埋点
		Dictionary<MARKET_EVENT, bool> bundle = new Dictionary<MARKET_EVENT, bool>();
		bundle.Add(MARKET_EVENT.MARKET_ALL,false);
		HeroUSDK.getInstance().setDisableMarketEvent(bundle);
		
		
	}
	// Update is called once per frame
	void Update () {
		if(Input.GetKeyDown(KeyCode.Escape))  
		{  
			
		}  
		//每秒执行
		// time += Time.deltaTime;
		// if (time >= 1)
		// {
		// 	time = 0;
		// 	Debug.LogError("EventHandle Update");
		// }
	}
	public void onLogin()
	{
		showLog("onLogin", "---------> start <-----------");
		HeroUSDK.getInstance ().login ();
	}
	public void onLogout()
	{
		showLog("onLogout", "---------> start <-----------");
		HeroUSDK.getInstance ().logout ();

	}
	public void onPay()
	{
		showLog("onPay", "---------> start <-----------");

		HeroUPaymentParameters orderInfo = new HeroUPaymentParameters();
		orderInfo.goodsId = "1000";
		orderInfo.extraParams = "HeroUGameRole";
		orderInfo.cpOrder = "cpOrderId_" + (System.DateTime.Now.ToFileTimeUtc()) / 1000 + "" ;
		orderInfo.callbackUrl = "callbackUrl" ;
		
		//根据各游戏需要传值不同
		HeroHDCGameRoleInfo gameRoleInfo = new HeroHDCGameRoleInfo();
		gameRoleInfo.channelUserId = "100128";
		gameRoleInfo.gameUserId = "100128";
		gameRoleInfo.serverId = "1";
		gameRoleInfo.serverName = "fire";
		gameRoleInfo.roleId = "000001";
		gameRoleInfo.roleName = "hotlucy";
		gameRoleInfo.roleAvatar = "";
		gameRoleInfo.level = "1";
		gameRoleInfo.vipLevel = "2";
		gameRoleInfo.gold1 = "3";
		gameRoleInfo.gold2 = "4";
		gameRoleInfo.sumPay = "5";
		
		HeroUSDK.getInstance ().pay (orderInfo, gameRoleInfo);
		
		Dictionary<string, string> paramters = new Dictionary<string, string>();
		paramters.Add("goodsId",orderInfo.goodsId);
		paramters.Add("extraParams",orderInfo.extraParams);
		paramters.Add("cpOrder",orderInfo.cpOrder);
		paramters.Add("callbackUrl",orderInfo.callbackUrl);
		//支付埋点
		HeroUSDK.getInstance().trackWithProperties("Pay",paramters);

	}
	public void onCreatRole(){

		showLog("onCreatRole", "---------> start <-----------");
		//注：基础信息必须先设置
		HeroHDCGameRoleInfo gameRoleInfo = new HeroHDCGameRoleInfo();
		gameRoleInfo.channelUserId = "100128";
		gameRoleInfo.gameUserId = "100128";
		gameRoleInfo.serverId = "1";
		gameRoleInfo.serverName = "火星服务器";
		gameRoleInfo.roleId = "000001";
		gameRoleInfo.roleName = "钱多多";
		gameRoleInfo.roleAvatar = "";
		gameRoleInfo.level = "1";
		gameRoleInfo.vipLevel = "2";
		gameRoleInfo.gold1 = "3";
		gameRoleInfo.gold2 = "4";
		gameRoleInfo.sumPay = "5";
		HeroUSDK.getInstance ().createNewRole(gameRoleInfo);//创建角色
		
		Dictionary<string, string> paramters = new Dictionary<string, string>();
		paramters.Add("roleId",gameRoleInfo.roleId);
		paramters.Add("roleName",gameRoleInfo.roleName);
		paramters.Add("roleAvatar",gameRoleInfo.roleAvatar);
		paramters.Add("serverId",gameRoleInfo.serverId);
		paramters.Add("serverName",gameRoleInfo.serverName);
		paramters.Add("level",gameRoleInfo.level);
		//创建角色埋点
		HeroUSDK.getInstance().trackWithProperties("CreateRole",paramters);
		
	}
	public void onEnterGame(){
		showLog("enterGame", "---------> start <-----------");
		//根据各游戏需要传值不同
		HeroHDCGameRoleInfo gameRoleInfo = new HeroHDCGameRoleInfo();
		gameRoleInfo.channelUserId = "100128";
		gameRoleInfo.gameUserId = "100128";
		gameRoleInfo.serverId = "1";
		gameRoleInfo.serverName = "火星服务器";
		gameRoleInfo.roleId = "000001";
		gameRoleInfo.roleName = "钱多多";
		gameRoleInfo.roleAvatar = "";
		gameRoleInfo.level = "1";
		gameRoleInfo.vipLevel = "2";
		gameRoleInfo.gold1 = "3";
		gameRoleInfo.gold2 = "4";
		gameRoleInfo.sumPay = "5";
		HeroUSDK.getInstance ().enterGame(gameRoleInfo);//角色登录
		
		Dictionary<string, string> paramters = new Dictionary<string, string>();
		paramters.Add("roleId",gameRoleInfo.roleId);
		paramters.Add("roleName",gameRoleInfo.roleName);
		paramters.Add("roleAvatar",gameRoleInfo.roleAvatar);
		paramters.Add("serverId",gameRoleInfo.serverId);
		paramters.Add("serverName",gameRoleInfo.serverName);
		paramters.Add("level",gameRoleInfo.level);
		//进入游戏埋点
		HeroUSDK.getInstance().trackWithProperties("EnterGame",paramters);
		
	}
	public void onRoleLevelUpAction()
	{
		showLog("roleLevelUp", "---------> start <-----------");

		HeroHDCGameRoleInfo gameRoleInfo = new HeroHDCGameRoleInfo();
		gameRoleInfo.channelUserId = "100128";
		gameRoleInfo.gameUserId = "100128";
		gameRoleInfo.serverId = "1";
		gameRoleInfo.serverName = "火星服务器";
		gameRoleInfo.roleId = "000001";
		gameRoleInfo.roleName = "钱多多";
		gameRoleInfo.roleAvatar = "";
		gameRoleInfo.level = "1";
		gameRoleInfo.vipLevel = "2";
		gameRoleInfo.gold1 = "3";
		gameRoleInfo.gold2 = "4";
		gameRoleInfo.sumPay = "5";
		HeroUSDK.getInstance ().roleLevelUp(gameRoleInfo);//角色升级
		
		Dictionary<string, string> paramters = new Dictionary<string, string>();
		paramters.Add("roleId",gameRoleInfo.roleId);
		paramters.Add("roleName",gameRoleInfo.roleName);
		paramters.Add("roleAvatar",gameRoleInfo.roleAvatar);
		paramters.Add("serverId",gameRoleInfo.serverId);
		paramters.Add("serverName",gameRoleInfo.serverName);
		paramters.Add("level",gameRoleInfo.level);
		//角色升级埋点
		HeroUSDK.getInstance().trackWithProperties("RoleLevelUp",paramters);
		
	}
	public void onSwitchAccount()
	{
		showLog("switchAccount", "---------> start <-----------");
		HeroUSDK.getInstance().switchAccount();
	}
	public void onExit(){
		
		showLog("exit", "---------> start <-----------");
#if UNITY_IOS && !UNITY_EDITOR

		Application.Quit();
	
#elif UNITY_ANDROID && !UNITY_EDITOR

             HeroUSDK.getInstance().exit();
#endif
	}
	/// <summary>
	/// 分享
	/// </summary>
	public void onShareAction()
	{
		ShareInfo shareInfo = new ShareInfo();
		shareInfo.sharePlatform = SharePlatform.HeroUSDKSharePlatformFaceBook;
		shareInfo.shareType = ShareType.HeroUSDKShareTypeImage;
		//截图
		string imagePath = CameraShootAndSave();
		shareInfo.imagePath = imagePath;
		HeroUSDK.getInstance().share(shareInfo);
	}
	/// <summary>
	/// 保存图片到相册
	/// </summary>
	public void onAddPicToAlbum()
	{
		string imagePath = CameraShootAndSave();
		string albumName = "HeroUSDK";
		HeroUSDK.getInstance().addPicToAlbum(imagePath,albumName);
	}
	/// <summary>
	/// 注销
	/// </summary>
	public void onCancellationAction()
	{
		showLog("注销", "---------> start <-----------");
		HeroUSDK.getInstance().accountCancellation();
	}
	public void onWithdrawAction()
	{
		showLog("撤回注销", "---------> start <-----------");
		HeroUSDK.getInstance().accountUnCancellation();
	}
	public void OnGlobalBindStateAction()
	{
		showLog("全球绑定状态", "---------> start <-----------");
		HeroUSDK.getInstance().getGlobalBindState();
	}
	public void OnXsollaPayAction()
	{
		showLog("打开Xsolla商城", "---------> start <-----------");
		Dictionary<string,string> xsollaParameters = new Dictionary<string, string>();
		xsollaParameters.Add("serverId","1");
		xsollaParameters.Add("serverName","火星服务器");
		xsollaParameters.Add("roleId","1000001");
		xsollaParameters.Add("roleName","钱多多");
		xsollaParameters.Add("cpUid","1000001");
		xsollaParameters.Add("isJumpOutBrowser","0");
		HeroUSDK.getInstance().startXsollaPayWithXsollaProperties(xsollaParameters);
	}
	public void OnShowAccountCenter()
	{
		showLog("用户中心", "---------> start <-----------");
		HeroUSDK.getInstance().showAccountCenter();
	}
	public void OnOpenBrowser()
	{
		showLog("打开内置浏览器", "---------> start <-----------");
		HeroUSDK.getInstance().openBrowser("test02");
	}
	//跳转到其他应用
	public void OnJumpToAPP()
	{
		/*
		 * https://www.youtube.com/channel/UC0mFPQiwt5556soJ543sIQg
			https://www.facebook.com/EternalEvolutionOfficial/
			https://twitter.com/EternalEvoluti4
			https://discord.gg/kdEvAknRV2
			https://www.tiktok.com/@eternal_evolution
			https://www.instagram.com/eternalevolution.official/
		 */
		//HeroUSDK.getInstance().jumpToApp("https://www.facebook.com/EternalEvolutionOfficial/");	
		
		
		HeroUSDK.getInstance().getGoogleSkuDetailsList("110002,110003,110004,110005,110006,110007");
	}
	/// <summary>
	/// 广告
	/// </summary>
	public void onAdAction()
	{
		//
		HeroUSDK.getInstance().showAdVideo("32562");
	}
	public void onGetAppsflyerOneLinkUrl()
	{
		Dictionary<string,string> appsLinkParams = new Dictionary<string, string>();
		string appsflyerUid = HeroUSDK.getInstance().getAppsflyerUID();
		showLog("AppsflyerUID", "---------> : " + appsflyerUid);
		appsLinkParams.Add("value",appsflyerUid);
		appsLinkParams.Add("sub1","sub1");
		appsLinkParams.Add("sub2","sub2");
		//获取邀请链接
		HeroUSDK.getInstance().getAppsflyerOneLinkUrl(appsLinkParams);
	}
	public void onGetAppsflyerOneLinkData()
	{
		//获取邀请链接
		string linkData = HeroUSDK.getInstance().getAppsflyerOneLinkData();
		showLog("AppsflyerOneLinkData", "---------> : " + linkData);
	}
	public void onResumeGame()
	{
		Time.timeScale = 1;
	}

	//************************************************************以下是需要实现的回调接口*************************************************************************************************************************
	//融合初始化回调
	public override void usdk_onInitCallBack(HeroUSDKResult result ,string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			showLog("onHeroUsdkInitSuccess", "msg: " + msg);
			Dictionary<string, string> paramters = new Dictionary<string, string>();
			paramters.Add("name","init");
			paramters.Add("value","success");
			HeroUSDK.getInstance().logEvent("usdk_init_success",paramters);
		}
		else
		{
			showLog("onHeroUsdkInitFailed", "msg: " + msg);
		}
	}
	//登录回调
	public override void usdk_onLoginCallBack(HeroUSDKResult result, UserInfo userInfo,string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			if (userInfo.plat == "android")
			{
				showLog("onHeroUsdkLoginSuccess for android ", "");
			}
			else if (userInfo.plat == "pc")
			{
				showLog("onHeroUsdkLoginSuccess for PC ", "");
			}
			else
			{
				showLog("onHeroUsdkLoginSuccess for iOS ", "");
			}
			
			showLog("sdkuserid :" + userInfo.sdkUserId, "");
			showLog("userName :" + userInfo.userName, "");

			int channelId = HeroUSDK.getInstance().getChannelId();
			string channelName = HeroUSDK.getInstance().getChannelName();
			string projectId = HeroUSDK.getInstance().getProjectId();
			string channelSdkVersionName = HeroUSDK.getInstance().getChannelSdkVersionName();
			
			showLog("channelId :" + channelId, "");
			showLog("channelName :" + channelName, "");
			showLog("projectId :" + projectId, "");
			showLog("channelSdkVersionName :" + channelSdkVersionName, "");
			
			Dictionary<string, string> paramters = new Dictionary<string, string>();
			paramters.Add("sdkUserId",userInfo.sdkUserId);
			paramters.Add("userName",userInfo.userName);
			//登录埋点
			HeroUSDK.getInstance().logEvent("usdk_Login_success",paramters);

			string protocolResult = HeroUSDK.getInstance().getProtocolResult();
			
			showLog("getProtocolResult", " : " + protocolResult);
			Debug.LogError("getProtocolResult：" + protocolResult);
		}
		else if (result == HeroUSDKResult.HeroUSDKResultFailed)
		{
			showLog("onHeroUsdkLoginFailed", "msg: " + msg);
		}
		else if (result == HeroUSDKResult.HeroUSDKResultCancel) {
			showLog("onHeroUsdkLoginCancel", "msg: " + msg);
		}
		
	}
	//切换账号回调
	public override void usdk_onSwitchAccountCallBack(HeroUSDKResult result, UserInfo userInfo,string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			if (userInfo.plat == "android")
			{
				showLog("onHeroUsdkSwitchAccountSuccess for android ", "");
			}
			else
			{
				showLog("onHeroUsdkSwitchAccountSuccess for iOS ", "");
			}
		}
		else if (result == HeroUSDKResult.HeroUSDKResultFailed) {
			showLog("onHeroUsdkSwitchAccountFailed", "msg: " + msg);
		}
		else if(result == HeroUSDKResult.HeroUSDKResultCancel)
		{
			showLog("onHeroUsdkSwitchAccountCancel", "msg: " + msg);
		}
	}
	//退出登录成功
	public override void usdk_onLogoutCallBack(HeroUSDKResult result, string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess) {
			showLog("onHeroUsdkLogoutSuccess", "");
		} else {
			showLog("onHeroUsdkLogoutFailed", "msg: " + msg); 
		}
	}
	//退出回调
	public override void usdk_onExitCallBack(HeroUSDKResult result, string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			showLog("onHeroUsdkExitSuccess", "");
			Application.Quit();
		}
		else {
			showLog("onHeroUsdkExitFailed", "msg: " + msg);
		}
	}
	//支付回调
	public override void usdk_onPayCallBack(HeroUSDKResult result, HeroUPaymentOrder payResult,string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			Dictionary<string, string> paramters = new Dictionary<string, string>();
			paramters.Add("orderId",payResult.orderId);
			if (payResult.plat == "android")
			{
				showLog("onHeroUsdkPaySuccess for android ", "");
				showLog("orderId: " + payResult.orderId, "");
				showLog("cpOrderId: " + payResult.cpOrderId, "");
				//支付日志上报
				double amount = 0 ;
				if (double.TryParse(payResult.orderAmount, out amount))
				{
					amount = double.Parse(payResult.orderAmount);
				}
				HeroUSDK.getInstance().logPurchaseWithOrderId(payResult.orderId,amount,payResult.currency,paramters);
			}
			else if (payResult.plat == "pc")
			{
				showLog("onHeroUsdkPaySuccess for PC ", "");
				showLog("orderId: " + payResult.orderId, "");
				showLog("orderAmount: " + payResult.orderAmount, "");
			}
			else
			{
				showLog("onHeroUsdkPaySuccess for iOS ", "");
				showLog("orderId: " + payResult.orderId, "");
				showLog("orderAmount: " + payResult.orderAmount, "");
				//支付日志上报
				double amount = 0 ;
				if (double.TryParse(payResult.orderAmount, out amount))
				{
					amount = double.Parse(payResult.orderAmount);
				}
				HeroUSDK.getInstance().logPurchaseWithOrderId(payResult.orderId,amount,payResult.currency,paramters);
			}
		}
		else if (result == HeroUSDKResult.HeroUSDKResultFailed)
		{
			showLog("onHeroUsdkPayFailed", "msg: " + msg);
		}
		else if (result == HeroUSDKResult.HeroUSDKResultCancel) {
			showLog("onHeroUsdkPayCancel", "msg: " + msg);
		}
	}
	//登录失效[防沉迷被踢下线]
	public override void usdk_onLoginInvalid(string msg)
	{
		showLog("onHeroUsdkLoginInvalid", "msg: " + msg);
	}
	//用户已经同意协议，在这里进行init等操作
	public override void usdk_onProtocolAgree()
	{
		showLog("onHeroUsdkAgree", "init here");
		Debug.Log(" >>>>>>>> onHeroUsdkAgree <<<<<<<<");

		//游戏初始化.
		Dictionary<string, string> paramters = new Dictionary<string, string>();
		paramters.Add("protocol","UsdkProtocol");
		//协议同意埋点
		HeroUSDK.getInstance().logEvent("Protocol",paramters);
	}
	public override void usdk_onShareCallBack(HeroUSDKResult result,SharePlatform sharePlatform, string msg)
	{
		if (result == HeroUSDKResult.HeroUSDKResultSuccess)
		{
			showLog("usdk_onShareCallBack Success", msg);
		}
		
		if (result == HeroUSDKResult.HeroUSDKResultFailed)
		{
			showLog("usdk_onShareCallBack Failed platform : " + sharePlatform + "", msg);
		}
		
	}
	public override void usdk_onAdCallBack(HeroUSDKAdResult result, string msg)
	{
		
	}
	//获取oaid回调
    public override void usdk_onGetOAIDResultAction(string msg)
    {
		showLog("onHeroUsdkGetOAIDResultAction", "OAID: " + msg);
		Debug.Log("oaid >>>> " + msg + "<<<<<<<<");
	}
    public override void usdk_onOpenBrowser(HeroUSDKResult result, string msg)
    {
	    showLog("usdk_onOpenBrowser ", "msg: " + msg);
	    
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("usdk_onOpenBrowser succcess", "msg: " + msg);
		    Debug.Log("usdk_onOpenBrowser >>>> " + msg + "<<<<<<<<");
	    }
	    else
	    {
		    showLog("usdk_onOpenBrowser fail", "msg: " + msg);
		    Debug.Log("usdk_onOpenBrowser >>>> " + msg + "<<<<<<<<");
	    }
	    
    }
    public override void usdk_onAccountCannellation(HeroUSDKResult result, string msg)
    {
	    showLog("usdk_onAccountCannellation ", "msg: " + msg);
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    //游戏这里需要退出登录，并返回到未登录界面
		    
	    }
    }
    public override void usdk_unAccountCancellation(HeroUSDKResult result, string msg)
    {
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("usdk_unAccountCancellation succcess", "msg: " + msg);
		    Debug.Log("usdk_unAccountCancellation >>>> " + msg + "<<<<<<<<");
	    }
	    else
	    {
		    showLog("usdk_unAccountCancellation fail", "msg: " + msg);
		    Debug.Log("usdk_unAccountCancellation >>>> " + msg + "<<<<<<<<");
	    }
    }
    public override void usdk_onTrackDataCallBack(string data)
    {
	    //showLog("onTrackDataCallBack", "data: " );
    }
    public override void usdk_onGetGlobalBindState(HeroUSDKResult result, string data, string msg)
    {
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("onGetGlobalBindState success", "data: " + data);
	    }
	    else
	    {
		    showLog("onGetGlobalBindState fail", "msg: " + msg);
	    }
    }
    public override void usdk_onBindAccountWithType(HeroUSDKResult result, string data, string msg)
    {
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("onBindAccountWithType success", "data: " + data);
	    }
	    else
	    {
		    showLog("onBindAccountWithType fail", "msg: " + msg);
	    }
    }
    public override void usdk_onScreenShotAction()
    {
	    string imagePath = CameraShootAndSave();
	    showLog("creenShotAction", "imagePath: " + imagePath);
	    ShareInfo shareInfo = new ShareInfo();
	    shareInfo.sharePlatform = SharePlatform.HeroUSDKSharePlatformFaceBook;
	    shareInfo.shareType = ShareType.HeroUSDKShareTypeImage;
	    //截图
	    shareInfo.imagePath = imagePath;
	    HeroUSDK.getInstance().share(shareInfo);
    }
    public override void usdk_onGetGoogleSkuDetailsList(HeroUSDKResult result, JSONArray data, string msg)
    {
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("GetGoogleSkuDetailsList Success", "msg: " + msg + "data : " + data);
		    foreach (JSONNode itemData in data)
		    {
			    //JSONNode itemNode =  JSONNode.Parse(itemData);
			    string usdkGoodsId =  itemData["usdkGoodsId"].Value ;
			    showLog("GetGoogleSkuDetailsList Success usdkGoodsId", "msg: " + usdkGoodsId);
		    }
	    }
	    else
	    {
		    showLog("GetGoogleSkuDetailsList Failed", "msg: " + msg);
	    }
    }
    public override void usdk_onGetAppsflyerUrl(HeroUSDKResult result, string url, string msg)
    {
	    if (result == HeroUSDKResult.HeroUSDKResultSuccess)
	    {
		    showLog("usdk_onGetAppsflyerUrl Succcess", "msg: " + url);
	    }
	    else
	    {
		    showLog("usdk_onGetAppsflyerUrl Failed", "msg: " + msg);
	    }
    }

    /// <summary>  
    /// 获取当前本地时间戳  
    /// </summary>  
    /// <returns></returns>        
    public long GetCurrentTimeUnix()  
	{  
		TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));  
		long t = (long)cha.TotalSeconds;  
		return t;  
	}  
}

