This commit is contained in:
Developer
2026-06-18 10:06:49 +08:00
parent fdd81aef19
commit ebd5dafa2d
922 changed files with 145347 additions and 297 deletions

View File

@@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using TapSDK.Core.Internal.Log;
using UnityEngine;
namespace TapSDK.Core
{
public static class DataStorage
{
private static Dictionary<string, string> dataCache;
private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
// 缓存 MacAddress避免多次获取
private static string cachedMacAddress;
public static void SaveString(string key, string value)
{
string storageKey = GenerateStorageKey(key);
SaveStringToCache(storageKey, value);
string encodeValue = EncodeString(value);
PlayerPrefs.SetString(storageKey, encodeValue);
}
public static string LoadString(string key)
{
string storageKey = GenerateStorageKey(key);
string value = LoadStringFromCache(storageKey);
if (!string.IsNullOrEmpty(value))
{
return value;
}
value = PlayerPrefs.HasKey(storageKey) ? DecodeString(PlayerPrefs.GetString(storageKey)) : null;
// 尝试从本地获取旧版本数据
if (value == null)
{
value = PlayerPrefs.HasKey(key) ? DecodeString(PlayerPrefs.GetString(key)) : null;
// 旧版本存在有效数据时,转储为新的 storageKey
if (value != null)
{
PlayerPrefs.SetString(storageKey, EncodeString(value));
PlayerPrefs.DeleteKey(key);
}
}
if (value != null)
{
SaveStringToCache(storageKey, value);
}
return value;
}
public static void RemoveCacheKey(string key)
{
if (!string.IsNullOrEmpty(key))
{
PlayerPrefs.DeleteKey(key);
PlayerPrefs.DeleteKey(GenerateStorageKey(key));
}
}
private static void SaveStringToCache(string key, string value)
{
if (dataCache == null)
{
dataCache = new Dictionary<string, string>();
}
if (dataCache.ContainsKey(key))
{
dataCache[key] = value;
}
else
{
dataCache.Add(key, value);
}
}
private static string LoadStringFromCache(string key)
{
if (dataCache == null)
{
dataCache = new Dictionary<string, string>();
}
return dataCache.ContainsKey(key) ? dataCache[key] : null;
}
private static string EncodeString(string encryptString)
{
if (Platform.IsAndroid() || Platform.IsIOS())
{
return encryptString;
}
try
{
byte[] rgbKey = Encoding.UTF8.GetBytes(GetMacAddress().Substring(0, 8));
byte[] rgbIV = Keys;
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
cStream.Close();
return Convert.ToBase64String(mStream.ToArray());
}
catch
{
return encryptString;
}
}
private static string DecodeString(string decryptString)
{
if (Platform.IsAndroid() || Platform.IsIOS())
{
return decryptString;
}
try
{
byte[] rgbKey = Encoding.UTF8.GetBytes(GetMacAddress().Substring(0, 8));
byte[] rgbIV = Keys;
byte[] inputByteArray = Convert.FromBase64String(decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
cStream.Close();
return Encoding.UTF8.GetString(mStream.ToArray());
}
catch (Exception e)
{
TapLog.Log(e.Message);
return decryptString;
}
}
private static string GetMacAddress()
{
if (!string.IsNullOrEmpty(cachedMacAddress))
{
return cachedMacAddress;
}
string physicalAddress = "FFFFFFFFFFFF";
if (Platform.IsAndroid() || Platform.IsIOS())
{
return physicalAddress;
}
NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adaper in nice)
{
if (adaper.Description == "en0")
{
physicalAddress = adaper.GetPhysicalAddress().ToString();
break;
}
else
{
physicalAddress = adaper.GetPhysicalAddress().ToString();
if (physicalAddress != "")
{
break;
};
}
}
cachedMacAddress = physicalAddress;
return physicalAddress;
}
// 生成存储在本地文件中 key
private static string GenerateStorageKey(string originKey){
if(TapTapSDK.taptapSdkOptions != null && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId)){
return originKey + "_" + TapTapSDK.taptapSdkOptions.clientId;
}
return originKey;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 32c169d8c12eb4e9598b83c11ad84f48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
namespace TapSDK.Core {
public interface ITapPropertiesProxy {
string GetProperties();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c03335ad3e42d4092aa308d6503ce66a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,636 @@
/*
* Copyright (c) 2013 Calvin Rien
*
* Based on the JSON parser by Patrick van Bergen
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* Simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Globalization;
//Serializer,Serialize
namespace TapSDK.Core
{
// Example usage:
//
// using UnityEngine;
// using System.Collections;
// using System.Collections.Generic;
// using MiniJSON;
//
// public class MiniJSONTest : MonoBehaviour {
// void Start () {
// var jsonString = "{ \"array\": [1.44,2,3], " +
// "\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
// "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
// "\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " +
// "\"int\": 65536, " +
// "\"float\": 3.1415926, " +
// "\"bool\": true, " +
// "\"null\": null }";
//
// var dict = Json.Deserialize(jsonString) as Dictionary<string,object>;
//
// Debug.Log("deserialized: " + dict.GetType());
// Debug.Log("dict['array'][0]: " + ((List<object>) dict["array"])[0]);
// Debug.Log("dict['string']: " + (string) dict["string"]);
// Debug.Log("dict['float']: " + (double) dict["float"]); // floats come out as doubles
// Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs
// Debug.Log("dict['unicode']: " + (string) dict["unicode"]);
//
// var str = Json.Serialize(dict);
//
// Debug.Log("serialized: " + str);
// }
// }
/// <summary>
/// This class encodes and decodes JSON strings.
/// Spec. details, see http://www.json.org/
///
/// JSON uses Arrays and Objects. These correspond here to the datatypes IList and IDictionary.
/// All numbers are parsed to doubles.
/// </summary>
public static class Json
{
/// <summary>
/// Parses the string json into a value
/// </summary>
/// <param name="json">A JSON string.</param>
/// <returns>An List&lt;object&gt;, a Dictionary&lt;string, object&gt;, a double, an integer,a string, null, true, or false</returns>
public static object Deserialize(string json)
{
// save the string for debug information
if (json == null)
{
return null;
}
return Parser.Parse(json);
}
sealed class Parser : IDisposable
{
const string WORD_BREAK = "{}[],:\"";
public static bool IsWordBreak(char c)
{
return Char.IsWhiteSpace(c) || WORD_BREAK.IndexOf(c) != -1;
}
enum TOKEN
{
NONE,
CURLY_OPEN,
CURLY_CLOSE,
SQUARED_OPEN,
SQUARED_CLOSE,
COLON,
COMMA,
STRING,
NUMBER,
TRUE,
FALSE,
NULL
};
StringReader json;
Parser(string jsonString)
{
json = new StringReader(jsonString);
}
public static object Parse(string jsonString)
{
using (var instance = new Parser(jsonString))
{
return instance.ParseValue();
}
}
public void Dispose()
{
json.Dispose();
json = null;
}
Dictionary<string, object> ParseObject()
{
Dictionary<string, object> table = new Dictionary<string, object>();
// ditch opening brace
json.Read();
// {
while (true)
{
switch (NextToken)
{
case TOKEN.NONE:
return null;
case TOKEN.COMMA:
continue;
case TOKEN.CURLY_CLOSE:
return table;
default:
// name
string name = ParseString();
if (name == null)
{
return null;
}
// :
if (NextToken != TOKEN.COLON)
{
return null;
}
// ditch the colon
json.Read();
// value
table[name] = ParseValue();
break;
}
}
}
List<object> ParseArray()
{
List<object> array = new List<object>();
// ditch opening bracket
json.Read();
// [
var parsing = true;
while (parsing)
{
TOKEN nextToken = NextToken;
switch (nextToken)
{
case TOKEN.NONE:
return null;
case TOKEN.COMMA:
continue;
case TOKEN.SQUARED_CLOSE:
parsing = false;
break;
default:
object value = ParseByToken(nextToken);
array.Add(value);
break;
}
}
return array;
}
object ParseValue()
{
TOKEN nextToken = NextToken;
return ParseByToken(nextToken);
}
object ParseByToken(TOKEN token)
{
switch (token)
{
case TOKEN.STRING:
return ParseString();
case TOKEN.NUMBER:
return ParseNumber();
case TOKEN.CURLY_OPEN:
return ParseObject();
case TOKEN.SQUARED_OPEN:
return ParseArray();
case TOKEN.TRUE:
return true;
case TOKEN.FALSE:
return false;
case TOKEN.NULL:
return null;
default:
return null;
}
}
string ParseString()
{
StringBuilder s = new StringBuilder();
char c;
// ditch opening quote
json.Read();
bool parsing = true;
while (parsing)
{
if (json.Peek() == -1)
{
parsing = false;
break;
}
c = NextChar;
switch (c)
{
case '"':
parsing = false;
break;
case '\\':
if (json.Peek() == -1)
{
parsing = false;
break;
}
c = NextChar;
switch (c)
{
case '"':
case '\\':
case '/':
s.Append(c);
break;
case 'b':
s.Append('\b');
break;
case 'f':
s.Append('\f');
break;
case 'n':
s.Append('\n');
break;
case 'r':
s.Append('\r');
break;
case 't':
s.Append('\t');
break;
case 'u':
var hex = new char[4];
for (int i = 0; i < 4; i++)
{
hex[i] = NextChar;
}
s.Append((char)Convert.ToInt32(new string(hex), 16));
break;
}
break;
default:
s.Append(c);
break;
}
}
return s.ToString();
}
object ParseNumber()
{
string number = NextWord;
if (number.IndexOf('.') == -1)
{
long parsedInt;
Int64.TryParse(number, NumberStyles.Number, CultureInfo.InvariantCulture, out parsedInt);
return parsedInt;
}
double parsedDouble;
Double.TryParse(number, NumberStyles.Number, CultureInfo.InvariantCulture, out parsedDouble);
return parsedDouble;
}
void EatWhitespace()
{
while (Char.IsWhiteSpace(PeekChar))
{
json.Read();
if (json.Peek() == -1)
{
break;
}
}
}
char PeekChar
{
get
{
return Convert.ToChar(json.Peek());
}
}
char NextChar
{
get
{
return Convert.ToChar(json.Read());
}
}
string NextWord
{
get
{
StringBuilder word = new StringBuilder();
while (!IsWordBreak(PeekChar))
{
word.Append(NextChar);
if (json.Peek() == -1)
{
break;
}
}
return word.ToString();
}
}
TOKEN NextToken
{
get
{
EatWhitespace();
if (json.Peek() == -1)
{
return TOKEN.NONE;
}
switch (PeekChar)
{
case '{':
return TOKEN.CURLY_OPEN;
case '}':
json.Read();
return TOKEN.CURLY_CLOSE;
case '[':
return TOKEN.SQUARED_OPEN;
case ']':
json.Read();
return TOKEN.SQUARED_CLOSE;
case ',':
json.Read();
return TOKEN.COMMA;
case '"':
return TOKEN.STRING;
case ':':
return TOKEN.COLON;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
return TOKEN.NUMBER;
}
switch (NextWord)
{
case "false":
return TOKEN.FALSE;
case "true":
return TOKEN.TRUE;
case "null":
return TOKEN.NULL;
}
return TOKEN.NONE;
}
}
}
/// <summary>
/// Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string
/// </summary>
/// <param name="json">A Dictionary&lt;string, object&gt; / List&lt;object&gt;</param>
/// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns>
public static string Serialize(object obj)
{
return Serializer.Serialize(obj);
}
sealed class Serializer
{
StringBuilder builder;
Serializer()
{
builder = new StringBuilder();
}
public static string Serialize(object obj)
{
var instance = new Serializer();
instance.SerializeValue(obj);
return instance.builder.ToString();
}
void SerializeValue(object value)
{
IList asList;
IDictionary asDict;
string asStr;
if (value == null)
{
builder.Append("null");
}
else if ((asStr = value as string) != null)
{
SerializeString(asStr);
}
else if (value is bool)
{
builder.Append((bool)value ? "true" : "false");
}
else if ((asList = value as IList) != null)
{
SerializeArray(asList);
}
else if ((asDict = value as IDictionary) != null)
{
SerializeObject(asDict);
}
else if (value is char)
{
SerializeString(new string((char)value, 1));
}
else
{
SerializeOther(value);
}
}
void SerializeObject(IDictionary obj)
{
bool first = true;
builder.Append('{');
foreach (object e in obj.Keys)
{
if (!first)
{
builder.Append(',');
}
SerializeString(e.ToString());
builder.Append(':');
SerializeValue(obj[e]);
first = false;
}
builder.Append('}');
}
void SerializeArray(IList anArray)
{
builder.Append('[');
bool first = true;
foreach (object obj in anArray)
{
if (!first)
{
builder.Append(',');
}
SerializeValue(obj);
first = false;
}
builder.Append(']');
}
void SerializeString(string str)
{
builder.Append('\"');
char[] charArray = str.ToCharArray();
foreach (var c in charArray)
{
switch (c)
{
case '"':
builder.Append("\\\"");
break;
case '\\':
builder.Append("\\\\");
break;
case '\b':
builder.Append("\\b");
break;
case '\f':
builder.Append("\\f");
break;
case '\n':
builder.Append("\\n");
break;
case '\r':
builder.Append("\\r");
break;
case '\t':
builder.Append("\\t");
break;
default:
int codepoint = Convert.ToInt32(c);
if ((codepoint >= 32) && (codepoint <= 126))
{
builder.Append(c);
}
else
{
builder.Append("\\u");
builder.Append(codepoint.ToString("x4"));
}
break;
}
}
builder.Append('\"');
}
void SerializeOther(object value)
{
// NOTE: decimals lose precision during serialization.
// They always have, I'm just letting you know.
// Previously floats and doubles lost precision too.
if (value is float)
{
builder.Append(((float)value).ToString("R", CultureInfo.InvariantCulture));
}
else if (value is int
|| value is uint
|| value is long
|| value is sbyte
|| value is byte
|| value is short
|| value is ushort
|| value is ulong)
{
builder.Append(value);
}
else if (value is double
|| value is decimal)
{
builder.Append(Convert.ToDouble(value).ToString("R", CultureInfo.InvariantCulture));
}
else
{
SerializeString(value.ToString());
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03626f52014bc4f14b549e8bb318ca74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 50f5141d913874984bd6a97cace57cbb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace TapSDK.Core {
public enum TapLogLevel {
Debug,
Warn,
Error,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1456af90a56064fe9afe2ccd9692f261
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using System;
using System.Text;
namespace TapSDK.Core {
public class TapLogger {
/// <summary>
/// Configures the logger.
/// </summary>
/// <value>The log delegate.</value>
public static Action<TapLogLevel, string> LogDelegate {
internal get; set;
}
public static void Debug(string log) {
LogDelegate?.Invoke(TapLogLevel.Debug, log);
}
public static void Debug(string format, params object[] args) {
LogDelegate?.Invoke(TapLogLevel.Debug, string.Format(format, args));
}
public static void Warn(string log) {
LogDelegate?.Invoke(TapLogLevel.Warn, log);
}
public static void Warn(string format, params object[] args) {
LogDelegate?.Invoke(TapLogLevel.Warn, string.Format(format, args));
}
public static void Error(string log) {
LogDelegate?.Invoke(TapLogLevel.Error, log);
}
public static void Error(string format, params object[] args) {
LogDelegate?.Invoke(TapLogLevel.Error, string.Format(format, args));
}
public static void Error(Exception e) {
StringBuilder sb = new StringBuilder();
sb.Append(e.GetType());
sb.Append("\n");
sb.Append(e.Message);
sb.Append("\n");
sb.Append(e.StackTrace);
Error(sb.ToString());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 256e6b07da183466a9621d24df1e3ae7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace TapSDK.Core
{
public class Platform
{
public static bool IsAndroid()
{
return Application.platform == RuntimePlatform.Android;
}
public static bool IsIOS()
{
return Application.platform == RuntimePlatform.IPhonePlayer;
}
public static bool IsWin32()
{
return Application.platform == RuntimePlatform.WindowsPlayer;
}
public static bool IsMacOS()
{
return Application.platform == RuntimePlatform.OSXPlayer;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ef69730c212ed4cc9b4f39d224e60de5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
namespace TapSDK.Core
{
public enum RegionType : int
{
CN = 0,
IO = 1
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 77cbd92bb921740e7b83329a483a1221
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace TapSDK.Core
{
public static class SafeDictionary
{
public static T GetValue<T> (Dictionary<string, object> dic, string key, T defaultVal = default(T))
{
if (dic == null || dic.Keys.Count == 0) return default(T);
if (!dic.TryGetValue(key, out var outputValue))
return defaultVal;
if(typeof(T) == typeof(int)){
return (T)(object)int.Parse(outputValue.ToString());
}
if(typeof(T) == typeof(double)){
return (T)(object)double.Parse(outputValue.ToString());
}
if(typeof(T) == typeof(long)){
return (T)(object)long.Parse(outputValue.ToString());
}
if(typeof(T) == typeof(bool)){
return (T)outputValue;
}
return (T) outputValue;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c5d3a73d3e1d4bf890c3a0b14b560fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using Newtonsoft.Json;
namespace TapSDK.Core
{
public class TapEngineBridgeResult
{
public const int RESULT_SUCCESS = 0;
public const int RESULT_ERROR = -1;
[JsonProperty("code")] public int code { get; set; }
[JsonProperty("message")] public string message { get; set; }
[JsonProperty("content")] public string content { get; set; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2ec1ea022bd44fcba1ad7c0fa5af9401
timeCreated: 1752474613

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
namespace TapSDK.Core
{
public class TapError
{
public int code;
public string errorDescription;
public TapError(string json)
{
if (string.IsNullOrEmpty(json))
{
return;
}
var dic = Json.Deserialize(json) as Dictionary<string, object>;
code = SafeDictionary.GetValue<int>(dic, "code");
errorDescription = SafeDictionary.GetValue<string>(dic, "error_description");
}
public TapError()
{
}
public static TapError SafeConstructorTapError(string json)
{
return string.IsNullOrEmpty(json) ? null : new TapError(json);
}
public static TapError UndefinedError()
{
return new TapError(TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnown Error");
}
public static TapError LoginCancelError()
{
return new TapError(TapErrorCode.ERROR_CODE_LOGIN_CANCEL, "Login Cancel");
}
public TapError(int code, string errorDescription)
{
this.code = code;
this.errorDescription = errorDescription;
}
private static TapErrorCode ParseCode(int parseCode)
{
return Enum.IsDefined(typeof(TapErrorCode), parseCode)
? (TapErrorCode) Enum.ToObject(typeof(TapErrorCode), parseCode)
: TapErrorCode.ERROR_CODE_UNDEFINED;
}
public TapError(TapErrorCode code, string errorDescription)
{
this.code = (int) code;
this.errorDescription = errorDescription;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c93fd38e60af46b78131cf90dddff5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
namespace TapSDK.Core
{
public enum TapErrorCode
{
/*
* 未知错误
*/
ERROR_CODE_UNDEFINED = 80000,
/**
* SDK 未初始化
*/
ERROR_CODE_UNINITIALIZED = 80001,
/**
* 绑定取消
*/
ERROR_CODE_BIND_CANCEL = 80002,
/**
* 绑定错误
*/
ERROR_CODE_BIND_ERROR = 80003,
/**
* 登陆错误
*/
ERROR_CODE_LOGOUT_INVALID_LOGIN_STATE = 80004,
/**
* 登陆被踢出
*/
ERROR_CODE_LOGOUT_KICKED = 80007,
/**
* 桥接回调错误
*/
ERROR_CODE_BRIDGE_EXECUTE = 80080,
/**
* 登录取消
*/
ERROR_CODE_LOGIN_CANCEL = 80081
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 28bd88a8759b74f55a9e42d04f7aacf3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using System;
namespace TapSDK.Core
{
public class TapException : Exception
{
public int code;
public int Code {
get => code;
set {
code = value;
}
}
public string message;
public TapException(int code, string message) : base(message)
{
this.code = code;
this.message = message;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b8258d80e38ee46738be23d42027f05c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,107 @@
using System;
using System.Threading.Tasks;
using TapSDK.Core.Internal;
using UnityEngine;
using System.Reflection;
using TapSDK.Core.Internal.Log;
namespace TapSDK.Core {
public class TapTapEvent {
private static ITapEventPlatform platformWrapper;
static TapTapEvent() {
platformWrapper = PlatformTypeUtils.CreatePlatformImplementationObject(typeof(ITapEventPlatform),
"TapSDK.Core") as ITapEventPlatform;
if(platformWrapper == null) {
TapLog.Error("PlatformWrapper is null");
}
}
internal static void Init(TapTapEventOptions eventOptions)
{
platformWrapper.Init(eventOptions);
}
public static void SetUserID(string userID)
{
platformWrapper?.SetUserID(userID);
}
public static void SetUserID(string userID, string properties){
platformWrapper?.SetUserID(userID,properties);
}
public static void ClearUser(){
platformWrapper?.ClearUser();
}
public static string GetDeviceId(){
if(platformWrapper != null) {
return platformWrapper?.GetDeviceId();
}
return "";
}
public static void LogEvent(string name, string properties){
platformWrapper?.LogEvent(name, properties);
}
public static void DeviceInitialize(string properties){
platformWrapper?.DeviceInitialize(properties);
}
public static void DeviceUpdate(string properties){
platformWrapper?.DeviceUpdate(properties);
}
public static void DeviceAdd(string properties){
platformWrapper?.DeviceAdd(properties);
}
public static void UserInitialize(string properties){
platformWrapper?.UserInitialize(properties);
}
public static void UserUpdate(string properties){
platformWrapper?.UserUpdate(properties);
}
public static void UserAdd(string properties){
platformWrapper?.UserAdd(properties);
}
public static void AddCommonProperty(string key, string value){
platformWrapper?.AddCommonProperty(key, value);
}
public static void AddCommon(string properties){
platformWrapper?.AddCommon(properties);
}
public static void ClearCommonProperty(string key){
platformWrapper?.ClearCommonProperty(key);
}
public static void ClearCommonProperties(string[] keys){
platformWrapper?.ClearCommonProperties(keys);
}
public static void ClearAllCommonProperties(){
platformWrapper?.ClearAllCommonProperties();
}
public static void LogPurchasedEvent(string orderID, string productName, long amount, string currencyType, string paymentMethod, string properties){
platformWrapper?.LogChargeEvent(orderID, productName, amount, currencyType, paymentMethod, properties);
}
public static void RegisterDynamicProperties(Func<string> callback){
platformWrapper?.RegisterDynamicProperties(callback);
}
public static void SetOAID(string value){
platformWrapper?.SetOAID(value);
}
public static void LogDeviceLoginEvent(){
platformWrapper?.LogDeviceLoginEvent();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 573a66a7d4c2a49309f0b3e2cef0eecb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
namespace TapSDK.Core
{
#if UNITY_STANDALONE_WIN
public class TapTapPCState
{
public const int ONLINE = 1;
public const int OFFLINE = 2;
public const int SHUTDOWN = 3;
}
#endif
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03b213fad1790bd4fb52fed89737b23f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,174 @@
using System;
using System.Threading.Tasks;
using System.Linq;
using TapSDK.Core.Internal;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;
using TapSDK.Core.Internal.Init;
using TapSDK.Core.Internal.Log;
using System.ComponentModel;
namespace TapSDK.Core {
public class TapTapSDK {
public static readonly string Version = "4.10.2";
public static string SDKPlatform = "TapSDK-Unity";
public static TapTapSdkOptions taptapSdkOptions;
private static ITapCorePlatform platformWrapper;
private static bool disableDurationStatistics;
public static bool DisableDurationStatistics {
get => disableDurationStatistics;
set {
disableDurationStatistics = value;
}
}
static TapTapSDK() {
platformWrapper = PlatformTypeUtils.CreatePlatformImplementationObject(typeof(ITapCorePlatform),
"TapSDK.Core") as ITapCorePlatform;
}
public static void Init(TapTapSdkOptions coreOption)
{
if (coreOption == null)
throw new ArgumentException("[TapSDK] options is null!");
TapTapSDK.taptapSdkOptions = coreOption;
TapLog.Enabled = coreOption.enableLog;
platformWrapper?.Init(coreOption);
// 初始化各个模块
Type[] initTaskTypes = GetInitTypeList();
if (initTaskTypes != null)
{
List<IInitTask> initTasks = new List<IInitTask>();
foreach (Type initTaskType in initTaskTypes)
{
initTasks.Add(Activator.CreateInstance(initTaskType) as IInitTask);
}
initTasks = initTasks.OrderBy(task => task.Order).ToList();
foreach (IInitTask task in initTasks)
{
TapLogger.Debug($"Init: {task.GetType().Name}");
task.Init(coreOption);
}
}
TapTapEvent.Init(HandleEventOptions(null));
}
public static void Init(TapTapSdkOptions coreOption, TapTapSdkBaseOptions[] otherOptions)
{
if (coreOption == null)
throw new ArgumentException("[TapSDK] options is null!");
TapTapSDK.taptapSdkOptions = coreOption;
TapLog.Enabled = coreOption.enableLog;
platformWrapper?.Init(coreOption, otherOptions);
Type[] initTaskTypes = GetInitTypeList();
if (initTaskTypes != null)
{
List<IInitTask> initTasks = new List<IInitTask>();
foreach (Type initTaskType in initTaskTypes)
{
initTasks.Add(Activator.CreateInstance(initTaskType) as IInitTask);
}
initTasks = initTasks.OrderBy(task => task.Order).ToList();
foreach (IInitTask task in initTasks)
{
TapLog.Log($"Init: {task.GetType().Name}");
task.Init(coreOption, otherOptions);
}
}
TapTapEvent.Init(HandleEventOptions(otherOptions));
}
/// <summary>
/// 通过初始化属性设置 TapEvent 属性,兼容旧版本
/// </summary>
/// <param name="coreOption"></param>
/// <param name="otherOptions"></param>
/// <returns>TapEvent 属性</returns>
private static TapTapEventOptions HandleEventOptions(
TapTapSdkBaseOptions[] otherOptions = null
)
{
TapTapEventOptions tapEventOptions = null;
if (otherOptions != null && otherOptions.Length > 0)
{
foreach (TapTapSdkBaseOptions otherOption in otherOptions)
{
if (otherOption is TapTapEventOptions option)
{
tapEventOptions = option;
}
}
}
if (tapEventOptions == null)
{
tapEventOptions = new TapTapEventOptions();
}
return tapEventOptions;
}
// UpdateLanguage 方法
public static void UpdateLanguage(TapTapLanguageType language)
{
platformWrapper?.UpdateLanguage(language);
}
// 是否通过 PC 启动器唤起游戏
public static Task<bool> IsLaunchedFromTapTapPC()
{
return platformWrapper?.IsLaunchedFromTapTapPC();
}
#if UNITY_STANDALONE_WIN
/// <summary>
/// 注册 TapTap PC 客户端运行状态监听
/// </summary>
/// <param name="action">监听回调</param>
public static void RegisterTapTapPCStateChangeListener(Action<int> action)
{
platformWrapper?.RegisterTapTapPCStateChangeListener(action);
}
/// <summary>
/// 移除 TapTap PC 客户端运行状态监听
/// </summary>
/// <param name="action">监听回调</param>
public static void UnRegisterTapTapPCStateChangeListener(Action<int> action)
{
platformWrapper?.UnRegisterTapTapPCStateChangeListener(action);
}
#endif
private static Type[] GetInitTypeList(){
Type interfaceType = typeof(IInitTask);
Type[] initTaskTypes = AppDomain.CurrentDomain.GetAssemblies()
.Where(asssembly => asssembly.GetName().FullName.StartsWith("TapSDK"))
.SelectMany(assembly => assembly.GetTypes())
.Where(clazz => interfaceType.IsAssignableFrom(clazz) && clazz.IsClass)
.ToArray();
return initTaskTypes;
}
public static void SendOpenLog(
string project,
string version,
string action,
Dictionary<string, string> properties = null
)
{
platformWrapper.SendOpenLog(project, version, action, properties);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4782af0660aa412ca06e2fa91af5838
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,143 @@
using UnityEngine;
using Newtonsoft.Json;
using System;
namespace TapSDK.Core
{
public interface TapTapSdkBaseOptions
{
string moduleName { get; }
}
public enum TapTapRegionType
{
CN = 0,
Overseas = 1
}
public enum TapTapLanguageType
{
Auto = 0,// 自动
zh_Hans,// 简体中文
en,// 英文
zh_Hant,// 繁体中文
ja,// 日文
ko,// 韩文
th,// 泰文
id,// 印度尼西亚语
de,// 德语
es,// 西班牙语
fr,// 法语
pt,// 葡萄牙语
ru,// 俄罗斯语
tr,// 土耳其语
vi// 越南语
}
public class TapTapSdkOptions : TapTapSdkBaseOptions
{
/// <summary>
/// 客户端 ID开发者后台获取
/// </summary>
public string clientId;
/// <summary>
/// 客户端令牌,开发者后台获取
/// </summary>
public string clientToken;
/// <summary>
/// PC 客户端公钥
/// </summary>
public string clientPublicKey;
/// <summary>
/// 地区CN 为国内Overseas 为海外
/// </summary>
public TapTapRegionType region = TapTapRegionType.CN;
/// <summary>
/// 语言,默认为 Auto默认情况下国内为 zh_Hans海外为 en
/// </summary>
public TapTapLanguageType preferredLanguage = TapTapLanguageType.Auto;
/// <summary>
/// 游戏版本号,如果不传则默认读取应用的版本号
/// </summary>
public string gameVersion = null;
/// <summary>
/// 是否开启日志Release 版本请设置为 false
/// </summary>
public bool enableLog = false;
/// <summary>
/// 屏幕方向0-竖屏 1-横屏
/// </summary>
public int screenOrientation = 1;
[JsonProperty("moduleName")]
private string _moduleName = "TapTapSDKCore";
[JsonIgnore]
public string moduleName
{
get => _moduleName;
}
}
public class TapTapEventOptions : TapTapSdkBaseOptions
{
/// <summary>
/// 是否启用 TapTap Event
/// </summary>
public bool enableTapTapEvent = true;
/// <summary>
/// 渠道,如 AppStore、GooglePlay
/// </summary>
public string channel = null;
/// <summary>
/// 初始化时传入的自定义参数,会在初始化时上报到 device_login 事件
/// </summary>
public string propertiesJson = null;
/// <summary>
/// 是否能够覆盖内置参数,默认为 false
/// </summary>
public bool overrideBuiltInParameters = false;
/// <summary>
/// 是否开启自动上报 IAP 事件
/// </summary>
public bool enableAutoIAPEvent = true;
/// <summary>
/// 是否即用禁用自动上报设备登录事件
/// </summary>
public bool disableAutoLogDeviceLogin = false;
/// <summary>
/// CAID仅国内 iOS
/// </summary>
public string caid = null;
/// <summary>
/// 是否开启广告商 ID 收集,默认为 false
/// </summary>
public bool enableAdvertiserIDCollection = false;
/// <summary>
/// OAID证书, 仅 Android用于上报 OAID 仅 [TapTapRegion.CN] 生效
/// </summary>
public string oaidCert = null;
/// <summary>
/// 是否禁用 OAID 反射
/// </summary>
public bool disableReflectionOAID = true;
[JsonProperty("moduleName")]
private string _moduleName = "TapTapEvent";
[JsonIgnore]
public string moduleName
{
get => _moduleName;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49658d3bba43c49e2a9b4dbca6f1b2ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: