SDK_UnityMoney/Assets/Script/Utils/DataUtils.cs

39 lines
972 B
C#

using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace WZ
{
public static class DataUtils
{
[System.Serializable]
private class Wrapper<T>
{
public T[] items;
}
public static T[] FromJsonArray<T>(string json)
{
string wrappedJson = $"{{\"items\":{json}}}";
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(wrappedJson);
return wrapper.items;
}
public static double StringToDouble(string str)
{
double result = 0;
if (double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
{
Debug.Log("转换成功: " + result);
}
else
{
Debug.Log("转换失败:字符串格式不正确");
}
return result;
}
}
}