备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using System;
using ThinkingSDK.PC.Config;
using ThinkingSDK.PC.Constant;
using UnityEngine;
namespace ThinkingSDK.PC.Utils
{
public class ThinkingSDKAppInfo
{
// sdk version
public static string LibVersion()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.LIB_VERSION))
{
return "";
}
return ThinkingSDKPublicConfig.Version() ;
}
// sdk name
public static string LibName()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.LIB))
{
return "";
}
return ThinkingSDKPublicConfig.Name();
}
// app version
public static string AppVersion()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.APP_VERSION))
{
return "";
}
return Application.version;
}
// app identifier, bundle ID
public static string AppIdentifier()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.APP_BUNDLEID))
{
return "";
}
return Application.identifier;
}
}
}

View File

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

View File

@@ -0,0 +1,229 @@
using System;
using ThinkingSDK.PC.Constant;
using ThinkingSDK.PC.Storage;
using UnityEngine;
namespace ThinkingSDK.PC.Utils
{
public class ThinkingSDKDeviceInfo
{
// devide ID
public static string DeviceID()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.DEVICE_ID))
{
return "";
}
#if (UNITY_WEBGL)
return RandomDeviceID();
#else
return SystemInfo.deviceUniqueIdentifier;
#endif
}
// A persistent random number, used as an alternative to the device ID (WebGL cannot obtain the device ID)
private static string RandomDeviceID()
{
string randomID = (string)ThinkingSDKFile.GetData(ThinkingSDKConstant.RANDOM_DEVICE_ID, typeof(string));
if (string.IsNullOrEmpty(randomID))
{
randomID = System.Guid.NewGuid().ToString("N");
ThinkingSDKFile.SaveData(ThinkingSDKConstant.RANDOM_DEVICE_ID, randomID);
}
return randomID;
}
// network type
public static string NetworkType()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.NETWORK_TYPE))
{
return "";
}
string networkType = "NULL";
if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
{
networkType = "Mobile";
}
else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
networkType = "LAN";
}
return networkType;
}
// carrier name
public static string Carrier()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.CARRIER))
{
return "";
}
return "NULL";
}
// os name
public static string OS()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.OS))
{
return "";
}
string os = "other";
if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux)
{
os = "Linux";
}
else if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
{
os = "MacOSX";
}
else if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows)
{
os = "Windows";
}
return os;
}
// os version
public static string OSVersion()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.OS_VERSION))
{
return "";
}
return SystemInfo.operatingSystem;
}
// device screen width
public static int ScreenWidth()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.SCREEN_WIDTH))
{
return 0;
}
return (int)(UnityEngine.Screen.currentResolution.width);
}
// device screen height
public static int ScreenHeight()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.SCREEN_HEIGHT))
{
return 0;
}
return (int)(UnityEngine.Screen.currentResolution.height);
}
// graphics card manufacturer name
public static string Manufacture()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.MANUFACTURE))
{
return "";
}
return SystemInfo.graphicsDeviceVendor;
}
// devide model
public static string DeviceModel()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.DEVICE_MODEL))
{
return "";
}
return SystemInfo.deviceModel;
}
// device language
public static string MachineLanguage()
{
if (ThinkingSDKUtil.DisPresetProperties.Contains(ThinkingSDKConstant.SYSTEM_LANGUAGE))
{
return "";
}
switch (Application.systemLanguage)
{
case SystemLanguage.Afrikaans:
return "af";
case SystemLanguage.Arabic:
return "ar";
case SystemLanguage.Basque:
return "eu";
case SystemLanguage.Belarusian:
return "be";
case SystemLanguage.Bulgarian:
return "bg";
case SystemLanguage.Catalan:
return "ca";
case SystemLanguage.Chinese:
return "zh";
case SystemLanguage.Czech:
return "cs";
case SystemLanguage.Danish:
return "da";
case SystemLanguage.Dutch:
return "nl";
case SystemLanguage.English:
return "en";
case SystemLanguage.Estonian:
return "et";
case SystemLanguage.Faroese:
return "fo";
case SystemLanguage.Finnish:
return "fu";
case SystemLanguage.French:
return "fr";
case SystemLanguage.German:
return "de";
case SystemLanguage.Greek:
return "el";
case SystemLanguage.Hebrew:
return "he";
case SystemLanguage.Icelandic:
return "is";
case SystemLanguage.Indonesian:
return "id";
case SystemLanguage.Italian:
return "it";
case SystemLanguage.Japanese:
return "ja";
case SystemLanguage.Korean:
return "ko";
case SystemLanguage.Latvian:
return "lv";
case SystemLanguage.Lithuanian:
return "lt";
case SystemLanguage.Norwegian:
return "nn";
case SystemLanguage.Polish:
return "pl";
case SystemLanguage.Portuguese:
return "pt";
case SystemLanguage.Romanian:
return "ro";
case SystemLanguage.Russian:
return "ru";
case SystemLanguage.SerboCroatian:
return "sr";
case SystemLanguage.Slovak:
return "sk";
case SystemLanguage.Slovenian:
return "sl";
case SystemLanguage.Spanish:
return "es";
case SystemLanguage.Swedish:
return "sv";
case SystemLanguage.Thai:
return "th";
case SystemLanguage.Turkish:
return "tr";
case SystemLanguage.Ukrainian:
return "uk";
case SystemLanguage.Vietnamese:
return "vi";
case SystemLanguage.ChineseSimplified:
return "zh";
case SystemLanguage.ChineseTraditional:
return "zh";
case SystemLanguage.Hungarian:
return "hu";
case SystemLanguage.Unknown:
return "unknown";
};
return "";
}
}
}

