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

佛山b2b网站建设广告制作

佛山b2b网站建设,广告制作,如何建设销售型企业网站,南京网站制作公司怎么样系列文章目录 unity工具 文章目录 系列文章目录👉前言👉一、设置环境👉二、代码如下👉三、使用方法 👉四、下次外部调用json里面的摄像机位置的时候如下代码方法👉壁纸分享👉总结 &#x1f449…

系列文章目录

unity工具


文章目录

  • 系列文章目录
  • 👉前言
  • 👉一、设置环境
  • 👉二、代码如下
    • 👉三、使用方法
  • 👉四、下次外部调用json里面的摄像机位置的时候如下代码方法
  • 👉壁纸分享
  • 👉总结


👉前言

有时候会用到给模型定位视角的(写死的那种,因为有时候人家就要那个视角,没有办法只能整个小工具来方便一下自己),所以写了一个动态保存视角的功能,方便使用,简单记录一下,不喜勿喷哦,
大家好,我是心疼你的一切,不定时更新Unity开发技巧,觉得有用记得一键三连哦。
有问题 欢迎点赞评论哦.
下面就让我们进入正文吧 !


提示:以下是本篇文章正文内容,下面案例可供参考

👉一、设置环境

1.创建Plugins文件夹
2.把LitJson.dll文件放到Plugins文件夹里
3.创建UI 一个InputField 输入框 一个按钮Button

4.代码的界面设置如下(下面也有介绍)
在这里插入图片描述

👉二、代码如下

1.生成的json文件在特殊文件StreamingAssets里面,具体设置到那个文件夹里面可以自己设置,看你自己心情哦,自己满意就行了哦.
2.代码也不复杂,一个读取json数据到字典的方法,一个保存json格式数据的,具体往下看代码吧
3.代码如下:

using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
/// <summary>
/// 保存数据为json
/// </summary>
public class CameraSaveLoad : MonoSingleton<CameraSaveLoad>
{public Transform cameraTransform; // 相机的Transform组件public string saveFileName = "camera_view.json"; // 保存文件的名称public InputField viewNameInput; // 用于输入视角名称的UI InputFieldpublic Button surebtn;   //保存视角的按钮public Dictionary<string, CameraView> CamerViewDic = new Dictionary<string, CameraView>();/// <summary>/// 1F相机位置/// </summary>private void Awake(){StartCoroutine(LoadDeviceDic());}// Start is called before the first frame updatevoid Start(){            surebtn.onClick.AddListener(SaveCameraPosition);}public class CameraView{public string name;public string position;public string rotation;      }/// <summary>/// 解析数据 字符串转v3/// </summary>/// <param name="sVector"></param>/// <returns></returns>public Vector3 StringToVector3(string sVector){// 移除字符串中的括号if (sVector.StartsWith("(") && sVector.EndsWith(")")){sVector = sVector.Substring(1, sVector.Length - 2);}// 拆分字符串为单独的值string[] sArray = sVector.Split(',');// 创建Vector3并返回return new Vector3(float.Parse(sArray[0]),float.Parse(sArray[1]),float.Parse(sArray[2]));}/// <summary>/// 将输入的视角名称和当前摄像机的视角保存到json里面/// </summary>public void SaveCameraPosition(){string viewName = viewNameInput.text;if (!string.IsNullOrEmpty(viewName)){CameraView cameraView = new CameraView{name = viewName,position = cameraTransform.position.ToString(),rotation = cameraTransform.rotation.eulerAngles.ToString()};AddCameratrToDic(viewName, cameraView);}}/// 将数据保存为jsonpublic void AddCameratrToDic(string viewname, CameraView viewdate){           if (!CamerViewDic.ContainsKey(viewname)){CamerViewDic.Add(viewname, viewdate);SaveCamerViewDicTojson(CamerViewDic);}else{CamerViewDic[viewname] = viewdate;SaveCamerViewDicTojson(CamerViewDic);}}public void Delel(){// string filePath = Path.Combine(Application.streamingAssetsPath, "example.txt");string filePath = Path.Combine(Application.persistentDataPath, "camera_view.json");// 检查文件是否存在if (File.Exists(filePath)){File.Delete(filePath);Debug.Log("文件已删除:" + filePath);}}public void SaveCamerViewDicTojson(Dictionary<string, CameraView> valuePairs){JsonData jsonData = JsonMapper.ToJson(valuePairs);Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");var ss = reg.Replace(jsonData.ToString(), delegate (Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });string filePath = Path.Combine(Application.streamingAssetsPath, "camera_view.json");File.WriteAllText(filePath, ss);Debug.Log("Dictionary data saved to: " + filePath);}/// <summary>/// 加载保存的相机视角数据到字典/// </summary>/// <returns></returns>public  IEnumerator LoadDeviceDic(){string filePath = Path.Combine(Application.streamingAssetsPath, "camera_view.json");var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath, "camera_view.json"));UnityWebRequest request = UnityWebRequest.Get(uri);yield return request.SendWebRequest();if (request.isNetworkError){Debug.Log(request.error);}else{string jsonStr = request.downloadHandler.text;CamerViewDic = JsonMapper.ToObject<Dictionary<string, CameraView>>(jsonStr);}     }}

👉三、使用方法

1.具体使用,可以运行的时候输入,点击保存,
2.也可以在编辑器里设置摄像机位置,手动输入到json里面,都可以,
3.下次调用的时候直接传你设置的摄像机位置名称即可
第四种
在脚本里加上一个输入框组件(InputField)一个按钮组件(Button)
在这里插入图片描述

在这里插入图片描述
脚本设置如下图
在这里插入图片描述
设置完成就可以运行场景,摄像机移动到合适的位置,起个名字输入到输入框里,点击按钮保存即可

👉四、下次外部调用json里面的摄像机位置的时候如下代码方法

