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

男女做那个的网站盲盒小程序加盟

男女做那个的网站,盲盒小程序加盟,濮阳公司建站,易名域名解析到手机网站项目需求为#xff1a; 1.实现存档列表#xff0c;显示存档截图#xff0c;可以查看之前保存的所有存档 2.点击存档直接加载到场景 首先#xff0c;定义两个类#xff0c;用于声明存档列表和存档所需要的List [System.Serializable] public class SaveData {//存储目标…项目需求为 1.实现存档列表显示存档截图可以查看之前保存的所有存档 2.点击存档直接加载到场景 首先定义两个类用于声明存档列表和存档所需要的List [System.Serializable] public class SaveData {//存储目标物的位置和朝向public ListVector3 targetPosition new ListVector3();public ListQuaternion targetRotation new ListQuaternion();//保存截图public string targetImg; }[System.Serializable] public class SaveList { //存档列表存储各个存档的地址public Liststring DataPath new Liststring(); } 存储存档列表、存档 //存档 public void TestSave() { //取当前时间来做存档的名字string now DateTime.Now.ToString(yyyy-M-d-HH-mm-ss);string path Application.dataPath /StreamingFile/ now;//调用存档方法SaveData saveData CreatSave(path);//利用jsonutility将savedata转为jsonstring saveJson JsonUtility.ToJson(saveData);//将json写入文件//新建StreamWriter写入jsonStreamWriter streamWriter new StreamWriter(path .json);streamWriter.Write(saveJson);//关闭StreamWriterstreamWriter.Close();TestListSave(path);Debug.Log(保存成功); }/// summary /// 存储存档列表 /// /summary /// param namepathname/param void TestListSave(string pathname) {SaveList sl new SaveList();string path Application.dataPath /StreamingFile/list.list;//alllist是临时List用于存所有的存档个数alllist.Add(pathname);sl.DataPath alllist;//将所有的存档个数打包保存覆盖式string saveList JsonUtility.ToJson(sl);StreamWriter streamWriter new StreamWriter(path);streamWriter.Write(saveList);streamWriter.Close(); }/// summary /// 创建Save对象存储当前状态 /// /summary /// returns/returns private SaveData CreatSave(string path) {SaveData saveTest new SaveData();//all是所有的目标物的父物体将位置和旋转存入listfor (int i 0;i all.childCount;i){saveTest.targetPosition.Add(all.GetChild(i).position);saveTest.targetRotation.Add(all.GetChild(i).rotation);}//将存档截图地址保存saveTest.targetImg path;//截图功能CameraCapture(path, main, new Rect(0, 0, Screen.width, Screen.height));return saveTest; } 截图相关代码 //指定相机指定范围 public static void CameraCapture(string i, Camera camera, Rect rect) { string path Path.Combine(i, ${i}.png);int w (int)rect.width;int h (int)rect.height;RenderTexture rt new RenderTexture(w, h, 0);//将相机渲染内容存到指定RenderTexturecamera.targetTexture rt;camera.Render();//激活指定RenderTextureRenderTexture.active rt;//参数4mipchain多级渐远纹理Texture2D t2D new Texture2D(w, h, TextureFormat.ARGB32, true);//防止截黑屏可能会报错//yield return new WaitForEndOfFrame();//把RenderTexture像素读到texture2dt2D.ReadPixels(rect, 0, 0);t2D.Apply();//存成PNGbyte[] bytes t2D.EncodeToPNG();File.WriteAllBytes(path, bytes);//用完重置、销毁camera.targetTexture null;RenderTexture.active null;GameObject.Destroy(rt); }public static Sprite LoadShot(string i) {string shotPath Application.dataPath /StreamingFile/Shot;var path Path.Combine(shotPath, ${i}.png);Texture2D t new Texture2D(640, 360);t.LoadImage(GetImgByte(path));return Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0.5f, 0.5f)); }static byte[] GetImgByte(string path) {FileStream s new FileStream(path, FileMode.Open);byte[] imgByte new byte[s.Length];s.Read(imgByte, 0, imgByte.Length);s.Close();return imgByte; }public static void deleteShot(string i) {string shotPath Application.dataPath /StreamingFile/Shot;var path Path.Combine(shotPath, ${i}.png);if (File.Exists(path)){File.Delete(path);Debug.Log($删除{i});} } 读取存档列表和存档 //读档 public void LoadTest(Text text) { string filepath Application.dataPath /StreamingFile/ text.text .json;if (File.Exists(filepath)){//创建StreamReader读取jsonStreamReader streamReader new StreamReader(filepath);//将json赋值给stringstring json streamReader.ReadToEnd();//关闭streamReader.Close();//将字符串json转换为savedata对象SaveData saveData JsonUtility.FromJsonSaveData(json);SetLoadSave(saveData);}else{Debug.Log(没有存档);} } /// summary /// 根据列表加载存档处理数据 /// /summary /// param namepathname/param void TestListLoad() {string path Application.dataPath /StreamingFile/list.list;if (File.Exists(path)){//创建StreamReader读取jsonStreamReader streamReader new StreamReader(path);//将json赋值给stringstring json streamReader.ReadToEnd();//关闭streamReader.Close();//将字符串json转换为SaveList对象SaveList saveList JsonUtility.FromJsonSaveList(json);if(saveList ! null){for (int i 0; i saveList.DataPath.Count; i){根据数据显示scroll view下的物体并将数据赋过去var obj list.transform.GetChild(0).GetChild(0).GetChild(i);obj.gameObject.SetActive(true);obj.GetComponentImage().sprite LoadShot(saveList.DataPath[i]);string str saveList.DataPath[i].Split(/)[5];obj.GetChild(2).GetComponentText().text str.Substring(0, 18);//读档时候将之前的列表内容读到临时list暂存alllist.Add(saveList.DataPath[i]);}}} }/// summary/// 将savedata数据赋值给当前场景/// /summary/// param namesaveData/paramprivate void SetLoadSave( SaveData saveData){if (saveData ! null){for (int i 0; i all.childCount; i){all.GetChild(i).position saveData.targetPosition[i];all.GetChild(i).rotation saveData.targetRotation[i];}}} 项目地址【免费】unity数据持久化json存档与读档资源-CSDN文库
http://www.w-s-a.com/news/455917/

