Beispiel #1
0
    static bool ProcessOneCSVFile(string path)
    {
        // 读取csv文件, 生成相应实体类
        // csv文件前几行:
        // Fields
        // Types
        // IsPrimary
        // Description

        var lines = File.ReadAllLines(path);

        var classInfo  = new Dictionary <string, string>();
        var fields     = lines[0].Split(',');
        var types      = lines[1].Split(',');
        var isPrimarys = lines[2].Split(',');

        // 处理前两行
        for (var i = 0; i < fields.Length; i++)
        {
            if (classInfo.ContainsKey(fields[i]))
            {
                Debug.LogErrorFormat("[ConfigTable]: Field '{0}' is already contained in '{1}'. Skip this file.", fields[i], path);
                return(false);
            }
            classInfo.Add(fields[i], types[i]);
        }

        var className = Path.GetFileNameWithoutExtension(path);
        var code      = TableClassTemplate.GenerateClass(classInfo, className, isPrimarys);

        UnityIOHelper.SaveToFile(code, TableClassTemplate.classOutputFolder + className + ".cs");
        return(true);
    }
Beispiel #2
0
        public string SaveMap()
        {
            string path = Application.streamingAssetsPath + "/Maps/Map.json";
            string str  = JsonHelper.SerializeObject(AllRoads);

            UnityIOHelper.SaveToFile(str, path);
            return(str);
        }
Beispiel #3
0
        /// <summary>
        /// 根据章节和关卡加载当前可选择道路
        /// </summary>
        /// <param name="chapter"></param>
        /// <param name="level"></param>
        public void LoadMap()
        {
            string path = Application.streamingAssetsPath + "/Maps/Map.json";

            AllRoads = JsonHelper.DeserializeObject <Dictionary <string, MapData> >(UnityIOHelper.ReadFromFile(path));
            if (AllRoads == null)
            {
                AllRoads = new Dictionary <string, MapData>();
            }
        }