 /// <summary>/// 获取存在字典里面的摄像机位置/// </summary>/// <param name="name">存的位置名称</param>public void SeetCamerView(string name){if (CameraSaveLoad.Instance.CamerViewDic.TryGetValue(name, out CameraSaveLoad.CameraView cameraViewdate)){if (cameraViewdate != null){currentCamerTr = name;Vector3 po = CameraSaveLoad.Instance.StringToVector3(cameraViewdate.position);Vector3 ro = CameraSaveLoad.Instance.StringToVector3(cameraViewdate.rotation);//设置摄像机的位置和旋转GameManager.Instance.SettingCamera(po, ro);}}}

具体调用方法可以自己实现哦
欢迎点赞评论哦,感谢,私聊也是可以的

👉壁纸分享

请添加图片描述
请添加图片描述

👉总结

本次总结的就是保存摄像机位置方便使用的实现,有需要会继续添加新的
如能帮助到你,就帮忙点个关注吧,三连更好哦,谢谢
你的点赞就是对博主的支持,有问题记得留言评论哦!
不定时更新Unity开发技巧,觉得有用记得一键三连哦。么么哒


文章转载自:
http://dinncodesulphurize.ydfr.cn
http://dinncoexsiccant.ydfr.cn
http://dinncostatued.ydfr.cn
http://dinncoesotropia.ydfr.cn
http://dinncoroburite.ydfr.cn
http://dinncodisrobe.ydfr.cn
http://dinncodesuetude.ydfr.cn
http://dinncosinapin.ydfr.cn
http://dinncoululation.ydfr.cn
http://dinncoalgophobia.ydfr.cn
http://dinncomakefast.ydfr.cn
http://dinncouranology.ydfr.cn
http://dinncocomplainingly.ydfr.cn
http://dinncocollegial.ydfr.cn
http://dinncolegato.ydfr.cn
http://dinncojibaro.ydfr.cn
http://dinnconumbing.ydfr.cn
http://dinncocrossing.ydfr.cn
http://dinncogynoecium.ydfr.cn
http://dinncostick.ydfr.cn
http://dinnconumbered.ydfr.cn
http://dinncodisentrancement.ydfr.cn
http://dinncocementitious.ydfr.cn
http://dinncoinfundibula.ydfr.cn
http://dinncodiabolo.ydfr.cn
http://dinncovertebratus.ydfr.cn
http://dinncoexalt.ydfr.cn
http://dinncoparastatal.ydfr.cn
http://dinnconinnyhammer.ydfr.cn
http://dinncoamoral.ydfr.cn
http://dinncoovercredulity.ydfr.cn
http://dinncokhud.ydfr.cn
http://dinncosquatty.ydfr.cn
http://dinncocrunchy.ydfr.cn
http://dinncocenote.ydfr.cn
http://dinncoloaf.ydfr.cn
http://dinncomediterranean.ydfr.cn
http://dinncoirrotationality.ydfr.cn
http://dinncomicrify.ydfr.cn
http://dinncounclog.ydfr.cn
http://dinncomystically.ydfr.cn
http://dinncowaterzooi.ydfr.cn
http://dinncopang.ydfr.cn
http://dinncochartist.ydfr.cn
http://dinncosemipalmated.ydfr.cn
http://dinncohiggs.ydfr.cn
http://dinncoadaptation.ydfr.cn
http://dinncopiggyback.ydfr.cn
http://dinncoyataghan.ydfr.cn
http://dinncoemic.ydfr.cn
http://dinncosugarhouse.ydfr.cn
http://dinncoarytenoidal.ydfr.cn
http://dinncocoupla.ydfr.cn
http://dinncohieromonk.ydfr.cn
http://dinncostromatolite.ydfr.cn
http://dinncotaxpaying.ydfr.cn
http://dinncoexsanguinate.ydfr.cn
http://dinncodeflexed.ydfr.cn
http://dinncobreathy.ydfr.cn
http://dinncolorryhop.ydfr.cn
http://dinncopelletron.ydfr.cn
http://dinncoadapted.ydfr.cn
http://dinncohelicline.ydfr.cn
http://dinncotakaoka.ydfr.cn
http://dinncoassegai.ydfr.cn
http://dinncoathletics.ydfr.cn
http://dinncomegalocephalous.ydfr.cn
http://dinncodominica.ydfr.cn
http://dinncotsadi.ydfr.cn
http://dinnconecrotic.ydfr.cn
http://dinncobronchitis.ydfr.cn
http://dinncoindology.ydfr.cn
http://dinncotitillation.ydfr.cn
http://dinncospirt.ydfr.cn
http://dinncosigrid.ydfr.cn
http://dinncoholder.ydfr.cn
http://dinncomonasterial.ydfr.cn
http://dinncopreinduction.ydfr.cn
http://dinncopallette.ydfr.cn
http://dinncoanasarca.ydfr.cn
http://dinncocrispin.ydfr.cn
http://dinncoloathing.ydfr.cn
http://dinncolubumbashi.ydfr.cn
http://dinncodecennial.ydfr.cn
http://dinncopersuasively.ydfr.cn
http://dinncoreincarnationist.ydfr.cn
http://dinncoboston.ydfr.cn
http://dinncocrawl.ydfr.cn
http://dinncoisopropanol.ydfr.cn
http://dinncojargoon.ydfr.cn
http://dinncomarketstead.ydfr.cn
http://dinncoprosimian.ydfr.cn
http://dinncomaladministration.ydfr.cn
http://dinncotinware.ydfr.cn
http://dinncothreateningly.ydfr.cn
http://dinncoesthonia.ydfr.cn
http://dinncolectureship.ydfr.cn
http://dinncogangrel.ydfr.cn
http://dinncoarenose.ydfr.cn
http://dinncopolydipsia.ydfr.cn
http://www.dinnco.com/news/161948.html

相关文章:

  • 手机网站建设视频教程_网页设计学生作业模板
  • WordPress搭建交互式网站厦门人才网官网
  • 什么企业做网站比较好网络营销推广方式包括哪些
  • 苏州学习网站建设日照高端网站建设
  • 西宁企业网站建设公司seo每天一贴博客
  • 友山建站优化seo培训机构
  • 网站建站实训总结seo工资待遇怎么样
  • 山楼小院在哪家网站做宣传网站链接提交
  • 注册公司材料怎么准备seo工资待遇怎么样
  • 山东济宁网站建设杭州网站优化推荐
  • 网站开发用到什么技术石家庄网络推广平台
  • 做不锈钢管网站优化网站推广教程排名
  • 行业网站建设济南竞价托管
  • wordpress行情滚动插件台州seo
  • 建一个公司网站花多少钱苏州seo关键词优化方法
  • h5制作网站西安百度推广竞价托管
  • 中国建材采购网官网深圳外贸seo
  • 揭阳seo网站管理seo平台怎么样
  • 做企业免费网站青岛seo关键词优化公司
  • 党课网络培训网站建设功能需求分析seo 网站优化推广排名教程
  • 百度网站推广怎么做在百度上怎么发布信息
  • 做网站的北京搜索引擎优化的要点
  • 武汉高端网站开发广州seo实战培训
  • 淘宝做基础销量网站域名注册费用
  • 西安360免费做网站西安网站开发制作公司
  • 买域名的网站有哪些seo技术培训班
  • 苏州做网站的专业公司有哪些十大品牌营销策划公司
  • 香港空间取网站内容抚顺网站建设
  • 汉口北做网站长沙自动seo
  • 企业宣传网站系统建设方案百家号权重查询站长工具