相关文章:

  • 西宁专业做网站教育网站建设策划书
  • 个人网站域名怎么起网站建设业务好跑吗
  • 网页设计的网网页设计的网站企业网站怎样做优化
  • 论文中小企业的网站建设域名网站空间
  • 宿迁网站建设联系电话现在出入邯郸最新规定
  • 男女做羞羞的事情网站30岁转行做网站编辑
  • 做企业网站的轻量级cmswordpress 越来越慢
  • 无锡中英文网站建设莱芜网络公司
  • ps软件下载官方网站相关搜索优化软件
  • 世界杯网站源码下载做网站推广代理
  • 用股票代码做网站的wordpress通过标签调用文章
  • iis添加网站ip地址树莓派运行wordpress
  • 网站空间域名多少钱宿迁做网站公司
  • 福州建设企业网站网站交互主要做什么的
  • 英文网站建设方法门户网站特点
  • 腾讯云备案 网站名称萧山城市建设网站
  • 漳浦网站建设网络营销推广策略
  • 龙岗商城网站建设教程百度关键词排名突然没了
  • 深圳网站建设服务哪家有织梦网站模板安装
  • 网站设计与网页制作代码大全网站开发还找到工作吗
  • 给设计网站做图会字体侵权吗站长工具seo综合查询张家界新娘
  • 网站的建设与颜色搭配win7在iis中新建一个网站
  • 单位做网站有哪些功能型类的网站
  • 网站怎样做优惠卷移动互联网开发培训
  • 重庆网站建设帝维科技网站做定向的作用
  • 网站建设工作室wp主题模板做污事网站
  • 网站建设 深圳 凡科重庆家居网站制作公司
  • 自己也可以免费轻松创建一个网站企业收录网站有什么用
  • 帮别人做网站违法导航网站开发工具
  • seo网站外包公司字画价格网站建设方案