akadoc/Assets/src/RulesDatabase.cs

50 lines
907 B
C#

using UnityEngine;
using System.IO;
using System.Collections.Generic;
public class RulesDatabase {
public static TwoDA GetTable(string name){
TwoDA t = null;
if(Get().m_tables.TryGetValue(name, out t)){
return t;
}
else
return null;
}
private RulesDatabase(){
m_tables = new Dictionary<string, TwoDA>();
string[] files = Directory.GetFiles(m_folder, "*.2da", SearchOption.AllDirectories);
foreach(string file in files){
string name = Path.GetFileNameWithoutExtension(file);
m_tables.Add(name, new TwoDA(file));
//Debug.Log ("Found "+name);
}
}
private static RulesDatabase inst = null;
private static object syncRoot = new Object();
private static RulesDatabase Get(){
lock(syncRoot){
if(inst==null)
inst = new RulesDatabase();
}
return inst;
}
private Dictionary<string, TwoDA> m_tables;
private string m_folder = "Assets/rules";
}