View File

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

View File

@@ -0,0 +1,630 @@
/*
* MIT License. Forked from GA_MiniJSON.
* I modified it so that it could be used for TD limitations.
*/
// using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Globalization;
namespace ThinkingSDK.PC.Utils
{
/* Based on the JSON parser from
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* I simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*/
/// <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 ArrayList and Hashtable.
/// All numbers are parsed to floats.
/// </summary>
public class ThinkingSDKJSON
{
/// <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 Dictionary<string, object> Deserialize(string json)
{
// save the string for debug information
if (json == null)
{
return null;
}
return Parser.Parse(json);
}
// Use caution!
public static List<object> DeserializeArray(string json)
{
// save the string for debug information
if (json == null)
{
return null;
}
return Parser.ParseArray(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 Dictionary<string, object> Parse(string jsonString)
{
using (var instance = new Parser(jsonString))
{
return instance.ParseObject();
}
}
public static List<object> ParseArray(string jsonString)
{
using (var instance = new Parser(jsonString))
{
return instance.ParseArray();
}
}
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:
string str = ParseString();
DateTime dateTime;
if (DateTime.TryParseExact(str, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
{
return dateTime;
}
return str;
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, out parsedInt);
return parsedInt;
}
double parsedDouble;
if (!Double.TryParse(number, System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out parsedDouble))
{
Double.TryParse(number, System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.CreateSpecificCulture("es-ES"), 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, Func<DateTime, string> func = null)
{
return Serializer.Serialize(obj, func);
}
sealed class Serializer
{
StringBuilder builder;
Func<DateTime, string> func;
Serializer()
{
builder = new StringBuilder();
}
public static string Serialize(object obj, Func<DateTime, string> func)
{
var instance = new Serializer();
instance.func = func;
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", System.Globalization.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)
{
builder.Append(Convert.ToDouble(value).ToString("R", System.Globalization.CultureInfo.InvariantCulture));
}
else if (value is decimal) {
builder.Append(Convert.ToDecimal(value).ToString("G", System.Globalization.CultureInfo.InvariantCulture));
}
else if (value is DateTime)
{
builder.Append('\"');
DateTime dateTime = (DateTime)value;
if (null != func)
{
builder.Append(func((DateTime)value));
}
else
{
builder.Append(dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture));
}
builder.Append('\"');
}
else
{
SerializeString(value.ToString());
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,23 @@
using System;
using System.IO;
using ThinkingSDK.PC.Constant;
using ThinkingSDK.PC.Config;
using UnityEngine;
namespace ThinkingSDK.PC.Utils
{
public class ThinkingSDKLogger
{
public ThinkingSDKLogger()
{
}
public static void Print(string str)
{
if (ThinkingSDKPublicConfig.IsPrintLog())
{
Debug.Log("[ThinkingData] Info: " + str);
}
}
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ThinkingSDK.PC.Utils
{
public class ThinkingSDKTimeUtil
{
public static string Time()
{
return "";
}
}
}

View File

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

View File

@@ -0,0 +1,199 @@
using UnityEngine;
using System;
using System.Xml;
using System.Collections.Generic;
using ThinkingSDK.PC.Config;
using ThinkingSDK.PC.Constant;
using ThinkingSDK.PC.Storage;
namespace ThinkingSDK.PC.Utils
{
public class ThinkingSDKUtil
{
private static Dictionary<string, object> deviceInfo = null;
public ThinkingSDKUtil()
{
}
public static List<string> DisPresetProperties = ThinkingSDKUtil.GetDisPresetProperties();
/*
* Check if the URL is valid
*/
public static bool IsValiadURL(string url)
{
return !(url == null || url.Length == 0 || !url.Contains("http") || !url.Contains("https"));
}
/*
* Check if the string is empty
*/
public static bool IsEmptyString(string str)
{
return (str == null || str.Length == 0);
}
public static Dictionary<string, object> DeviceInfo()
{
if (deviceInfo == null)
{
deviceInfo = new Dictionary<string, object>();
deviceInfo[ThinkingSDKConstant.DEVICE_ID] = ThinkingSDKDeviceInfo.DeviceID();
//deviceInfo[ThinkingSDKConstant.CARRIER] = ThinkingSDKDeviceInfo.Carrier(); //PC端不采集
deviceInfo[ThinkingSDKConstant.OS] = ThinkingSDKDeviceInfo.OS();
deviceInfo[ThinkingSDKConstant.OS_VERSION] = ThinkingSDKDeviceInfo.OSVersion();
deviceInfo[ThinkingSDKConstant.SCREEN_HEIGHT] = ThinkingSDKDeviceInfo.ScreenHeight();
deviceInfo[ThinkingSDKConstant.SCREEN_WIDTH] = ThinkingSDKDeviceInfo.ScreenWidth();
deviceInfo[ThinkingSDKConstant.MANUFACTURE] = ThinkingSDKDeviceInfo.Manufacture();
deviceInfo[ThinkingSDKConstant.DEVICE_MODEL] = ThinkingSDKDeviceInfo.DeviceModel();
deviceInfo[ThinkingSDKConstant.APP_VERSION] = ThinkingSDKAppInfo.AppVersion();
deviceInfo[ThinkingSDKConstant.APP_BUNDLEID] = ThinkingSDKAppInfo.AppIdentifier();
deviceInfo[ThinkingSDKConstant.LIB] = ThinkingSDKAppInfo.LibName();
deviceInfo[ThinkingSDKConstant.LIB_VERSION] = ThinkingSDKAppInfo.LibVersion();
}
deviceInfo[ThinkingSDKConstant.SYSTEM_LANGUAGE] = ThinkingSDKDeviceInfo.MachineLanguage();
deviceInfo[ThinkingSDKConstant.NETWORK_TYPE] = ThinkingSDKDeviceInfo.NetworkType();
return deviceInfo;
}
// Get disabled preset properties
private static List<string> GetDisPresetProperties()
{
List<string> properties = new List<string>();
TextAsset textAsset = Resources.Load<TextAsset>("ta_public_config");
if (textAsset != null && textAsset.text != null)
{
XmlDocument xmlDoc = new XmlDocument();
// xmlDoc.Load(srcPath);
xmlDoc.LoadXml(textAsset.text);
XmlNode root = xmlDoc.SelectSingleNode("resources");
for (int i=0; i<root.ChildNodes.Count; i++)
{
XmlNode x1 = root.ChildNodes[i];
if (x1.NodeType == XmlNodeType.Element)
{
XmlElement e1 = x1 as XmlElement;
if (e1.HasAttributes)
{
string name = e1.GetAttribute("name");
if (name == "TDDisPresetProperties" && e1.HasChildNodes)
{
for (int j=0; j<e1.ChildNodes.Count; j++)
{
XmlNode x2 = e1.ChildNodes[j];
if (x2.NodeType == XmlNodeType.Element)
{
properties.Add(x2.InnerText);
}
}
}
}
}
}
}
return properties;
}
// A persistent random number, used as an alternative to the distinct ID
public static string RandomID(bool persistent = true)
{
string randomID = null;
if (persistent)
{
randomID = (string)ThinkingSDKFile.GetData(ThinkingSDKConstant.RANDOM_ID, typeof(string));
}
if (string.IsNullOrEmpty(randomID))
{
randomID = System.Guid.NewGuid().ToString("N");
if (persistent)
{
ThinkingSDKFile.SaveData(ThinkingSDKConstant.RANDOM_ID, randomID);
}
}
return randomID;
}
// Get time zone offset
public static double ZoneOffset(DateTime dateTime, TimeZoneInfo timeZone)
{
bool success = true;
TimeSpan timeSpan = new TimeSpan();
try
{
timeSpan = timeZone.BaseUtcOffset;
}
catch (Exception)
{
success = false;
//if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("ZoneOffset: TimeSpan get failed : " + e.Message);
}
try
{
if (timeZone.IsDaylightSavingTime(dateTime))
{
TimeSpan timeSpan1 = TimeSpan.FromHours(1);
timeSpan = timeSpan.Add(timeSpan1);
}
}
catch (Exception)
{
success = false;
//if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("ZoneOffset: IsDaylightSavingTime get failed : " + e.Message);
}
if (success == false)
{
timeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
}
return timeSpan.TotalHours;
}
// time formatting
public static string FormatDate(DateTime dateTime, TimeZoneInfo timeZone)
{
bool success = true;
DateTime univDateTime = dateTime.ToUniversalTime();
TimeSpan timeSpan = new TimeSpan();
try
{
timeSpan = timeZone.BaseUtcOffset;
}
catch (Exception)
{
success = false;
//if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("FormatDate - TimeSpan get failed : " + e.Message);
}
try
{
if (timeZone.IsDaylightSavingTime(dateTime))
{
TimeSpan timeSpan1 = TimeSpan.FromHours(1);
timeSpan = timeSpan.Add(timeSpan1);
}
}
catch (Exception)
{
success = false;
//if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("FormatDate: IsDaylightSavingTime get failed : " + e.Message);
}
if (success == false)
{
timeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
}
DateTime dateNew = univDateTime + timeSpan;
return dateNew.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);
}
// add Dictionary to Dictionary
public static void AddDictionary(Dictionary<string, object> originalDic, Dictionary<string, object> subDic)
{
if (originalDic != subDic)
{
foreach (KeyValuePair<string, object> kv in subDic)
{
originalDic[kv.Key] = kv.Value;
}
}
}
//get timestamp
public static long GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalMilliseconds);
}
}
}

View File

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