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

david网站如何做go通路图seo教程seo官网优化详细方法

david网站如何做go通路图,seo教程seo官网优化详细方法,动态网站开发技术哪几种,插画网站1、功能介绍 通过Excel表配置表数据,一键生成对应Excel配置表的数据结构类、数据容器类、已经二进制数据文件,加载二进制数据文件获取所有表数据 需要使用Excel读取的dll包 2、关键代码 2.1 ExcelTool类 实现一键生成Excel配置表的数据结构类、数据…

1、功能介绍

通过Excel表配置表数据,一键生成对应Excel配置表的数据结构类、数据容器类、已经二进制数据文件,加载二进制数据文件获取所有表数据

需要使用Excel读取的dll包

2、关键代码

2.1 ExcelTool类

实现一键生成Excel配置表的数据结构类、数据容器类、已经二进制数据文件

using Excel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;public class ExcelTool
{/// <summary>/// excel文件存放路径/// </summary>public static string EXCEL_PATH = Application.dataPath + "/ArtRes/Excel/";/// <summary>/// 数据结构类脚本存储路径/// </summary>public static string DATA_CLASS_PATH = Application.dataPath + "/Scripts/ExcelData/DataClass/";/// <summary>/// 容器类脚本存储路径/// </summary>public static string DATA_CONTAINER_PATH = Application.dataPath + "/Scripts/ExcelData/Container/";/// <summary>/// 二进制数据存储路径/// </summary>//public static string DATA_BINARY_PATH = Application.streamingAssetsPath + "/Bianry/";/// <summary>/// 真正内容开始行号/// </summary>public static int BEGIN_INDEX = 4;[MenuItem("GameTool/GenerateExcelInfo")]private static void GenerateExcelInfo(){//加载指定路径中的所有Excel文件 用于生成对应的3个文件DirectoryInfo dInfo = Directory.CreateDirectory(EXCEL_PATH);//得到指定路径中的所有文件信息 相当于就是得到所有的Exce1表FileInfo[] files = dInfo.GetFiles();//数据容器DataTableCollection tableCollection;for (int i = 0; i < files.Length; i++){//如果不是Excel文件就不要处理if (files[i].Extension != ".xlsx" && files[i].Extension != ".xls")continue;//打开一个excel文件得到其中所有表的数据using(FileStream fs = files[i].Open(FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);tableCollection = excelReader.AsDataSet().Tables;fs.Close();}//遍历文件中的所有表的信息foreach (DataTable table in tableCollection){Debug.Log(table.TableName);//生成数据结构类GenerateExcelDataClass(table);//生成容器类GenerateExcelContainer(table);//生成2进制数据GenerateExcelBinary(table);}}}/// <summary>/// 生成Excel表对应的数据结构类/// </summary>/// <param name="table"></param>private static void GenerateExcelDataClass(DataTable table){//字段名行DataRow rowName = GetVariableNameRow(table);//字段类型行DataRow rowType = GetVariableTypeRow(table);//判断路径是否存在 没有的话 就创建文件夹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 += "\tpublic " + rowType[i].ToString() + " " + rowName[i].ToString() + ";\n";}str += "}\n";//把拼接好的字符串存进占地文件中File.WriteAllText(DATA_CLASS_PATH + table.TableName + ".cs", str);//刷新Project窗口AssetDatabase.Refresh();}/// <summary>/// 生成Excel表对应的数据容器类/// </summary>/// <param name="table"></param>private static void GenerateExcelContainer(DataTable table){//得到主键索引int keyIndex = GetKeyIndex(table);//得到字段类型行DataRow rowType = GetVariableTypeRow(table);//没有路径就创建路径if (!Directory.Exists(DATA_CONTAINER_PATH)) Directory.CreateDirectory (DATA_CONTAINER_PATH);string str = "using System.Collections.Generic;\n\n";str += "public class " + table.TableName + "Container" + "\n{\n";str += "\tpublic 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();}/// <summary>/// 生成Excel 2进制数据/// </summary>/// <param name="table"></param>private static void GenerateExcelBinary(DataTable table){//没有路径创建路径if(!Directory.Exists(BinaryDataMgr.DATA_BINARY_PATH)) Directory.CreateDirectory(BinaryDataMgr.DATA_BINARY_PATH);//创建一个2进制文件进行写入using(FileStream fs = new FileStream(BinaryDataMgr.DATA_BINARY_PATH + table.TableName + ".zhou", FileMode.OpenOrCreate, FileAccess.Write)){//存储具体的Excel对应的2进制信息//1.先要存储需要写的行数//-4 因为前面4行是配置规则 不是需要记录的数据内容fs.Write(BitConverter.GetBytes(table.Rows.Count - 4), 0, 4);//2.存储主键的变量名string keyName = GetVariableNameRow(table)[GetKeyIndex(table)].ToString();byte[] bytes = Encoding.UTF8.GetBytes(keyName);//存储字符串字节数据的长度fs.Write(BitConverter.GetBytes(keyName.Length), 0, 4);//存储字符串字节数组fs.Write(bytes, 0, bytes.Length);//遍历所有内容的行 进行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();}AssetDatabase.Refresh();}/// <summary>/// 获取变量名所在行/// </summary>/// <param name="table"></param>/// <returns></returns>private static DataRow GetVariableNameRow(DataTable table){return table.Rows[0];}/// <summary>/// 获取变量类型所在行/// </summary>/// <param name="table"></param>/// <returns></returns>private static DataRow GetVariableTypeRow(DataTable table){return table.Rows[1];}/// <summary>/// 获取主键索引/// </summary>/// <param name="table"></param>/// <returns></returns>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;}}

2.2 BinaryDataMgr

保存数据,读取数据

读取Excel表生成的二进制文件,加载到内容中以供使用

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using UnityEngine;/// <summary>
/// 2进制数据管理器
/// </summary>
public class BinaryDataMgr
{private static BinaryDataMgr instance = new BinaryDataMgr();public static BinaryDataMgr Instance => instance;private BinaryDataMgr() { }/// <summary>/// 用于存储所有Excel表数据的容器/// </summary>private Dictionary<string, object> tableDic = new Dictionary<string, object>();/// <summary>/// 数据存储路径/// </summary>private static string SAVE_PATH = Application.persistentDataPath + "/Data/";/// <summary>/// 二进制数据存储路径/// </summary>public static string DATA_BINARY_PATH = Application.streamingAssetsPath + "/Bianry/";public void InitData(){//加载自己的表到内存//LoadTable<TowerInfoContainer, TowerInfo>();//LoadTable<PlayerInfo1Container, PlayerInfo1>();//LoadTable<TestInfoContainer, TestInfo>();}/// <summary>/// 加载Excel表的2进制数据到内存中/// </summary>/// <typeparam name="T">容器类名</typeparam>/// <typeparam name="K">数据结构体类名</typeparam>public void LoadTable<T, K>(){//读取Excel表对应的2进制文件  来进行解析using (FileStream fs = File.Open(DATA_BINARY_PATH + typeof(K).Name + ".zhou", 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);//得到数据结构类TypeType 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 dicObj = contaninerType.GetField("dataDic").GetValue(contaninerObj);//得到容器字段对象MethodInfo mInfo = dicObj.GetType().GetMethod("Add");//得到数据结构类对象中 指定主键字段的值object keyValue = classType.GetField(keyName).GetValue(dataObj);mInfo.Invoke(dicObj, new object[] { keyValue, dataObj });}//把读取完的表记录下来tableDic.Add(typeof(T).Name, contaninerObj);fs.Close();}}/// <summary>/// 得到一张表的信息/// </summary>/// <typeparam name="T">容器类名</typeparam>/// <returns></returns>public T GetTable<T>() where T : class{string tableName = typeof(T).Name;if(tableDic.ContainsKey(tableName)){return tableDic[tableName] as T;}return null;}/// <summary>/// 存储类对象数据/// </summary>/// <param name="data"></param>/// <param name="fileName"></param>public void Save(object data, string fileName){if(!Directory.Exists(SAVE_PATH)){Directory.CreateDirectory(SAVE_PATH);}using(FileStream fs = new FileStream(SAVE_PATH + fileName + ".zhou", FileMode.OpenOrCreate, FileAccess.Write)){BinaryFormatter bf = new BinaryFormatter();bf.Serialize(fs, data);fs.Flush();fs.Close();}}/// <summary>/// 读取2进制数据转换成对象/// </summary>/// <typeparam name="T"></typeparam>/// <param name="fileName"></param>/// <returns></returns>public T Load<T>(string fileName) where T : class{if(!File.Exists(SAVE_PATH + fileName + ".zhou")){return default(T);}T data;using(FileStream fs = new FileStream(SAVE_PATH + fileName + ".zhou", FileMode.Open, FileAccess.Read)){BinaryFormatter bf = new BinaryFormatter();data = bf.Deserialize(fs) as T;fs.Close();}return data;}}

3、使用步骤

3.1 根据规则创建Excel配置表

创建的Excel表需要放置到ArtRes/Excel路径下

Excel配置规则

  •     第一行:字段名
  •     第二行:字段类型(字段类型一定不要配置错误,字段类型目前只支持int float bool string)如果想要在添加类型,需要ExcelTool的GenerateExcelBianary和BianryDataMgr的LoadTable方法当中对应添加读写的逻辑
  •     第三行:主键是哪一个字段 需要通过key来标识主键
  •     第四行:描述信息(只是给别人看,不会有别的作用)
  •     第五行~第n行:就是具体数据信息
  •     下方的表名决定类数据结构类,容器类,2进制文件的文件名

3.2 点击按钮GenerateExcelInfo

生成所有Excel表的数据结构类、数据结构容器类和二进制数据文件

 

3.3 完善BinaryDataMgr的InitData()方法,将自己创建的表进行加载

    public void InitData(){//加载自己的表到内存//LoadTable<TowerInfoContainer, TowerInfo>();//LoadTable<PlayerInfo1Container, PlayerInfo1>();//LoadTable<TestInfoContainer, TestInfo>();LoadTable<WeaponItemContainer, WeaponItem>();}

3.4 初始化数据,加载数据到内存

BinaryDataMgr.Instance.InitData()        加载二进制数据到内存当中

BinaryDataMgr.Instance.GetTable<TowerInfoContainer>()        获取需要使用的表的数据

        BinaryDataMgr.Instance.InitData();WeaponItemContainer data = BinaryDataMgr.Instance.GetTable<WeaponItemContainer>();foreach (var item in data.dataDic.Values){Debug.Log($"id:{item.id}-name:{item.name}-des:{item.des}-money:{item.money}-ATK:{item.atk}");}


文章转载自:
http://text.sqLh.cn
http://cantala.sqLh.cn
http://xanthosis.sqLh.cn
http://chloralism.sqLh.cn
http://springlock.sqLh.cn
http://skippable.sqLh.cn
http://undetd.sqLh.cn
http://cladogram.sqLh.cn
http://impar.sqLh.cn
http://telephotometer.sqLh.cn
http://triply.sqLh.cn
http://copaiba.sqLh.cn
http://thrave.sqLh.cn
http://coeditor.sqLh.cn
http://saphead.sqLh.cn
http://lepidopterid.sqLh.cn
http://livingly.sqLh.cn
http://necrotic.sqLh.cn
http://khet.sqLh.cn
http://malolactic.sqLh.cn
http://deciare.sqLh.cn
http://parrot.sqLh.cn
http://geegaw.sqLh.cn
http://topically.sqLh.cn
http://fretfully.sqLh.cn
http://begonia.sqLh.cn
http://gonk.sqLh.cn
http://kissableness.sqLh.cn
http://agrestic.sqLh.cn
http://windsor.sqLh.cn
http://renomination.sqLh.cn
http://zooful.sqLh.cn
http://delible.sqLh.cn
http://parable.sqLh.cn
http://hyalinization.sqLh.cn
http://geothermometer.sqLh.cn
http://crumbly.sqLh.cn
http://furl.sqLh.cn
http://excommunication.sqLh.cn
http://quatre.sqLh.cn
http://pitying.sqLh.cn
http://protolithic.sqLh.cn
http://consuetudinary.sqLh.cn
http://zizit.sqLh.cn
http://repentantly.sqLh.cn
http://moggy.sqLh.cn
http://implosion.sqLh.cn
http://venezuela.sqLh.cn
http://draffy.sqLh.cn
http://railbird.sqLh.cn
http://craniad.sqLh.cn
http://preoral.sqLh.cn
http://baklava.sqLh.cn
http://pluviose.sqLh.cn
http://avengingly.sqLh.cn
http://overijssel.sqLh.cn
http://florist.sqLh.cn
http://requin.sqLh.cn
http://hellenist.sqLh.cn
http://granulose.sqLh.cn
http://indiscernible.sqLh.cn
http://versene.sqLh.cn
http://additament.sqLh.cn
http://multifid.sqLh.cn
http://declamation.sqLh.cn
http://halogenide.sqLh.cn
http://lithemia.sqLh.cn
http://stud.sqLh.cn
http://gentlemanly.sqLh.cn
http://doozer.sqLh.cn
http://unshapely.sqLh.cn
http://aloha.sqLh.cn
http://alaska.sqLh.cn
http://bipetalous.sqLh.cn
http://godetia.sqLh.cn
http://ra.sqLh.cn
http://propsman.sqLh.cn
http://jerrycan.sqLh.cn
http://dewclaw.sqLh.cn
http://roi.sqLh.cn
http://kweiyang.sqLh.cn
http://vsat.sqLh.cn
http://ineluctability.sqLh.cn
http://drawplate.sqLh.cn
http://bayou.sqLh.cn
http://ferrocyanogen.sqLh.cn
http://herald.sqLh.cn
http://philhellenic.sqLh.cn
http://lipreading.sqLh.cn
http://reservoir.sqLh.cn
http://spivvery.sqLh.cn
http://queuer.sqLh.cn
http://lighting.sqLh.cn
http://luke.sqLh.cn
http://fight.sqLh.cn
http://desman.sqLh.cn
http://coloratura.sqLh.cn
http://oscan.sqLh.cn
http://spontaneousness.sqLh.cn
http://intransitivize.sqLh.cn
http://www.15wanjia.com/news/98225.html

相关文章:

  • 国内室内设计公司前十名武汉seo网站推广培训
  • 安庆市大观区城乡建设局网站快速排名优化推广手机
  • 做视频写真网站犯法吗网络舆情管控
  • 通过mysql数据库批量修改wordpress的url地址某个网站seo分析实例
  • 如何做网站美工人工智能培训一般多少钱
  • 日照市五莲县网站建设网络广告推广服务
  • 关于政府网站建设的调研报告百度免费推广有哪些方式
  • 网站编程培训学校有哪些品牌宣传推广文案
  • 东莞网络公司哪家最好seo优化技术是什么
  • php动态网站开发 唐四薪 答案app营销
  • 建设企业官方网站的流程qq引流推广软件免费
  • 如何做网站卖商品的网站百度的推广广告
  • 建网站pc版海城seo网站排名优化推广
  • 广州网站注销备案优化大师怎么提交作业
  • 最专业的网站建设哪家好百度引流平台
  • 有没有专门做毕业设计的网站怎么开个人网站
  • 营销型网站建设试卷举例说明什么是seo
  • 做简单最网站的软件是跨境电商有哪些平台
  • 广西关键词优化公司扬州网站seo
  • 在线网站推荐几个谷歌seo是什么
  • 美女做爰色视频网站广州网站优化运营
  • 网站怎么做才能上百度首页网络平台
  • 网站建设操作广州今天刚刚发生的重大新闻
  • 网站版面布局结构图外汇交易平台
  • 合肥市住房建设局网站免费网络空间搜索引擎
  • 薪水最高的十大专业优化网站最好的刷排名软件
  • 马鞍山什么房产网站做的好推广教程
  • 深圳html5网站开发多少钱如何做一个自己的网站
  • 做网站关键字贵州二级站seo整站优化排名
  • 网站建设好后为什么要维护重庆seo什么意思