コード例 #1
0
ファイル: DTRole.cs プロジェクト: Enanyy/moon
    /// <summary>
    /// 注释XXXX_BEGIN和XXXX_END为替换区域,这些注释不能删除否则自动生成代码会失败,并且自定义内容不能写在注释之间,否则下次自动生成内容时会覆盖掉。
    /// </summary>
    public void Read(SQLiteTable table)
    {
        if (table == null)
        {
            return;
        }
        dic.Clear();
        list.Clear();
        while (table.Read())
        {
//TABLE_READ_BEGIN
            TBRole o = new TBRole();
            o.id     = table.GetByColumnName("id", 0);
            o.name   = table.GetByColumnName("name", "");
            o.type   = table.GetByColumnName("type", 0);
            o.height = table.GetByColumnName("height", 0f);
            o.desc   = table.GetByColumnName("desc", "");
            o.weigth = table.GetByColumnName("weigth", 0f);
            o.config = table.GetByColumnName("config", 0);
            o.y      = table.GetByColumnName("y", 0);
            dic.Add(o.id, o);
            list.Add(o);
//TABLE_READ_END
        }
    }
コード例 #2
0
    static void ExportDataTables()
    {
        if (SQLite.Instance.Open(database))
        {
            SQLiteTable table = SQLite.Instance.GetTables();
            if (table != null)
            {
                List <string> tableNames = new List <string>();
                while (table.Read())
                {
                    string tableName = table.GetByColumnName("name", "");

                    tableNames.Add(tableName);
                }
                table.Close();

                ExportDataTables(tableNames);
            }
            SQLite.Instance.Close();
        }

        else
        {
            Debug.LogError("Can't open database:" + database);
        }
    }
コード例 #3
0
    /// <summary>
    /// 注释XXXX_BEGIN和XXXX_END为替换区域,这些注释不能删除否则自动生成代码会失败,并且自定义内容不能写在注释之间,否则下次自动生成内容时会覆盖掉。
    /// </summary>
    public void Read(SQLiteTable table)
    {
        if (table == null)
        {
            return;
        }
        dic.Clear();
        list.Clear();
        while (table.Read())
        {
//TABLE_READ_BEGIN
            TBLanguage o = new TBLanguage();
            o.key = table.GetByColumnName("key", "");
            o.ch  = table.GetByColumnName("ch", "");
            o.en  = table.GetByColumnName("en", "");
            dic.Add(o.key, o);
            list.Add(o);
//TABLE_READ_END
        }
    }
コード例 #4
0
 private void OnEnable()
 {
     mTableNames.Clear();
     if (SQLite.Instance.Open(database))
     {
         SQLiteTable table = SQLite.Instance.GetTables();
         mTableNames.Add("All");
         if (table != null)
         {
             while (table.Read())
             {
                 string tableName = table.GetByColumnName("name", "");
                 mTableNames.Add(tableName);
             }
             table.Close();
         }
     }
 }
コード例 #5
0
    static void ExportDataTable(string tableName, string fileName, string className)
    {
        if (string.IsNullOrEmpty(tableName))
        {
            return;
        }

        if (SQLite.Instance.IsOpen() == false)
        {
            if (SQLite.Instance.Open(database) == false)
            {
                Debug.LogError("无法打开数据库:" + database);
                return;
            }
        }
        SQLiteTable info = SQLite.Instance.GetTableInfo(tableName);

        if (info == null)
        {
            Debug.LogError("无法读取表" + tableName + "信息");
            return;
        }

        string path       = string.Format("{0}/Scripts/Data/Tables/{1}.cs", Application.dataPath, fileName);
        string definition = "";
        string read       = string.Format("\t{0} o = new {1}();\n", className, className);
        string keyName    = null;
        string keyType    = null;

        while (info.Read())
        {
            string columnName = info.GetByColumnName("name", "");
            string columnType = GetType(info.GetByColumnName("type", ""));

            if (string.IsNullOrEmpty(keyName))
            {
                keyName = columnName;
            }
            if (string.IsNullOrEmpty(keyType))
            {
                keyType = columnType;
            }

            definition += string.Format("\tpublic {0} {1};\n", columnType, columnName);
            read       += string.Format("\t\t\to.{0} = table.GetByColumnName(\"{1}\", {2});\n", columnName, columnName, GetDefaultValue(columnType));
        }

        read += string.Format("\t\t\tdic.Add(o.{0},o);\n\t\t\tlist.Add(o);", keyName);

        info.Close();


        if (File.Exists(path) == false)
        {
            string code = template.Replace("{filename}", fileName)
                          .Replace("{definition}", definition)
                          .Replace("{classname}", className)
                          .Replace("{tablename}", tableName)
                          .Replace("{read}", read)
                          .Replace("{key}", keyType);

            Debug.Log(code);

            FileEx.SaveFile(path, code);
        }
        else
        {
            string datatable = File.ReadAllText(path);
            datatable = datatable.ReplaceEx("//TABLE_DEFINITION_BEGIN", "//TABLE_DEFINITION_END", definition);
            datatable = datatable.ReplaceEx("//TABLE_READ_BEGIN", "//TABLE_READ_END", "\t\t" + read + "\n");

            FileEx.SaveFile(path, datatable);
        }

        Debug.Log("成功导出数据表:" + tableName);
    }
コード例 #6
0
ファイル: DTHero.cs プロジェクト: Enanyy/moon
    /// <summary>
    /// 注释XXXX_BEGIN和XXXX_END为替换区域,这些注释不能删除否则自动生成代码会失败,并且自定义内容不能写在注释之间,否则下次自动生成内容时会覆盖掉。
    /// </summary>

    public void Read(SQLiteTable table)
    {
        if (table == null)
        {
            return;
        }
        dic.Clear();
        list.Clear();
        while (table.Read())
        {
//TABLE_READ_BEGIN
            TBHero o = new TBHero();
            o.id             = table.GetByColumnName("id", 0);
            o.name           = table.GetByColumnName("name", "");
            o.type           = table.GetByColumnName("type", 0);
            o.config         = table.GetByColumnName("config", "");
            o.hp             = table.GetByColumnName("hp", 0);
            o.attack         = table.GetByColumnName("attack", 0);
            o.defense        = table.GetByColumnName("defense", 0);
            o.movedistance   = table.GetByColumnName("movedistance", 0);
            o.movedirection  = table.GetByColumnName("movedirection", 0);
            o.attackdistance = table.GetByColumnName("attackdistance", 0);
            o.searchdistance = table.GetByColumnName("searchdistance", 0);
            o.radius         = table.GetByColumnName("radius", 0f);
            o.height         = table.GetByColumnName("height", 0f);
            dic.Add(o.id, o);
            list.Add(o);
//TABLE_READ_END
        }
    }