当前位置: 首页 > news >正文

有哪些网站做的比较好看江门网站定制多少钱

有哪些网站做的比较好看,江门网站定制多少钱,wordpress分享积分,怎样在手机上制作网站1.为编辑器菜单栏添加新的选项入口 通过Unity提供的MenuItem特性在菜单栏添加选项按钮 特性名:MenuItem 命名空间:UnityEditor 要求:一定是静态方法;新建的这个菜单栏按钮 必须有至少一个斜杠 不然会报错 它不支持只有一个菜单…

1.为编辑器菜单栏添加新的选项入口

通过Unity提供的MenuItem特性在菜单栏添加选项按钮

特性名:MenuItem
命名空间:UnityEditor

要求:一定是静态方法;新建的这个菜单栏按钮 必须有至少一个斜杠 不然会报错 它不支持只有一个菜单栏入口 ;这个特性可以用在任意的类当中

    [MenuItem("GameTool/Test")]private static void Test(){Directory.CreateDirectory(Application.dataPath + "/测试文件夹");AssetDatabase.Refresh();}

同时,通过以上方式,可以调用后自动刷新窗口

类名:AssetDatabase

命名空间:UnityEditor

方法:Refresh

补充:Editor文件夹

Editor文件夹可以放在项目的任何文件夹下,可以有多个,放在其中的内容,项目打包时不会被打包到项目中。一般编辑器相关代码都可以放在该文件夹中

同时不能再非editor的文件夹下的脚本调用editor文件夹下的脚本

2.导入ExcelDll包

Excel表的本质:Excel表本质上也是一堆数据,有自己的存储读取规则

DLL文件用来解析Excel文件的

Dll文件:库文件,可以理解为它是许多代码的集合,将相关代码集合在库文件中可以方便迁移和使用,方便用户直接使用

(建议放在editor文件夹下)

3.Excel数据读取

