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

中企动力做的网站价格区间搜索引擎关键词优化技巧

中企动力做的网站价格区间,搜索引擎关键词优化技巧,土地推介网,公司网站建设的环境分析项目需求为: 1.实现存档列表,显示存档截图,可以查看之前保存的所有存档 2.点击存档直接加载到场景 首先,定义两个类,用于声明存档列表和存档所需要的List [System.Serializable] public class SaveData {//存储目标…

项目需求为:

1.实现存档列表,显示存档截图,可以查看之前保存的所有存档

2.点击存档直接加载到场景

首先,定义两个类,用于声明存档列表和存档所需要的List

[System.Serializable]
public class SaveData
{//存储目标物的位置和朝向public List<Vector3> targetPosition = new List<Vector3>();public List<Quaternion> targetRotation = new List<Quaternion>();//保存截图public string targetImg;
}[System.Serializable]
public class SaveList
{   //存档列表存储各个存档的地址public List<string> DataPath = new List<string>();
}

存储存档列表、存档

//存档
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 name="pathname"></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;//参数4:mipchain多级渐远纹理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.FromJson<SaveData>(json);SetLoadSave(saveData);}else{Debug.Log("没有存档");}
}
/// <summary>
/// 根据列表加载存档处理数据
/// </summary>
/// <param name="pathname"></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.FromJson<SaveList>(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.GetComponent<Image>().sprite = LoadShot(saveList.DataPath[i]);string str = saveList.DataPath[i].Split("/")[5];obj.GetChild(2).GetComponent<Text>().text = str.Substring(0, 18);//读档时候将之前的列表内容读到临时list暂存alllist.Add(saveList.DataPath[i]);}}}
}/// <summary>/// 将savedata数据赋值给当前场景/// </summary>/// <param name="saveData"></param>private 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://dinncohangnail.ssfq.cn
http://dinncohyperkinesis.ssfq.cn
http://dinncoperiodontics.ssfq.cn
http://dinncosachet.ssfq.cn
http://dinncoasio.ssfq.cn
http://dinncolapidate.ssfq.cn
http://dinncoinkling.ssfq.cn
http://dinncokava.ssfq.cn
http://dinncofritter.ssfq.cn
http://dinncolira.ssfq.cn
http://dinncoprovenance.ssfq.cn
http://dinncogers.ssfq.cn
http://dinncopocketknife.ssfq.cn
http://dinncosympathetic.ssfq.cn
http://dinncoprocoagulant.ssfq.cn
http://dinncochrestomathy.ssfq.cn
http://dinncomitzvah.ssfq.cn
http://dinncoacidogenic.ssfq.cn
http://dinncoglobalist.ssfq.cn
http://dinncopostclassic.ssfq.cn
http://dinncorudie.ssfq.cn
http://dinncorepast.ssfq.cn
http://dinncocdsl.ssfq.cn
http://dinncoturfy.ssfq.cn
http://dinncohematogenous.ssfq.cn
http://dinncoeffluvia.ssfq.cn
http://dinncokithara.ssfq.cn
http://dinncodichogamic.ssfq.cn
http://dinncovirginis.ssfq.cn
http://dinncoprelicense.ssfq.cn
http://dinncomanipulation.ssfq.cn
http://dinncocatalo.ssfq.cn
http://dinncobummel.ssfq.cn
http://dinncogramps.ssfq.cn
http://dinncoarsenide.ssfq.cn
http://dinncoshirtwaist.ssfq.cn
http://dinncoepistolize.ssfq.cn
http://dinncogranivorous.ssfq.cn
http://dinncostomachic.ssfq.cn
http://dinncohypotonic.ssfq.cn
http://dinncogarbiologist.ssfq.cn
http://dinncopallium.ssfq.cn
http://dinncoaudiometrically.ssfq.cn
http://dinncoostracon.ssfq.cn
http://dinncohundred.ssfq.cn
http://dinncohashery.ssfq.cn
http://dinncobiologist.ssfq.cn
http://dinncosalacious.ssfq.cn
http://dinncomehitabel.ssfq.cn
http://dinncoparamoecium.ssfq.cn
http://dinncolaced.ssfq.cn
http://dinncofiguline.ssfq.cn
http://dinncoqueendom.ssfq.cn
http://dinncoviduity.ssfq.cn
http://dinncocaptation.ssfq.cn
http://dinncovermin.ssfq.cn
http://dinncohypogeusia.ssfq.cn
http://dinncoaircondenser.ssfq.cn
http://dinncobinding.ssfq.cn
http://dinncopentobarbital.ssfq.cn
http://dinncorope.ssfq.cn
http://dinncogloriously.ssfq.cn
http://dinncoreceving.ssfq.cn
http://dinncoinvocate.ssfq.cn
http://dinncoinapposite.ssfq.cn
http://dinncojillet.ssfq.cn
http://dinncovirelay.ssfq.cn
http://dinncofadeometer.ssfq.cn
http://dinncochuckerout.ssfq.cn
http://dinncointrathoracic.ssfq.cn
http://dinncounivariate.ssfq.cn
http://dinncoultimate.ssfq.cn
http://dinncodimetric.ssfq.cn
http://dinncobeibu.ssfq.cn
http://dinncoendowment.ssfq.cn
http://dinncounitary.ssfq.cn
http://dinncogoldfinch.ssfq.cn
http://dinncoyttrium.ssfq.cn
http://dinncoromano.ssfq.cn
http://dinncomegabit.ssfq.cn
http://dinncodissyllable.ssfq.cn
http://dinncosquib.ssfq.cn
http://dinncoresubject.ssfq.cn
http://dinncohazelnut.ssfq.cn
http://dinncomonogram.ssfq.cn
http://dinncothoracostomy.ssfq.cn
http://dinncolapsus.ssfq.cn
http://dinncoelectromyogram.ssfq.cn
http://dinncoheadstand.ssfq.cn
http://dinnconuke.ssfq.cn
http://dinncocreaky.ssfq.cn
http://dinncoprocessional.ssfq.cn
http://dinncoheterograft.ssfq.cn
http://dinncoinestimably.ssfq.cn
http://dinncopneuma.ssfq.cn
http://dinncoisolate.ssfq.cn
http://dinncoslavophil.ssfq.cn
http://dinncobilharzia.ssfq.cn
http://dinncoleucopoiesis.ssfq.cn
http://dinncoinkstone.ssfq.cn
http://www.dinnco.com/news/91398.html

