30 lines
701 B
C#
30 lines
701 B
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public static class LocalTextLoader
|
|
{
|
|
/// <summary>
|
|
/// 从固定路径加载文本文件
|
|
/// </summary>
|
|
/// <param name="filePath">完整文件路径</param>
|
|
/// <returns>文本内容,失败返回 null</returns>
|
|
public static string LoadText(string filePath)
|
|
{
|
|
if (!File.Exists(filePath))
|
|
{
|
|
Debug.LogError($"[LocalTextLoader] 文件不存在: {filePath}");
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
return File.ReadAllText(filePath);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError($"[LocalTextLoader] 读取文件失败: {e.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
}
|