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

电脑制作软件的工具沈阳seo优化排名公司

电脑制作软件的工具,沈阳seo优化排名公司,江门网站推广,呼和浩特建设委员会网站一、PlayerPrefs PlayerPrefs适合用于存储简单的键值对数据 存储的数据会在游戏关闭后依然保持,并且可以在不同场景之间共享,适合用于需要在游戏不同场景之间传递和保持的数据。 它利用key-value的方式将数据保存到本地,跟字典类似。然后通…

一、PlayerPrefs

PlayerPrefs适合用于存储简单的键值对数据

存储的数据会在游戏关闭后依然保持,并且可以在不同场景之间共享,适合用于需要在游戏不同场景之间传递和保持的数据。

它利用key-value的方式将数据保存到本地,跟字典类似。然后通过代码进行保存、读取、更新操作。值得注意的是此方法只能保存int型、float型,string型的数据,当然,对于bool类型的可以用0和1来代替真和假,以实现保存目的。

示例:制作登录界面的记住密码功能

1:在Start方法中判断PlayerPrefs是否存在该键名,有的话就设置

    private void Start(){if (PlayerPrefs.HasKey("Name")) {UserField.text = PlayerPrefs.GetString("Name");}if (PlayerPrefs.HasKey("Password")){PasswordField.text = PlayerPrefs.GetString("Password");}}

2:在登录按钮按下时,去设置该键值

 if(rememberToggle.isOn){PlayerPrefs.SetString("Name", UserField.text);PlayerPrefs.SetString("Password", PasswordField.text);}else{PlayerPrefs.DeleteKey("Password");}

PlayerPrefas就是这么简单,就是本地字典,可以离线存储

二、Json/Xml/Excel/Txt(本地)

1:Json
①书写解析类

需要创建和Json格式一样的类,以便于解析该Json文件到该类,不同复杂程度的Json文件,解析方式也不一样,简单的格式可以使用JsonUtility,复杂的则使用LitJson解析

比如Json格式如下:

{"name": "张三","level": 10,"hp": 100.0
}

解析类如下:

 public class PlayerData{public string name;public int level;public float hp;}

比如Json格式如下(嵌套格式):

{"name": "John","age": 30,"isStudent": true,"scores": [ 98, 95, 100 ],"address":{"city": "New York","state": "NY"}
}

解析类如下:

public class ExampleData
{public string name;public int age;public bool isStudent;public List<int> scores;public AddressData address;
}
public class AddressData
{public string city;public string state;
}

在Json的格式中,整块的内容需要用到{},数组的内容需要用到[]

②读取和解析Json文件

路径

string filePath = Application.streamingAssetsPath + "/JsonData/player.json";
string jsonString = File.ReadAllText(Application.streamingAssetsPath + "/JsonData/litexample.json");

第一种是文件的路径,第二种则直接把后面的读取该路径下的Json文件也包括了

解析

string jsonString = File.ReadAllText(filePath);
PlayerData playerData1 = JsonUtility.FromJson<PlayerData>(jsonString);
exampleData = JsonMapper.ToObject<ExampleData>(jsonString);

后续只需要对你读取到数据类中的数据进行读取就好了,当然这只是读取,还有存取,后续补

2:XML
①书写XML文件
<?xml version="1.0" encoding="UTF-8"?>
<library><book><title>Unity 3D游戏开发</title><authors><author>张三</author><author>李四</author></authors></book><book><title>Java编程思想</title><authors><author>John Doe</author><author>Jane Doe</author></authors></book>
</library>

<library> 是根元素(root element)。

  • <book> 元素包含了书的相关信息。
    • <title> 元素用于包含书的标题。
    • <authors> 元素用于包含一个或多个作者。
      • <author> 元素包含作者的名字。

标记的位置表明了层级关系,Library是最高层,就表明它是根节点元素,其次就是Book,Book是有两组,然后是Title和Authors是并列关系的,最后是两个Author

 <book>

 </book>


注意到这种结构,以尖括号不加/开始,以为尖括号加/结束!

②解析XML类
public class Book
{public string title;public List<string> authors = new List<string>();
}

解析类使用了XML中的最基础的Book数组

③解析方法

string filePath = Application.streamingAssetsPath + "/XMLData/XMLExample.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);

XmlDocument是 .NET Framework 提供的 XML 文档处理类,允许你加载、创建、编辑和操作 XML 文档