利用FileStream读取文件流,再利用IExcelDataReader类,从流中读取Excel数据,使用DataSet数据集合类,将Excel数据转存进其中方便读取

        using (FileStream fs = File.Open(Application.dataPath + "/ArtRes/Excel/PlayerInfo.xlsx", FileMode.Open, FileAccess.Read )){//通过文件流获取Excel数据IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);//将excel表中的数据转换为DataSet数据类型 方便获取其中的内容DataSet result = excelReader.AsDataSet();//得到Excel文件中的所有表信息for (int i = 0; i < result.Tables.Count; i++){Debug.Log("表名:" + result.Tables[i].TableName);Debug.Log("行数:" + result.Tables[i].Rows.Count);Debug.Log("列数:" + result.Tables[i].Columns.Count);}fs.Close();}

获取Excel表中单元格的信息

using (FileStream fs = File.Open(Application.dataPath + "/ArtRes/Excel/PlayerInfo.xlsx", FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);DataSet result = excelReader.AsDataSet();for (int i = 0; i < result.Tables.Count; i++){DataTable table = result.Tables[i];DataRow row;for (int j = 0; j < table.Rows.Count; j++){//得到每一行的信息row = table.Rows[j];for (int k = 0; k < table.Columns.Count; k++){Debug.Log(row[k].ToString());}}}fs.Close();}

DataTable 数据表类:表示Excel文件中的一个表

DataRow 数据行类:表示某张表中的一行数据

可以根据表中数据来动态的生成相关数据:数据结构类;容器类;2进制数据

为什么不直接读取Excel表而要把它转成2进制数据?

提升读取效率和数据安全性

4.制定配置表的相关规则

数据结构类

容器:放一个字典,存储整张表的数据,对应数据结构类的类型,key利用唯一ID来设置(保证主键不一样)

二进制数据

5.读取Excel目录下所有的excel文件

声明文件存放的路径

public static string EXCEL_PATH = Application.dataPath + "/ArtRes/Excel/";

加载指定路径中的所有Excel文件,用于生成对应的3个文件

        DirectoryInfo dInfo = Directory.CreateDirectory(EXCEL_PATH);//得到指定路径中的所有文件信息 相当于就是得到所有的Excel表FileInfo[] files = dInfo.GetFiles();

遍历数组中所有的内容,其中会有meta文件,之后操作中无需对其进行处理

for (int i = 0; i < files.Length; i++){if (files[i].Extension != ".xlsx" &&files[i].Extension != ".xls")continue;
}

files[i].Extension 记录的是文件的后缀名

设置数据类容器

DataTableCollection tableConllection;

打开一个Excel文件得到其中的所有表的数据

            using (FileStream fs = files[i].Open(FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);tableConllection = excelReader.AsDataSet().Tables;fs.Close();}

遍历文件中的所有表的信息

            foreach (DataTable table in tableConllection){Debug.Log(table.TableName);}

6.生成数据结构类

创建生成Excel表对应的数据结构类

    private static void GenerateExcelDataClass(DataTable table){}

获取变量名所在行

    private static DataRow GetVariableNameRow(DataTable table){return table.Rows[0];}

获取变量类型所在行

    private static DataRow GetVariableTypeRow(DataTable table){return table.Rows[1];}

回到生成Excel表对应的数据结构类

   private static void GenerateExcelDataClass(DataTable table){//字段名行DataRow rowName = GetVariableNameRow(table);//字段类型行DataRow rowType = GetVariableTypeRow(table);}

设置数据结构类脚本存储位置路径

public static string DATA_CLASS_PATH = Application.dataPath + "/Scripts/ExcelData/DataClass/";

生成对应的数据结构类脚本(通过代码进行字符串拼接 然后存进文件)

        //判断路径是否存在 没有的话 就创建文件夹if (!Directory.Exists(DATA_CLASS_PATH))Directory.CreateDirectory(DATA_CLASS_PATH);string str = "public class " + table.TableName + "\n{\n";//变量进行字符串拼接for (int i = 0; i < table.Columns.Count; i++){str += "    public " + rowType[i].ToString() + " " + rowName[i].ToString() + ";\n";}str += "}";

把拼接好的字符串存到指定文件中去

 File.WriteAllText(DATA_CLASS_PATH + table.TableName + ".cs", str);

最后刷新Project窗口

AssetDatabase.Refresh();

7.生成容器类

利用字典,表示一张表的数据

创建Excel表对应的数据容器类

    private static void GenerateExcelContainer(DataTable table){}

获取主键索引

    private static int GetKeyIndex(DataTable table){DataRow row = table.Rows[2];for (int i = 0; i < table.Columns.Count; i++){if (row[i].ToString() == "key")return i;}return 0;}

获取变量类型所在行

    private static DataRow GetVariableTypeRow(DataTable table){return table.Rows[1];}

得到主键索引

int keyIndex = GetKeyIndex(table);

得到字段类型行

DataRow rowType = GetVariableTypeRow(table);

设置容器类脚本存储位置路径

public static string DATA_CONTAINER_PATH = Application.dataPath + "/Scripts/ExcelData/Container/";

具体容器类内部逻辑

        //没有路径创建路径if (!Directory.Exists(DATA_CONTAINER_PATH))Directory.CreateDirectory(DATA_CONTAINER_PATH);string str = "using System.Collections.Generic;\n";str += "public class " + table.TableName + "Container" + "\n{\n";str += "    ";str += "public Dictionary<" + rowType[keyIndex].ToString() + ", " + table.TableName + ">";str += "dataDic = new " + "Dictionary<" + rowType[keyIndex].ToString() + ", " + table.TableName + ">();\n";str += "}";File.WriteAllText(DATA_CONTAINER_PATH + table.TableName + "Container.cs", str);

刷新Project窗口

        AssetDatabase.Refresh();

8.生成二进制数据

生成excel 2进制数据

    private static void GenerateExcelBinary(DataTable table){}

可以利用StreamingAssets在非编辑模式下,是只读状态

2进制数据存储位置路径

public static string DATA_BINARY_PATH = Application.streamingAssetsPath + "/Binary/";

创建一个2进制文件进行写入

FileStream fs = new FileStream(DATA_BINARY_PATH + table.TableName + ".yuan", FileMode.OpenOrCreate, FileAccess.Write)

存储具体的excel对应的2进制信息

存储我们需要写多少行的数据,方便读取

fs.Write(BitConverter.GetBytes(table.Rows.Count - 4), 0, 4);

存储主键的变量名

            string keyName = GetVariableNameRow(table)[GetKeyIndex(table)].ToString();byte[] bytes = Encoding.UTF8.GetBytes(keyName);

存储字符串字节数组的长度

fs.Write(BitConverter.GetBytes(bytes.Length), 0, 4);

存储字符串字节数组

fs.Write(bytes, 0, bytes.Length);

得到类型行 根据类型来决定应该如何写入数据

DataRow rowType = GetVariableTypeRow(table);

遍历所有内容的行 进行2进制的写入

            DataRow row;DataRow rowType = GetVariableTypeRow(table);for (int i = BEGIN_INDEX; i < table.Rows.Count; i++){//得到一行的数据row = table.Rows[i];for (int j = 0; j < table.Columns.Count; j++){switch (rowType[j].ToString()){case "int":fs.Write(BitConverter.GetBytes(int.Parse(row[j].ToString())), 0, 4);break;case "float":fs.Write(BitConverter.GetBytes(float.Parse(row[j].ToString())), 0, 4);break;case "bool":fs.Write(BitConverter.GetBytes(bool.Parse(row[j].ToString())), 0, 1);break;case "string":bytes = Encoding.UTF8.GetBytes(row[j].ToString());//写入字符串字节数组的长度fs.Write(BitConverter.GetBytes(bytes.Length), 0, 4);//写入字符串字节数组fs.Write(bytes, 0, bytes.Length);break;}}}fs.Close();

最后别忘了刷新Project窗口

AssetDatabase.Refresh();

9.Excel数据文件的使用

创建用于存储所有Excel表数据的容器

private Dictionary<string, object> tableDic = new Dictionary<string, object>();

数据存储的位置

private static string SAVE_PATH = Application.persistentDataPath + "/Data/";

读取excel表对应的2进制文件,根据结构体类名进行判断

using (FileStream fs = File.Open(DATA_BINARY_PATH + typeof(K).Name + ".tang", FileMode.Open, FileAccess.Read)){}

记录读取信息

            byte[] bytes = new byte[fs.Length];fs.Read(bytes, 0, bytes.Length);fs.Close();//用于记录当前读取了多少字节了int index = 0;//读取多少行数据int count = BitConverter.ToInt32(bytes, index);index += 4;//读取主键的名字int keyNameLength = BitConverter.ToInt32(bytes, index);index += 4;string keyName = Encoding.UTF8.GetString(bytes, index, keyNameLength);index += keyNameLength;

创建容器类对象(通过反射)

            Type contaninerType = typeof(T);object contaninerObj = Activator.CreateInstance(contaninerType);

(Activator根据type创建对象)

得到数据结构类的Type

Type classType = typeof(K);

通过反射来得到数据结构类所有字段的信息

FieldInfo[] infos = classType.GetFields();

读取每一行的信息

            for (int i = 0; i < count; i++){//实例化一个数据结构类 对象object dataObj = Activator.CreateInstance(classType);foreach (FieldInfo info in infos){if( info.FieldType == typeof(int) ){//相当于就是把2进制数据转为int 然后赋值给了对应的字段info.SetValue(dataObj, BitConverter.ToInt32(bytes, index));index += 4;}else if (info.FieldType == typeof(float)){info.SetValue(dataObj, BitConverter.ToSingle(bytes, index));index += 4;}else if (info.FieldType == typeof(bool)){info.SetValue(dataObj, BitConverter.ToBoolean(bytes, index));index += 1;}else if (info.FieldType == typeof(string)){//读取字符串字节数组的长度int length = BitConverter.ToInt32(bytes, index);index += 4;info.SetValue(dataObj, Encoding.UTF8.GetString(bytes, index, length));index += length;}}

每次读取完一行的数据,便把这个数据添加到容器对象中

                object dicObject = contaninerType.GetField("dataDic").GetValue(contaninerObj);//通过字典对象得到其中的 Add方法MethodInfo mInfo = dicObject.GetType().GetMethod("Add");//得到数据结构类对象中 指定主键字段的值object keyValue = classType.GetField(keyName).GetValue(dataObj);mInfo.Invoke(dicObject, new object[] { keyValue, dataObj });

把读取完的表记录下来

            tableDic.Add(typeof(T).Name, contaninerObj);fs.Close();

10.工具包导出

书写相关帮助文档

创建测试工程、

        BinaryDataMgr.Instance.InitData();TowerInfoContainer data = BinaryDataMgr.Instance.GetTable<TowerInfoContainer>();


文章转载自:
http://dinncocaffeinism.bkqw.cn
http://dinncofusil.bkqw.cn
http://dinncoappendent.bkqw.cn
http://dinncoplateresque.bkqw.cn
http://dinncocarbamyl.bkqw.cn
http://dinncostrepsiceros.bkqw.cn
http://dinncofalchion.bkqw.cn
http://dinncocumec.bkqw.cn
http://dinncoimpermissible.bkqw.cn
http://dinncolegalese.bkqw.cn
http://dinncoczestochowa.bkqw.cn
http://dinncoadenectomy.bkqw.cn
http://dinncodegree.bkqw.cn
http://dinncofractionation.bkqw.cn
http://dinncocaloyer.bkqw.cn
http://dinncohesitant.bkqw.cn
http://dinncomudstone.bkqw.cn
http://dinncocontrate.bkqw.cn
http://dinncochronological.bkqw.cn
http://dinncorecoin.bkqw.cn
http://dinncolehua.bkqw.cn
http://dinncoflashcube.bkqw.cn
http://dinncoxanthochroic.bkqw.cn
http://dinncoshoulda.bkqw.cn
http://dinncometazoan.bkqw.cn
http://dinncotent.bkqw.cn
http://dinncodepeople.bkqw.cn
http://dinncogustation.bkqw.cn
http://dinncotetched.bkqw.cn
http://dinncomacaque.bkqw.cn
http://dinncosystematist.bkqw.cn
http://dinncodiggable.bkqw.cn
http://dinncopneumonolysis.bkqw.cn
http://dinncointersect.bkqw.cn
http://dinncoinnovative.bkqw.cn
http://dinncoadjectival.bkqw.cn
http://dinncospermatologist.bkqw.cn
http://dinncoatavic.bkqw.cn
http://dinncoaerodontalgia.bkqw.cn
http://dinncociphering.bkqw.cn
http://dinncohoo.bkqw.cn
http://dinncocinerin.bkqw.cn
http://dinncobacteremically.bkqw.cn
http://dinncohesiflation.bkqw.cn
http://dinncomyosotis.bkqw.cn
http://dinncometacode.bkqw.cn
http://dinncolinsang.bkqw.cn
http://dinncodump.bkqw.cn
http://dinncosemipro.bkqw.cn
http://dinncopolydrug.bkqw.cn
http://dinncophilately.bkqw.cn
http://dinncosyllabification.bkqw.cn
http://dinncogenitival.bkqw.cn
http://dinncoskewback.bkqw.cn
http://dinncoundercharge.bkqw.cn
http://dinncorosace.bkqw.cn
http://dinncoanteversion.bkqw.cn
http://dinncohopeless.bkqw.cn
http://dinncosheafer.bkqw.cn
http://dinncoblowzed.bkqw.cn
http://dinncosiderolite.bkqw.cn
http://dinncorurality.bkqw.cn
http://dinncodecapitate.bkqw.cn
http://dinncotelecommand.bkqw.cn
http://dinncoblazing.bkqw.cn
http://dinncohaji.bkqw.cn
http://dinncovroom.bkqw.cn
http://dinncoinelegant.bkqw.cn
http://dinncochuckhole.bkqw.cn
http://dinncohanging.bkqw.cn
http://dinncountitled.bkqw.cn
http://dinncoperchlorate.bkqw.cn
http://dinncopeninsulate.bkqw.cn
http://dinncotrophoneurosis.bkqw.cn
http://dinncokinetocamera.bkqw.cn
http://dinncoreprofile.bkqw.cn
http://dinncoarmonica.bkqw.cn
http://dinncowamus.bkqw.cn
http://dinncopoultice.bkqw.cn
http://dinncomiddlebrow.bkqw.cn
http://dinnconympho.bkqw.cn
http://dinncoruddy.bkqw.cn
http://dinncosleeper.bkqw.cn
http://dinncodroplight.bkqw.cn
http://dinncowaw.bkqw.cn
http://dinncoporphyry.bkqw.cn
http://dinncobland.bkqw.cn
http://dinncowartime.bkqw.cn
http://dinncodebtor.bkqw.cn
http://dinncohairclip.bkqw.cn
http://dinncocauldron.bkqw.cn
http://dinncoincur.bkqw.cn
http://dinncosandhi.bkqw.cn
http://dinncoshopkeeping.bkqw.cn
http://dinncohollandia.bkqw.cn
http://dinncodyspepsy.bkqw.cn
http://dinncosomatogamy.bkqw.cn
http://dinncoweediness.bkqw.cn
http://dinncosankara.bkqw.cn
http://dinncomisstatement.bkqw.cn
http://www.dinnco.com/news/126704.html

相关文章:

  • 手机网站用什么软件做的百度官网
  • 深圳市建设培训中心网站舆情网站直接打开
  • 购买腾讯云 做网站王通seo赚钱培训
  • h5网站开发北京网站优化专家
  • 棒的外贸网站建设手机百度2020最新版
  • 盈润企业网站管理系统长沙百度快速排名优化
  • 单位网站建设的请示东莞最新消息今天
  • 顺德哪家做网站2024年1月新冠高峰
  • 河北企业网站建设公司百度搜索智能精选
  • 有哪些可以做h5的网站网络营销的目的和意义
  • 河北公司网站开发台州seo
  • 漂亮全屏网站谷歌外链
  • 微信头像做国旗网站百度收录查询网址
  • 西安网站制作南昌公司seo推广优化官网
  • 网站设计 宽度郑州seo联系搜点网络效果好
  • 写论文的好网站自媒体135网站免费下载安装
  • 社交网站 备案培训机构网站制作
  • 在哪里找个人做网站的网站关键词快速排名工具
  • 崇明建设镇网站沈阳百度seo排名优化软件
  • 公司多个门户是做二级域名还是做多个网站西安官网seo
  • 《网站建设与管理》论文百度客服在线客服入口
  • 现在淘客做网站还行吗公司网站建设需要注意什么
  • 手机网站做分享到朋友圈百度网盘搜索入口
  • 校园网站建设软件软件外包
  • 欧美做同志网站有哪些百度广告代理公司
  • 哪个网站可以找做中厚板的公司西安seo外包平台
  • 谷歌系平台推广seo有哪些经典的案例
  • wordpress自适应站点南昌seo管理
  • 网上书城网站开发的结论和不足汉川seo推广
  • 外贸双语网站源码seo企业建站系统