Ai
1 Star 6 Fork 1

dante/UnityGlobalFuncs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FileBuffer.cs 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
dante 提交于 2017-02-13 10:34 +08:00 . 加入obj 的buffer机制;
using System.Collections.Generic;
namespace Game.Global.Buffer
{
/// <summary>
/// 提供缓存机制的 string-string buffer,在超过一定长度之后自动删去之前的文件缓存,采取队列删除策略
/// </summary>
class FileBuffer
{
//文件结构管理
private class CFile
{
public string fileName;
public string fileContent;
public CFile(string fName, string fContent)
{
fileName = fName;
fileContent = fContent;
}
}
List<CFile> g_cfgFileBuffer = new List<CFile>();
int m_maxBufferCount = 3;
public void SetBufferSize(int count)
{
m_maxBufferCount = count;
}
public int GetBufferSize()
{
return m_maxBufferCount;
}
/// <summary>
/// 将文件名、文件内容放入缓冲区
/// </summary>
public void PushToBuffer(string fileName, string fileContent)
{
if (g_cfgFileBuffer.Count + 1 > m_maxBufferCount)
{
//Pop the first one:
g_cfgFileBuffer.RemoveAt(0);
}
g_cfgFileBuffer.Add(new CFile(fileName, fileContent));
}
/// <summary>
/// 获得对应文件名的缓存,如果不存在则返回false
/// </summary>
public bool GetFileContent(string fileName, out string fileContent)
{
for (int i = 0; i < g_cfgFileBuffer.Count; i++)
{
if (g_cfgFileBuffer[i].fileName == fileName)
{
fileContent = g_cfgFileBuffer[i].fileContent;
return true;
}
}
fileContent = null;
return false;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/dragengt/UnityGlobalFuncs.git
git@gitee.com:dragengt/UnityGlobalFuncs.git
dragengt
UnityGlobalFuncs
UnityGlobalFuncs
master

搜索帮助