81 lines
1.7 KiB
C#
81 lines
1.7 KiB
C#
using System.Diagnostics;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public static class FileSystem
|
|
{
|
|
public static bool LogDebug;
|
|
|
|
public static bool LogTime;
|
|
|
|
public static FileSystemBackend Backend;
|
|
|
|
public static bool IsBundled
|
|
{
|
|
get
|
|
{
|
|
if (Application.isPlaying)
|
|
{
|
|
return Backend is AssetBundleBackend;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static GameObject[] LoadPrefabs(string folder)
|
|
{
|
|
return Backend.LoadPrefabs(folder);
|
|
}
|
|
|
|
public static GameObject LoadPrefab(string filePath)
|
|
{
|
|
return Backend.LoadPrefab(filePath);
|
|
}
|
|
|
|
public static string[] FindAll(string folder, string search = "")
|
|
{
|
|
return Backend.FindAll(folder, search);
|
|
}
|
|
|
|
public static T[] LoadAll<T>(string folder, string search = "") where T : Object
|
|
{
|
|
if (!folder.IsLower())
|
|
{
|
|
folder = folder.ToLower();
|
|
}
|
|
return Backend.LoadAll<T>(folder, search);
|
|
}
|
|
|
|
public static T[] LoadAllFromBundle<T>(string bundleName, string editorSearch) where T : Object
|
|
{
|
|
return Backend.LoadAllFromBundle<T>(bundleName, editorSearch);
|
|
}
|
|
|
|
public static T Load<T>(string filePath, bool complain = true) where T : Object
|
|
{
|
|
if (!filePath.IsLower())
|
|
{
|
|
filePath = filePath.ToLower();
|
|
}
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
if (LogDebug)
|
|
{
|
|
File.AppendAllText("filesystem_debug.csv", $"{filePath}\n");
|
|
}
|
|
T val = Backend.Load<T>(filePath);
|
|
if (complain && val == null)
|
|
{
|
|
UnityEngine.Debug.LogWarning("[FileSystem] Not Found: " + filePath + " (" + typeof(T)?.ToString() + ")");
|
|
}
|
|
if (LogTime)
|
|
{
|
|
File.AppendAllText("filesystem.csv", $"{filePath},{stopwatch.Elapsed.TotalMilliseconds}\n");
|
|
}
|
|
return val;
|
|
}
|
|
|
|
public static bool HasAsset(string filePath)
|
|
{
|
|
return Backend.HasAsset(filePath);
|
|
}
|
|
}
|