//写成Static静态方法,可以在全局进行使用 
public static List<Book> ParseBooks(XmlDocument xmlDoc){//创建一个Book数组,用于存储数据List<Book> books = new List<Book>();//SelectSingleNode,获取XML的单一节点XmlNode root = xmlDoc.SelectSingleNode("library");//遍历该节点下的所有子节点foreach (XmlNode bookNode in root.ChildNodes){//再创建新的Book对象Book book = new Book();//再获取单一节点book.title = bookNode.SelectSingleNode("title").InnerText;XmlNode authorsNode = bookNode.SelectSingleNode("authors");foreach (XmlNode authorNode in authorsNode.ChildNodes){book.authors.Add(authorNode.InnerText);}books.Add(book);}return books;}

其实使用了xmlDoc.SelectSingleNode方法来选中XMl文件中的一个节点,然后再进行遍历,注意在遍历之前需要先创建对应的数据类进行存储
 

3:Excel

①导入读取文件

一般是EPPlus,Excel,ICharpCode,用于读取excle

②解析Excel

分成三步

//FileStream是基于IO名称空间
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);//IExcelDataReader是基于Excel名称空间
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);DataSet result = excelReader.AsDataSet();

第一步:

  • filePath:表示要打开的文件的路径。
  • FileMode.Open:表示以打开的方式打开文件,如果文件不存在则引发异常。
  • FileAccess.Read:表示以只读模式打开文件,不允许写入。
  • FileShare.Read:表示文件共享选项,允许多个读取器打开文件并同时读取。

第二步:

        创建一个 IExcelDataReader 对象,它用于读取 Excel 文件的内容ExcelReaderFactory.CreateOpenXmlReader 是从 ExcelDataReader 库中创建 Excel 读取器的工厂方法。这里使用的是 OpenXml 格式的读取器,它可以读取基于 Office Open XML 标准的 Excel 文件(.xlsx 格式)。

注意:     读取.xlsx格式的使用ExcelReaderFactory.CreateOpenXmlReader
                读取.xls格式的使用ExcelReaderFactory.CreateBinaryReader

第三步:

        读取 Excel 文件的内容,并将其转换为 DataSet 对象

③读取Excel
columnNum = result.Tables[0].Columns.Count;
rowNum = result.Tables[0].Rows.Count;

4:Txt

①获取路径

Resources:

string filePath = "MyTextFiles/Example.txt";

StreamingAssets:

string fileName = "Example.txt";
string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
②读取文件
using System.IO;public string ReadTextFile(string filePath)
{try{if (File.Exists(filePath)){// 从文本文件中读取所有文本内容string content = File.ReadAllText(filePath);return content;}else{Debug.LogError("File not found: " + filePath);return null;}}catch (Exception e){Debug.LogError("Error reading text file: " + e.Message);return null;}
}

三、ScriptableObject

ScriptableObject是 Unity 提供的一个数据配置存储基类,它是一个可以用来保存大量数据的数据容器,我们可以将它保存为自定义的数据资源文件,实例会被保存成资源文件(.asset文件),和预制体,材质球,音频文件等类似,都是一种资源文件,存放在 Assets 文件夹下,创建出来的实例也是唯一存在的。

①创建目标数据结构的数据类

namespace Data
{public class Item{public string Name;public string Class;public string Sex;public string Age;}public class ItemManager : ScriptableObject{public Item[] dataArray;}
}

嵌套Item的数组

②编辑Scripts

可以在代码中进行编辑内容,也可以在外部进行编辑

public class ItemParser : MonoBehaviour
{public ItemManager itemManager; // 在Unity中分配你的ItemManager实例private void Start(){if (itemManager != null){// 遍历dataArray中的每个Item对象foreach (Item item in itemManager.dataArray){Debug.Log("Item Name: " + item.Name);Debug.Log("Item Class: " + item.Class);Debug.Log("Item Sex: " + item.Sex);Debug.Log("Item Age: " + item.Age);}}else{Debug.LogError("ItemManager is not assigned!");}}
}

③读取即可

四、数据库

一般使用数据库进行数据的增删改查,我的另一篇关于创建本地数据库的文章写的非常详细,详见:Unity_安装部署本地MySQL数据库(Navicat可视化)_mysql安装 unity_Future_404的博客-CSDN博客

1:SqlHelp

一般是工具方法,实现打开数据库,关闭数据库,增删改查等功能

  1. LeiSqlHelper 构造函数:接受数据库连接所需的参数(如主机地址、端口、用户名、密码、数据库名等),用于初始化数据库连接。

  2. Connect 方法:根据提供的连接信息来建立数据库连接。它将连接字符串创建并初始化了 MySqlConnection 对象。

  3. Open 方法:用于打开数据库连接。

  4. Close 方法:用于关闭数据库连接。

  5. Dispose 方法:用于在 using 块中释放资源,主要是调用 Close 方法。

  6. Select 方法:执行查询语句,允许你选择指定表的指定字段或选择整个表的所有字段,并返回一个包含结果的 DataSet。

  7. SelectWhere 方法:执行有条件的查询,你可以为查询指定条件,根据条件筛选数据,并返回一个包含结果的 DataSet。

  8. UpdateIntoSpecific 方法:执行更新操作,允许你根据条件更新指定表的特定字段。

  9. InsertInto 方法:执行插入操作,允许你向指定表插入数据。

  10. Delete 方法:执行删除操作,允许你删除符合条件的表中的数据或整个表的内容。

  11. CreateTable 方法:执行创建表的操作,允许你创建一个新的数据库表。

  12. ExecuteNonQuery 方法:执行 SQL 语句,通常用于更新、插入、删除等不返回数据集的操作。它返回受影响的行数。

2:SqlToos(读取)
using System.Collections.Generic;
using UnityEngine;
using Lei.Mysql;public class LeiTestSql : MonoBehaviour
{void Start(){//                                                      IP地址       端口   用户名    密码   数据库项目名称var mySqlTools = new LeiSqlHelper("127.0.0.1", "3306", "root", "123456", "SqlTest");//先打开数据库mySqlTools.Open();//创建表方法                          表名         字段名称                                            字段类型//mySqlTools.CreateTable("FirstData", new[] { "UID", "User", "Password" }, new[] { "tinytest", "tinytext", "tinytest" });//插入数据                      表名                     字段名称                                             插入的数据//mySqlTools.InsertInto("FirstData", new[] { "UID", "User", "Password" }, new[] { "雷康", "leikang", "123456" });//查询方法FindMysql(mySqlTools, "firstdata", new[] { "UID", "User", "Password" });//  插入方法                 表名                             字段名                                                 插入数据//mySqlTools.InsertInto("firstdata", new[] { "UID", "User", "Password" },new[] {"52022","ddxj1","123456" });//   更新方法                                     表名          更新字段名       判断符号          更新数据               查询条件字段         条件成立字段//mySqlTools.UpdateIntoSpecific("firstdata", new[] { "User" }, new[] { "=" }, new[] { "ddxj1" }, new[] { "Password" }, new[] { "456789" });//  删除方法                     表名          删除字段        判断条件       条件成立数据         //mySqlTools.Delete("firstdata", new[] { "User" }, new[] { "=" }, new[] { "ddxj1" });//查询方法                                               表名        查询字段名         判断字段名       判断符号        条件成立数据// var ds = mySqlTools.SelectWhere("firstdata", new[] { "UID" }, new[] { "User" }, new[] { "=" }, new[] { "ddxj1" });//查询方法                                              表名         判断字段名       判断符号        条件成立数据// var ds = mySqlTools.SelectWhere("firstdata", new[] { "User" }, new[] { "=" }, new[] { "ddxj1" });mySqlTools.Close();}/// <summary>/// 查询表中数据   记得先调用Open()方法  用完此方法后直接Close()/// </summary>/// <param name="mySqlTools">Mysql框架类</param>/// <param name="tableName">表名</param>/// <param name="items">字段名称</param>void FindMysql(LeiSqlHelper mySqlTools, string tableName, string[] items){var ds = mySqlTools.Select(tableName, items);//调取获取数据的方法var pairs = LeiSqlTools.TableData(ds);DebugMysql(pairs);}/// <summary>/// 打印查询数据库/// </summary>/// <param name="pairs"></param>private void DebugMysql(Dictionary<string, object>[] pairs){for (int i = 0; i < pairs.Length; i++){foreach (var table in pairs[i]){string tableList = string.Format("第{0}行,表字段名对应数据是 {1}", i + 1, table);print(tableList);}}}
}

文章转载自:
http://pianism.c7512.cn
http://dotard.c7512.cn
http://honduranean.c7512.cn
http://aminotransferase.c7512.cn
http://foregoing.c7512.cn
http://kid.c7512.cn
http://extramental.c7512.cn
http://chipping.c7512.cn
http://gaoshan.c7512.cn
http://exaction.c7512.cn
http://portable.c7512.cn
http://yellowness.c7512.cn
http://build.c7512.cn
http://quackster.c7512.cn
http://roentgenoscopy.c7512.cn
http://tumbleweed.c7512.cn
http://ravioli.c7512.cn
http://vachel.c7512.cn
http://inbound.c7512.cn
http://eucolloid.c7512.cn
http://pepsin.c7512.cn
http://ecdysis.c7512.cn
http://burb.c7512.cn
http://deterrable.c7512.cn
http://dekare.c7512.cn
http://mariana.c7512.cn
http://heathfowl.c7512.cn
http://horribly.c7512.cn
http://delay.c7512.cn
http://bmc.c7512.cn
http://primidone.c7512.cn
http://varec.c7512.cn
http://cuttlefish.c7512.cn
http://ganglion.c7512.cn
http://runover.c7512.cn
http://booklore.c7512.cn
http://dissidence.c7512.cn
http://companionate.c7512.cn
http://memorialise.c7512.cn
http://pickled.c7512.cn
http://deplorable.c7512.cn
http://tympanoplasty.c7512.cn
http://ossuary.c7512.cn
http://cyanine.c7512.cn
http://cumbrian.c7512.cn
http://discriminative.c7512.cn
http://beneficence.c7512.cn
http://yrast.c7512.cn
http://eyecup.c7512.cn
http://erythritol.c7512.cn
http://quantitate.c7512.cn
http://iontophoresis.c7512.cn
http://blanky.c7512.cn
http://electrommunication.c7512.cn
http://septate.c7512.cn
http://esophagoscope.c7512.cn
http://significans.c7512.cn
http://purulent.c7512.cn
http://vertex.c7512.cn
http://mfa.c7512.cn
http://phosphorize.c7512.cn
http://judea.c7512.cn
http://hypocrisy.c7512.cn
http://bangbang.c7512.cn
http://ophthalmotomy.c7512.cn
http://bolivar.c7512.cn
http://connie.c7512.cn
http://fingerfish.c7512.cn
http://airhead.c7512.cn
http://insurgency.c7512.cn
http://boscage.c7512.cn
http://vestryman.c7512.cn
http://signalise.c7512.cn
http://christianlike.c7512.cn
http://patchouli.c7512.cn
http://siriasis.c7512.cn
http://massif.c7512.cn
http://musicianly.c7512.cn
http://backspin.c7512.cn
http://cajun.c7512.cn
http://epoxy.c7512.cn
http://clapt.c7512.cn
http://thymelaeaceous.c7512.cn
http://minifloppy.c7512.cn
http://rebukeful.c7512.cn
http://convolve.c7512.cn
http://unspoke.c7512.cn
http://quotiety.c7512.cn
http://paramenstruum.c7512.cn
http://submerse.c7512.cn
http://wired.c7512.cn
http://dishrag.c7512.cn
http://nicotinamide.c7512.cn
http://triquetrous.c7512.cn
http://sternward.c7512.cn
http://nutshell.c7512.cn
http://directrix.c7512.cn
http://venite.c7512.cn
http://dryfoot.c7512.cn
http://farfetched.c7512.cn
http://www.zhongyajixie.com/news/76170.html

相关文章:

  • 学院网站建设服务宗旨网络营销seo培训
  • 怎样建设一个公司网站贵州seo推广
  • 滁州市南谯区建设局网站舆情信息范文
  • 温岭做网站公司久久seo综合查询
  • 福田的网站建设公司有哪些网站可以免费发布广告
  • wordpress管理界面站长工具之家seo查询
  • 广西企业网站有哪些合肥做网站公司哪家好
  • 东莞专业网站推广需要多少钱网站建站哪家公司好
  • 提高网站打开速度的7大秘籍毕节地seo
  • 常州外贸集团 网站建设seo推广软件代理
  • 购物网站制作公司宁波谷歌seo推广
  • 微信引流推广精准粉对搜索引擎优化的认识
  • 杭州网站搭建公司百度商家怎么入驻
  • 深圳 企业 网站建设南京关键词网站排名
  • 哪里有个人做网站的seo新手教程
  • 网站做中文和英文切换桔子seo
  • 网页微信版本在哪里下载重庆电子商务seo
  • 济南手机端建站模板百度公司好进吗
  • 网页设计作品模板seo词库排行
  • 雅虎网站提交优化关键词排名的工具
  • 临猗做网站seo服务顾问
  • 网站资源做外链社会化媒体营销
  • 安装wordpress后加固爱站seo工具包官网
  • 做电子书网站 赚钱手机免费发布信息平台
  • 如何百度到自己的网站重庆森林影评
  • 制作大型网站开发企业seo推广外包
  • 微信里有人发做任务网站站长网
  • 如何做免费的网站佛山做网站建设
  • 企业官网的作用seo是搜索引擎优化吗
  • 济南网站建设用途郑州seo优化服务