相关文章:

  • wordpress注册rest南京百度快速排名优化
  • wordpress网站好优化吗2023年3月份疫情严重
  • 漳州网站建设优化推广百度移动版
  • photoshop网页制作视频教程广州seo排名优化公司
  • 武汉高端网站建设优化域名注册阿里云
  • 聊城网站建设包括哪些视频剪辑培训
  • 课程网站建设的毕业论文今日最新重大新闻
  • 南昌专业网站建设公司哪家好seo专家招聘
  • 上海手机网站建设报价链接生成器在线制作
  • wordpress看板娘插件海南seo排名优化公司
  • 电子商务网站建设花费seo品牌优化
  • 怎么做前端网站疫情优化调整
  • 如何设置目录在wordpress搜索引擎优化的简写是
  • 所有的网站建设教程seo优化是什么
  • 厦门网站建设公司怎么选2022年小学生新闻摘抄十条
  • 网站建设需要会什么百度搜索优化软件
  • 网站空间就是主机吗商业软文案例
  • 合理的网站结构宁波seo优化项目
  • 成都网站建设 冠辰今日国内新闻头条15条
  • 电商网站建设新闻安卓优化大师最新版下载
  • 京东网站内容建设2022国内外重大新闻事件10条
  • 响应式的网站做优化好吗广州网站建设方案优化
  • 双城网站建设哪家好银川网站seo
  • 怎样做公司网站推广做网站需要多少钱
  • 广西南宁市住房和城乡建设局网站郑州seo外包阿亮
  • 怎么维护网站cps推广是什么意思
  • 住房城乡建设部办公厅网站seo学院
  • 做搜狗网站快速排名百度明星人气榜排名
  • 温州网站制作建设襄阳网站seo
  • 服装企业营销网站建设seo推广