123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- using UnityEngine;
- public enum TalkingDataProfileType
- {
- ANONYMOUS = 0,
- REGISTERED = 1,
- SINA_WEIBO = 2,
- QQ = 3,
- QQ_WEIBO = 4,
- ND91 = 5,
- WEIXIN = 6,
- TYPE1 = 11,
- TYPE2 = 12,
- TYPE3 = 13,
- TYPE4 = 14,
- TYPE5 = 15,
- TYPE6 = 16,
- TYPE7 = 17,
- TYPE8 = 18,
- TYPE9 = 19,
- TYPE10 = 20
- }
- public enum TalkingDataGender
- {
- UNKNOWN = 0,
- MALE = 1,
- FEMALE = 2
- }
- public class TalkingDataProfile
- {
- #if UNITY_ANDROID
- public AndroidJavaObject javaObj;
- #endif
- #if UNITY_IPHONE
- private string name;
- private TalkingDataProfileType type;
- private TalkingDataGender gender;
- private int age;
- private object property1;
- private object property2;
- private object property3;
- private object property4;
- private object property5;
- private object property6;
- private object property7;
- private object property8;
- private object property9;
- private object property10;
- #endif
- public static TalkingDataProfile CreateProfile()
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- TalkingDataProfile profile = new TalkingDataProfile();
- #if UNITY_ANDROID
- AndroidJavaClass javaClass = new AndroidJavaClass("com.tendcloud.tenddata.TalkingDataProfile");
- profile.javaObj = javaClass.CallStatic<AndroidJavaObject>("createProfile");
- #endif
- return profile;
- }
- return null;
- }
- // 账户名称
- public TalkingDataProfile SetName(string name)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- javaObj.Call<AndroidJavaObject>("setName", name);
- }
- #endif
- #if UNITY_IPHONE
- this.name = name;
- #endif
- }
- return this;
- }
- // 账户类型
- public TalkingDataProfile SetType(TalkingDataProfileType type)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaClass enumClass = new AndroidJavaClass("com.tendcloud.tenddata.TalkingDataProfileType");
- AndroidJavaObject typeObj = enumClass.CallStatic<AndroidJavaObject>("valueOf", type.ToString());
- javaObj.Call<AndroidJavaObject>("setType", typeObj);
- }
- #endif
- #if UNITY_IPHONE
- this.type = type;
- #endif
- }
- return this;
- }
- // 性别
- public TalkingDataProfile SetGender(TalkingDataGender gender)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaClass enumClass = new AndroidJavaClass("com.tendcloud.tenddata.TalkingDataGender");
- AndroidJavaObject genderObj = enumClass.CallStatic<AndroidJavaObject>("valueOf", gender.ToString());
- javaObj.Call<AndroidJavaObject>("setGender", genderObj);
- }
- #endif
- #if UNITY_IPHONE
- this.gender = gender;
- #endif
- }
- return this;
- }
- // 年龄
- public TalkingDataProfile SetAge(int age)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- javaObj.Call<AndroidJavaObject>("setAge", age);
- }
- #endif
- #if UNITY_IPHONE
- this.age = age;
- #endif
- }
- return this;
- }
- // 用户属性1
- public TalkingDataProfile SetProperty1(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty1", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property1 = property;
- #endif
- }
- return this;
- }
- // 用户属性2
- public TalkingDataProfile SetProperty2(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty2", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property2 = property;
- #endif
- }
- return this;
- }
- // 用户属性3
- public TalkingDataProfile SetProperty3(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty3", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property3 = property;
- #endif
- }
- return this;
- }
- // 用户属性4
- public TalkingDataProfile SetProperty4(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty4", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property4 = property;
- #endif
- }
- return this;
- }
- // 用户属性5
- public TalkingDataProfile SetProperty5(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty5", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property5 = property;
- #endif
- }
- return this;
- }
- // 用户属性6
- public TalkingDataProfile SetProperty6(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty6", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property6 = property;
- #endif
- }
- return this;
- }
- // 用户属性7
- public TalkingDataProfile SetProperty7(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty7", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property7 = property;
- #endif
- }
- return this;
- }
- // 用户属性8
- public TalkingDataProfile SetProperty8(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty8", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property8 = property;
- #endif
- }
- return this;
- }
- // 用户属性9
- public TalkingDataProfile SetProperty9(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty9", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property9 = property;
- #endif
- }
- return this;
- }
- // 用户属性10
- public TalkingDataProfile SetProperty10(object property)
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- #if UNITY_ANDROID
- if (javaObj != null)
- {
- AndroidJavaObject androidObject = AndroidJavaObjectFromObject(property);
- javaObj.Call<AndroidJavaObject>("setProperty10", androidObject);
- }
- #endif
- #if UNITY_IPHONE
- this.property10 = property;
- #endif
- }
- return this;
- }
- #if UNITY_ANDROID
- private AndroidJavaObject AndroidJavaObjectFromObject(object parameter)
- {
- AndroidJavaObject androidObject = null;
- if (parameter is string)
- {
- androidObject = new AndroidJavaObject("java.lang.String", parameter);
- }
- else if (parameter is byte || parameter is sbyte)
- {
- androidObject = new AndroidJavaObject("java.lang.Byte", parameter);
- }
- else if (parameter is short || parameter is ushort)
- {
- androidObject = new AndroidJavaObject("java.lang.Short", parameter);
- }
- else if (parameter is int || parameter is uint)
- {
- androidObject = new AndroidJavaObject("java.lang.Integer", parameter);
- }
- else if (parameter is long || parameter is ulong)
- {
- androidObject = new AndroidJavaObject("java.lang.Long", parameter);
- }
- else if (parameter is float)
- {
- androidObject = new AndroidJavaObject("java.lang.Float", parameter);
- }
- else if (parameter is double)
- {
- androidObject = new AndroidJavaObject("java.lang.Double", parameter);
- }
- return androidObject;
- }
- #endif
- #if UNITY_IPHONE
- public override string ToString()
- {
- if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
- {
- string profileStr = "{\"name\":\"" + name + "\""
- + ",\"type\":" + (int)type
- + ",\"gender\":" + (int)gender
- + ",\"age\":" + age;
- if (property1 is string)
- {
- profileStr += ",\"property1\":\"" + property1 + "\"";
- }
- else
- {
- profileStr += ",\"property1\":" + property1;
- }
- if (property2 is string)
- {
- profileStr += ",\"property2\":\"" + property2 + "\"";
- }
- else
- {
- profileStr += ",\"property2\":" + property2;
- }
- if (property3 is string)
- {
- profileStr += ",\"property3\":\"" + property3 + "\"";
- }
- else
- {
- profileStr += ",\"property3\":" + property3;
- }
- if (property4 is string)
- {
- profileStr += ",\"property4\":\"" + property4 + "\"";
- }
- else
- {
- profileStr += ",\"property4\":" + property4;
- }
- if (property5 is string)
- {
- profileStr += ",\"property5\":\"" + property5 + "\"";
- }
- else
- {
- profileStr += ",\"property5\":" + property5;
- }
- if (property6 is string)
- {
- profileStr += ",\"property6\":\"" + property6 + "\"";
- }
- else
- {
- profileStr += ",\"property6\":" + property6;
- }
- if (property7 is string)
- {
- profileStr += ",\"property7\":\"" + property7 + "\"";
- }
- else
- {
- profileStr += ",\"property7\":" + property7;
- }
- if (property8 is string)
- {
- profileStr += ",\"property8\":\"" + property8 + "\"";
- }
- else
- {
- profileStr += ",\"property8\":" + property8;
- }
- if (property9 is string)
- {
- profileStr += ",\"property9\":\"" + property9 + "\"";
- }
- else
- {
- profileStr += ",\"property9\":" + property9;
- }
- if (property10 is string)
- {
- profileStr += ",\"property10\":\"" + property10 + "\"";
- }
- else
- {
- profileStr += ",\"property10\":" + property10;
- }
- profileStr += "}";
- return profileStr;
- }
- return null;
- }
- #endif
- }
|