117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.UI;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author YangHua
|
||
//@create 20230914
|
||
//@company QianHuo
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
namespace Utility
|
||
{
|
||
public class ToolUtility
|
||
{
|
||
/// <summary>
|
||
/// 分割字符串
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <returns></returns>
|
||
public static string[] GetInfos(string info, char t)
|
||
{
|
||
string[] result = info.Split(t);
|
||
return result;
|
||
}
|
||
|
||
public static string GetInfo(string info, char t)
|
||
{
|
||
string[] result = info.Split(t);
|
||
return result[1];
|
||
}
|
||
|
||
public static string SubUserNum(string userNum)
|
||
{
|
||
string rightUserNum = "";
|
||
if (userNum.Length == 13)
|
||
{
|
||
var tempstr = userNum.Substring(3, 10);
|
||
if (tempstr.Length.Equals(10))
|
||
{
|
||
rightUserNum = tempstr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
rightUserNum = userNum;
|
||
}
|
||
return rightUserNum;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 剔除字符串
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <param name="eliminate"></param>
|
||
/// <returns></returns>
|
||
public static string GetEliminateInfo(string info, string eliminate)
|
||
{
|
||
string result = info.Replace(eliminate, "");
|
||
return result;
|
||
}
|
||
|
||
|
||
public static bool CheckGuiRaycastObjects()
|
||
{
|
||
PointerEventData eventData = new PointerEventData(EventSystem.current);
|
||
eventData.pressPosition = Input.mousePosition;//touch.position
|
||
eventData.position = Input.mousePosition;//touch.position
|
||
|
||
var results = new List<RaycastResult>();
|
||
//gr.Raycast(eventData, results);
|
||
EventSystem.current.RaycastAll(eventData, results); //使用此方式也可
|
||
return results.Count > 0;
|
||
}
|
||
|
||
public static void ReadFromLocal<T>(string fileName, T monoBehaviour)
|
||
{
|
||
//string path = Application.dataPath + "/StreamingAssets/" + fileName+".json";
|
||
|
||
if (!File.Exists(fileName))
|
||
{
|
||
Debug.Log("没有地址信息");
|
||
return;
|
||
}
|
||
//Debug.Log(path);
|
||
string json = File.ReadAllText(fileName);
|
||
JsonUtility.FromJsonOverwrite(json, monoBehaviour);
|
||
}
|
||
|
||
|
||
public static void WriteToLocal<T>(string fileName, T monoBehaviour)
|
||
{
|
||
string path = Application.dataPath + "/StreamingAssets/" + fileName + ".json";
|
||
string json = JsonUtility.ToJson(monoBehaviour);
|
||
if (!File.Exists(path)) File.Create(path).Close();
|
||
File.WriteAllText(path, json, Encoding.UTF8);
|
||
Debug.Log("path...." + path);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 路径
|
||
/// </summary>
|
||
/// <param name="fileType">xxx.xxxx</param>
|
||
/// <returns></returns>
|
||
public string GetPath(string fileType)
|
||
{
|
||
string path = Application.dataPath + "/StreamingAssets/" + fileType;
|
||
return path;
|
||
}
|
||
}
|
||
}
|