66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.IO;
|
||
|
using UnityEngine;
|
||
|
using System.Linq;
|
||
|
namespace BITKit
|
||
|
{
|
||
|
public static partial class Utility
|
||
|
{
|
||
|
public static class Path
|
||
|
{
|
||
|
[RuntimeInitializeOnLoadMethod]
|
||
|
static void Init()
|
||
|
{
|
||
|
dataPath = Application.dataPath;
|
||
|
persistentDataPath = Application.persistentDataPath;
|
||
|
currentDirectory = System.Environment.CurrentDirectory;
|
||
|
}
|
||
|
public static string dataPath { get; private set; }
|
||
|
public static string persistentDataPath { get; private set; }
|
||
|
public static string currentDirectory { get; private set; }
|
||
|
public static string Get(params string[] nextPaths)
|
||
|
{
|
||
|
currentDirectory = System.Environment.CurrentDirectory;
|
||
|
var path = currentDirectory;
|
||
|
var filePath = System.IO.Path.Combine(currentDirectory, "Assembly-CSharp.csproj");
|
||
|
if (File.Exists(filePath))
|
||
|
{
|
||
|
path = System.IO.Path.Combine(path, "Assets");
|
||
|
}
|
||
|
foreach (var nextPath in nextPaths)
|
||
|
{
|
||
|
path = System.IO.Path.Combine(path, nextPath);
|
||
|
}
|
||
|
return path;
|
||
|
}
|
||
|
public static string CombinePath(params string[] nextPaths)
|
||
|
{
|
||
|
string path = nextPaths[0];
|
||
|
for (int i = 1; i < nextPaths.Length - 1; i++)
|
||
|
{
|
||
|
path += "/" + nextPaths[i];
|
||
|
}
|
||
|
path += "/" + nextPaths.Last();
|
||
|
return path;
|
||
|
}
|
||
|
public static IEnumerable<string> ReadAllFile(string folderPath, string filter = null)
|
||
|
{
|
||
|
if (Directory.Exists(folderPath))
|
||
|
{
|
||
|
DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
|
||
|
|
||
|
var files = directoryInfo.GetFiles()
|
||
|
.OrderBy(x => x.LastWriteTime)
|
||
|
.Select(x => x);
|
||
|
if (filter.IsValid())
|
||
|
{
|
||
|
files = files.Where(x => x.Name.Contains(filter));
|
||
|
}
|
||
|
return files.Select(x => x.ToString());
|
||
|
}
|
||
|
return new List<string>();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|