您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
49 行
1.5 KiB
49 行
1.5 KiB
using UnityEngine;
|
|
using System.IO;
|
|
|
|
namespace NaughtyAttributes.Editor
|
|
{
|
|
public static class IOUtility
|
|
{
|
|
public static string GetPersistentDataPath()
|
|
{
|
|
return Application.persistentDataPath + "/";
|
|
}
|
|
|
|
public static void WriteToFile(string filePath, string content)
|
|
{
|
|
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
|
|
{
|
|
using (StreamWriter streamWriter = new StreamWriter(fileStream, System.Text.Encoding.ASCII))
|
|
{
|
|
streamWriter.WriteLine(content);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string ReadFromFile(string filePath)
|
|
{
|
|
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
|
{
|
|
using (StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.ASCII))
|
|
{
|
|
string content = streamReader.ReadToEnd();
|
|
return content;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool FileExists(string filePath)
|
|
{
|
|
return File.Exists(filePath);
|
|
}
|
|
|
|
public static string GetPathRelativeToProjectFolder(string fullPath)
|
|
{
|
|
int indexOfAssetsWord = fullPath.IndexOf("\\Assets");
|
|
string relativePath = fullPath.Substring(indexOfAssetsWord + 1);
|
|
|
|
return relativePath;
|
|
}
|
|
}
|
|
}
|