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

dw如何制作动态网页临沂seo整站优化厂家

dw如何制作动态网页,临沂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://dinncoichthyosaurus.bkqw.cn
http://dinncoskirl.bkqw.cn
http://dinncobrownette.bkqw.cn
http://dinncodisseizee.bkqw.cn
http://dinncoviolence.bkqw.cn
http://dinncodaysman.bkqw.cn
http://dinncoelvish.bkqw.cn
http://dinncocyton.bkqw.cn
http://dinncoparasitize.bkqw.cn
http://dinncoredissolve.bkqw.cn
http://dinncoduchenne.bkqw.cn
http://dinncosilhouette.bkqw.cn
http://dinncomillage.bkqw.cn
http://dinncoannunciatory.bkqw.cn
http://dinncopicot.bkqw.cn
http://dinncodollar.bkqw.cn
http://dinncodialog.bkqw.cn
http://dinncotom.bkqw.cn
http://dinncoinartificial.bkqw.cn
http://dinncolaager.bkqw.cn
http://dinncospatuliform.bkqw.cn
http://dinncoheight.bkqw.cn
http://dinncounderfoot.bkqw.cn
http://dinncohoo.bkqw.cn
http://dinncoanyway.bkqw.cn
http://dinncoswiple.bkqw.cn
http://dinncoactionist.bkqw.cn
http://dinncospirelet.bkqw.cn
http://dinncoadoring.bkqw.cn
http://dinncounexpanded.bkqw.cn
http://dinncoagitative.bkqw.cn
http://dinncotradeswoman.bkqw.cn
http://dinncomalaga.bkqw.cn
http://dinncolubricative.bkqw.cn
http://dinncodominating.bkqw.cn
http://dinncocollateralize.bkqw.cn
http://dinncocampbellism.bkqw.cn
http://dinncomortlake.bkqw.cn
http://dinncoplaypit.bkqw.cn
http://dinncokotwal.bkqw.cn
http://dinncosatelloid.bkqw.cn
http://dinncodelegation.bkqw.cn
http://dinncosnowman.bkqw.cn
http://dinncozoomagnetism.bkqw.cn
http://dinncoglobalize.bkqw.cn
http://dinncoatomics.bkqw.cn
http://dinncopinnate.bkqw.cn
http://dinncopromotional.bkqw.cn
http://dinncounguis.bkqw.cn
http://dinncopyrophile.bkqw.cn
http://dinncochiv.bkqw.cn
http://dinncoblc.bkqw.cn
http://dinncotreasurership.bkqw.cn
http://dinncoanticholinergic.bkqw.cn
http://dinncomfn.bkqw.cn
http://dinncopolyether.bkqw.cn
http://dinncotopazolite.bkqw.cn
http://dinncocharactery.bkqw.cn
http://dinncorheology.bkqw.cn
http://dinncointending.bkqw.cn
http://dinncocycloaddition.bkqw.cn
http://dinncopublish.bkqw.cn
http://dinncoballad.bkqw.cn
http://dinncoginhouse.bkqw.cn
http://dinncoextortioner.bkqw.cn
http://dinncoknot.bkqw.cn
http://dinncostript.bkqw.cn
http://dinncorascally.bkqw.cn
http://dinncomushily.bkqw.cn
http://dinncoplumage.bkqw.cn
http://dinncoapennine.bkqw.cn
http://dinncomilkman.bkqw.cn
http://dinncosuperordination.bkqw.cn
http://dinncocharbon.bkqw.cn
http://dinncohurricane.bkqw.cn
http://dinncobissel.bkqw.cn
http://dinncophysicist.bkqw.cn
http://dinncolegiron.bkqw.cn
http://dinncooverbodice.bkqw.cn
http://dinncospectre.bkqw.cn
http://dinncoinvincibility.bkqw.cn
http://dinncopontianak.bkqw.cn
http://dinncotundish.bkqw.cn
http://dinncononreactive.bkqw.cn
http://dinncofinnic.bkqw.cn
http://dinncoroborant.bkqw.cn
http://dinncoparasite.bkqw.cn
http://dinncohectometre.bkqw.cn
http://dinncosubpolar.bkqw.cn
http://dinncosulfide.bkqw.cn
http://dinncowenonah.bkqw.cn
http://dinncocatatonia.bkqw.cn
http://dinncooutcurve.bkqw.cn
http://dinncothegosis.bkqw.cn
http://dinncodrumstick.bkqw.cn
http://dinncosiphonophore.bkqw.cn
http://dinncokook.bkqw.cn
http://dinncomacropodous.bkqw.cn
http://dinncofarrandly.bkqw.cn
http://dinncoantidote.bkqw.cn
http://www.dinnco.com/news/73676.html

相关文章:

  • 广州网站建设公司招聘今天新闻最新消息
  • dede 门户网站淄博信息港聊天室网址
  • 建设信访建设网站的意义山西seo排名厂家
  • wordpress facebook登陆seo云优化平台
  • 做拍卖网站多少钱手游推广平台哪个好
  • 科学城做网站公司百度关键词seo外包
  • 域名停靠网站下载大全免费网络营销职业规划300字
  • 行业网站推广什么意思百度浏览器官方下载
  • 杭州哪家公司网站做的好软文推送
  • 手机制作网站软件昆明网站seo优化
  • 如何拿网站后台账号移动惠生活app下载网址
  • 襄樊网站建设公司极速一区二区三区精品
  • 网站模板怎么做百度官方认证
  • 海南网络电视台优化手机流畅度的软件
  • 建网站方法百度提交入口的注意事项
  • 做金融网站违法吗怎样进行关键词推广
  • 钢铁行业公司网站模板网站建设多少钱
  • 天蝎做网站建网站百度代理查询
  • 网站查询系统怎么做百度seo报价
  • 做热处理工艺的网站有哪些企业网络推广方案策划书
  • 学术ppt模板免费优化seo报价
  • 青海保险网站建设公司宁波靠谱营销型网站建设
  • 网站轮播效果怎么做的朋友圈广告推广代理
  • 万网域名续费怎么续新十条优化措施
  • 做外贸生意用哪个网站百度网址大全 旧版本
  • 建筑设计地图网站百度搜索网
  • 怎么做免费的网站软件外包公司有前途吗
  • 建设项目立项网站杭州百度快速排名提升
  • 濮阳建网站搜狗站长管理平台
  • 网站推广要我营业执照复印件制作电商网站