123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- // version: 5.0.1
- using UnityEngine;
- using System.Collections.Generic;
- #if UNITY_ANDROID
- using System;
- #endif
- #if UNITY_IPHONE
- using System.Runtime.InteropServices;
- using System.Collections;
- #endif
- public static class TalkingDataSDK
- {
- #if UNITY_ANDROID
- private static readonly string TALKINGDATA_CLASS = "com.tendcloud.tenddata.TalkingDataSDK";
- private static AndroidJavaClass talkingdataClass;
- private static AndroidJavaClass unityPlayerClass;
- #endif
- #if UNITY_IPHONE
- [DllImport("__Internal")]
- private static extern void TDInit(string appId, string channelId, string custom);
- [DllImport("__Internal")]
- private static extern void TDBackgroundSessionEnabled();
- [DllImport("__Internal")]
- private static extern string TDGetDeviceId();
- [DllImport("__Internal")]
- private static extern void TDSetVerboseLogDisable();
- [DllImport("__Internal")]
- private static extern void TDSetLocation(double latitude, double longitude);
- [DllImport("__Internal")]
- private static extern void TDOnPageBegin(string pageName);
- [DllImport("__Internal")]
- private static extern void TDOnPageEnd(string pageName);
- [DllImport("__Internal")]
- private static extern void TDOnReceiveDeepLink(string url);
- [DllImport("__Internal")]
- private static extern void TDOnRegister(string profileId, string profileJson, string invitationCode);
- [DllImport("__Internal")]
- private static extern void TDOnLogin(string profileId, string profileJson);
- [DllImport("__Internal")]
- private static extern void TDOnProfileUpdate(string profileJson);
- [DllImport("__Internal")]
- private static extern void TDOnCreateCard(string profileId, string method, string content);
- [DllImport("__Internal")]
- private static extern void TDOnFavorite(string category, string content);
- [DllImport("__Internal")]
- private static extern void TDOnShare(string profileId, string content);
- [DllImport("__Internal")]
- private static extern void TDOnPunch(string profileId, string punchId);
- [DllImport("__Internal")]
- private static extern void TDOnSearch(string searchJson);
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- [DllImport("__Internal")]
- private static extern void TDOnContact(string profileId, string content);
- #endif
- #if TD_GAME || TD_TOUR || TD_ONLINEEDU || TD_READING || TD_OTHER
- [DllImport("__Internal")]
- private static extern void TDOnPay(string profileId, string orderId, int amount, string currencyType, string paymentType, string itemId, int itemCount);
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- [DllImport("__Internal")]
- private static extern void TDOnChargeBack(string profileId, string orderId, string reason, string type);
- #endif
- #if TD_FINANCE || TD_ONLINEEDU
- [DllImport("__Internal")]
- private static extern void TDOnReservation(string profileId, string reservationId, string category, int amount, string term);
- #endif
- #if TD_RETAIL || TD_TOUR
- [DllImport("__Internal")]
- private static extern void TDOnBooking(string profileId, string bookingId, string category, int amount, string content);
- #endif
- #if TD_RETAIL
- [DllImport("__Internal")]
- private static extern void TDOnViewItem(string itemId, string category, string name, int unitPrice);
- [DllImport("__Internal")]
- private static extern void TDOnAddItemToShoppingCart(string item, string category, string name, int unitPrice, int amount);
- [DllImport("__Internal")]
- private static extern void TDOnViewShoppingCart(string shoppingCartJson);
- [DllImport("__Internal")]
- private static extern void TDOnPlaceOrder(string orderJson, string profileId);
- [DllImport("__Internal")]
- private static extern void TDOnOrderPaySucc(string orderJson, string paymentType, string profileId);
- [DllImport("__Internal")]
- private static extern void TDOnCancelOrder(string orderJson);
- #endif
- #if TD_FINANCE
- [DllImport("__Internal")]
- private static extern void TDOnCredit(string profileId, int amount, string content);
- [DllImport("__Internal")]
- private static extern void TDOnTransaction(string profileId, string transactionJson);
- #endif
- #if TD_GAME
- [DllImport("__Internal")]
- private static extern void TDOnCreateRole(string name);
- [DllImport("__Internal")]
- private static extern void TDOnLevelPass(string profileId, string levelId);
- [DllImport("__Internal")]
- private static extern void TDOnGuideFinished(string profileId, string content);
- #endif
- #if TD_ONLINEEDU
- [DllImport("__Internal")]
- private static extern void TDOnLearn(string profileId, string course, long begin, int duration);
- [DllImport("__Internal")]
- private static extern void TDOnPreviewFinished(string profileId, string content);
- #endif
- #if TD_READING
- [DllImport("__Internal")]
- private static extern void TDOnRead(string profileId, string book, long begin, int duration);
- [DllImport("__Internal")]
- private static extern void TDOnFreeFinished(string profileId, string content);
- #endif
- #if TD_GAME || TD_ONLINEEDU
- [DllImport("__Internal")]
- private static extern void TDOnAchievementUnlock(string profileId, string achievementId);
- #endif
- #if TD_FINANCE || TD_TOUR || TD_OTHER
- [DllImport("__Internal")]
- private static extern void TDOnBrowse(string profileId, string content, long begin, int duration);
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_OTHER
- [DllImport("__Internal")]
- private static extern void TDOnTrialFinished(string profileId, string content);
- #endif
- [DllImport("__Internal")]
- private static extern void TDOnEvent(string eventId, string parameters);
- [DllImport("__Internal")]
- private static extern void TDSetGlobalKV(string key, string strVal, double numVal);
- [DllImport("__Internal")]
- private static extern void TDRemoveGlobalKV(string key);
- #endif
- #if UNITY_ANDROID
- private static AndroidJavaObject GetCurrentActivity()
- {
- if (unityPlayerClass == null)
- {
- unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- }
- AndroidJavaObject activity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
- return activity;
- }
- #endif
- public static void Init(string appId, string channelId, string custom)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- Debug.Log("TalkingData Unity SDK.");
- #if UNITY_ANDROID
- using (AndroidJavaClass dz = new AndroidJavaClass("com.tendcloud.tenddata.dz"))
- {
- dz.SetStatic("a", 2);
- }
- if (talkingdataClass == null)
- {
- talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
- }
- AndroidJavaObject activity = GetCurrentActivity();
- talkingdataClass.CallStatic("init", activity, appId, channelId, custom);
- talkingdataClass.CallStatic("onResume", activity);
- #endif
- #if UNITY_IPHONE
- TDInit(appId, channelId, custom);
- #endif
- }
- }
- public static void OnPause()
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPause", GetCurrentActivity());
- }
- #endif
- }
- }
- public static void BackgroundSessionEnabled()
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_IPHONE
- TDBackgroundSessionEnabled();
- #endif
- }
- }
- private static string deviceId = null;
- public static string GetDeviceId()
- {
- if (deviceId == null && Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass == null)
- {
- talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
- }
- deviceId = talkingdataClass.CallStatic<string>("getDeviceId", GetCurrentActivity());
- #endif
- #if UNITY_IPHONE
- deviceId = TDGetDeviceId();
- #endif
- }
- return deviceId;
- }
- private static string oaid = null;
- public static string GetOAID()
- {
- if (oaid == null && Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass == null)
- {
- talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
- }
- oaid = talkingdataClass.CallStatic<string>("getOAID", GetCurrentActivity());
- #endif
- }
- return oaid;
- }
- public static void SetVerboseLogDisable()
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass == null)
- {
- talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
- }
- talkingdataClass.CallStatic("setVerboseLogDisable");
- #endif
- #if UNITY_IPHONE
- TDSetVerboseLogDisable();
- #endif
- }
- }
- public static void SetLocation(double latitude, double longitude)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_IPHONE
- TDSetLocation(latitude, longitude);
- #endif
- }
- }
- public static void OnPageBegin(string pageName)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPageBegin", GetCurrentActivity(), pageName);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPageBegin(pageName);
- #endif
- }
- }
- public static void OnPageEnd(string pageName)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPageEnd", GetCurrentActivity(), pageName);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPageEnd(pageName);
- #endif
- }
- }
- public static void OnReceiveDeepLink(string url)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onReceiveDeepLink", url);
- }
- #endif
- #if UNITY_IPHONE
- TDOnReceiveDeepLink(url);
- #endif
- }
- }
- public static void OnRegister(string profileId, TalkingDataProfile profile, string invitationCode)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onRegister", profileId, profile.javaObj, invitationCode);
- }
- #endif
- #if UNITY_IPHONE
- TDOnRegister(profileId, profile.ToString(), invitationCode);
- #endif
- }
- }
- public static void OnLogin(string profileId, TalkingDataProfile profile)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onLogin", profileId, profile.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnLogin(profileId, profile.ToString());
- #endif
- }
- }
- public static void OnProfileUpdate(TalkingDataProfile profile)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onProfileUpdate", profile.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnProfileUpdate(profile.ToString());
- #endif
- }
- }
- public static void OnCreateCard(string profileId, string method, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onCreateCard", profileId, method, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnCreateCard(profileId, method, content);
- #endif
- }
- }
- public static void OnFavorite(string category, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onFavorite", category, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnFavorite(category, content);
- #endif
- }
- }
- public static void OnShare(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onShare", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnShare(profileId, content);
- #endif
- }
- }
- public static void OnPunch(string profileId, string punchId)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPunch", profileId, punchId);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPunch(profileId, punchId);
- #endif
- }
- }
- public static void OnSearch(TalkingDataSearch search)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onSearch", search.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnSearch(search.ToString());
- #endif
- }
- }
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- public static void OnContact(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onContact", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnContact(profileId, content);
- #endif
- }
- }
- #endif
- #if TD_GAME || TD_TOUR || TD_ONLINEEDU || TD_READING || TD_OTHER
- public static void OnPay(string profileId, string orderId, int amount, string currencyType, string paymentType, string itemId, int itemCount)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPay", profileId, orderId, amount, currencyType, paymentType, itemId, itemCount);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPay(profileId, orderId, amount, currencyType, paymentType, itemId, itemCount);
- #endif
- }
- }
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- public static void OnChargeBack(string profileId, string orderId, string reason, string type)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onChargeBack", profileId, orderId, reason, type);
- }
- #endif
- #if UNITY_IPHONE
- TDOnChargeBack(profileId, orderId, reason, type);
- #endif
- }
- }
- #endif
- #if TD_FINANCE || TD_ONLINEEDU
- public static void OnReservation(string profileId, string reservationId, string category, int amount, string term)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onReservation", profileId, reservationId, category, amount, term);
- }
- #endif
- #if UNITY_IPHONE
- TDOnReservation(profileId, reservationId, category, amount, term);
- #endif
- }
- }
- #endif
- #if TD_RETAIL || TD_TOUR
- public static void OnBooking(string profileId, string bookingId, string category, int amount, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onBooking", profileId, bookingId, category, amount, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnBooking(profileId, bookingId, category, amount, content);
- #endif
- }
- }
- #endif
- #if TD_RETAIL
- public static void OnViewItem(string itemId, string category, string name, int unitPrice)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onViewItem", itemId, category, name, unitPrice);
- }
- #endif
- #if UNITY_IPHONE
- TDOnViewItem(itemId, category, name, unitPrice);
- #endif
- }
- }
- public static void OnAddItemToShoppingCart(string itemId, string category, string name, int unitPrice, int amount)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onAddItemToShoppingCart", itemId, category, name, unitPrice, amount);
- }
- #endif
- #if UNITY_IPHONE
- TDOnAddItemToShoppingCart(itemId, category, name, unitPrice, amount);
- #endif
- }
- }
- public static void OnViewShoppingCart(TalkingDataShoppingCart shoppingCart)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onViewShoppingCart", shoppingCart.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnViewShoppingCart(shoppingCart.ToString());
- #endif
- }
- }
- public static void OnPlaceOrder(TalkingDataOrder order, string profileId)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPlaceOrder", order.javaObj, profileId);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPlaceOrder(order.ToString(), profileId);
- #endif
- }
- }
- public static void OnOrderPaySucc(TalkingDataOrder order, string paymentType, string profileId)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onOrderPaySucc", order.javaObj, paymentType, profileId);
- }
- #endif
- #if UNITY_IPHONE
- TDOnOrderPaySucc(order.ToString(), paymentType, profileId);
- #endif
- }
- }
- public static void OnCancelOrder(TalkingDataOrder order)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onCancelOrder", order.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnCancelOrder(order.ToString());
- #endif
- }
- }
- #endif
- #if TD_FINANCE
- public static void OnCredit(string profileId, int amount, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onCredit", profileId, amount, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnCredit(profileId, amount, content);
- #endif
- }
- }
- public static void OnTransaction(string profileId, TalkingDataTransaction transaction)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onTransaction", profileId, transaction.javaObj);
- }
- #endif
- #if UNITY_IPHONE
- TDOnTransaction(profileId, transaction.ToString());
- #endif
- }
- }
- #endif
- #if TD_GAME
- public static void OnCreateRole(string name)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onCreateRole", name);
- }
- #endif
- #if UNITY_IPHONE
- TDOnCreateRole(name);
- #endif
- }
- }
- public static void OnLevelPass(string profileId, string levelId)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onLevelPass", profileId, levelId);
- }
- #endif
- #if UNITY_IPHONE
- TDOnLevelPass(profileId, levelId);
- #endif
- }
- }
- public static void OnGuideFinished(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onGuideFinished", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnGuideFinished(profileId, content);
- #endif
- }
- }
- #endif
- #if TD_ONLINEEDU
- public static void OnLearn(string profileId, string course, long begin, int duration)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onLearn", profileId, course, begin, duration);
- }
- #endif
- #if UNITY_IPHONE
- TDOnLearn(profileId, course, begin, duration);
- #endif
- }
- }
- public static void OnPreviewFinished(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onPreviewFinished", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnPreviewFinished(profileId, content);
- #endif
- }
- }
- #endif
- #if TD_READING
- public static void OnRead(string profileId, string book, long begin, int duration)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onRead", profileId, book, begin, duration);
- }
- #endif
- #if UNITY_IPHONE
- TDOnRead(profileId, book, begin, duration);
- #endif
- }
- }
- public static void OnFreeFinished(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onFreeFinished", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnFreeFinished(profileId, content);
- #endif
- }
- }
- #endif
- #if TD_GAME || TD_ONLINEEDU
- public static void OnAchievementUnlock(string profileId, string achievementId)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onAchievementUnlock", profileId, achievementId);
- }
- #endif
- #if UNITY_IPHONE
- TDOnAchievementUnlock(profileId, achievementId);
- #endif
- }
- }
- #endif
- #if TD_FINANCE || TD_TOUR || TD_OTHER
- public static void OnBrowse(string profileId, string content, long begin, int duration)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onBrowse", profileId, content, begin, duration);
- }
- #endif
- #if UNITY_IPHONE
- TDOnBrowse(profileId, content, begin, duration);
- #endif
- }
- }
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_OTHER
- public static void OnTrialFinished(string profileId, string content)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("onTrialFinished", profileId, content);
- }
- #endif
- #if UNITY_IPHONE
- TDOnTrialFinished(profileId, content);
- #endif
- }
- }
- #endif
- public static void OnEvent(string eventId, Dictionary<string, object> parameters)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- if (parameters != null && parameters.Count > 0)
- {
- int count = parameters.Count;
- AndroidJavaObject map = new AndroidJavaObject("java.util.HashMap", count);
- IntPtr method_Put = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
- object[] args = new object[2];
- foreach (KeyValuePair<string, object> kvp in parameters)
- {
- args[0] = new AndroidJavaObject("java.lang.String", kvp.Key);
- args[1] = typeof(string).IsInstanceOfType(kvp.Value)
- ? new AndroidJavaObject("java.lang.String", kvp.Value)
- : new AndroidJavaObject("java.lang.Double", "" + kvp.Value);
- AndroidJNI.CallObjectMethod(map.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
- }
- talkingdataClass.CallStatic("onEvent", GetCurrentActivity(), eventId, map);
- map.Dispose();
- }
- else
- {
- talkingdataClass.CallStatic("onEvent", GetCurrentActivity(), eventId, null);
- }
- }
- #endif
- #if UNITY_IPHONE
- if (parameters != null && parameters.Count > 0)
- {
- string parameterStr = "{";
- foreach (KeyValuePair<string, object> kvp in parameters)
- {
- if (kvp.Value is string)
- {
- parameterStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
- }
- else
- {
- try
- {
- double tmp = System.Convert.ToDouble(kvp.Value);
- parameterStr += "\"" + kvp.Key + "\":" + tmp + ",";
- }
- catch (System.Exception)
- {
- }
- }
- }
- parameterStr = parameterStr.TrimEnd(',');
- parameterStr += "}";
- TDOnEvent(eventId, parameterStr);
- }
- else
- {
- TDOnEvent(eventId, null);
- }
- #endif
- }
- }
- public static void SetGlobalKV(string key, object val)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- AndroidJavaObject valObject = typeof(string).IsInstanceOfType(val)
- ? new AndroidJavaObject("java.lang.String", val)
- : new AndroidJavaObject("java.lang.Double", "" + val);
- talkingdataClass.CallStatic("setGlobalKV", key, valObject);
- }
- #endif
- #if UNITY_IPHONE
- if (val is string)
- {
- string tmp = System.Convert.ToString(val);
- TDSetGlobalKV(key, tmp, 0);
- }
- else
- {
- double tmp = System.Convert.ToDouble(val);
- TDSetGlobalKV(key, null, tmp);
- }
- #endif
- }
- }
- public static void RemoveGlobalKV(string key)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (talkingdataClass != null)
- {
- talkingdataClass.CallStatic("removeGlobalKV", key);
- }
- #endif
- #if UNITY_IPHONE
- TDRemoveGlobalKV(key);
- #endif
- }
- }
- }
|