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

在Unity中使用C#进行Xml序列化时保留特定小数位的方法参考

序列化方法代码参考:

using System.IO;
using System.Xml.Serialization;public class XmlTool
{public static string ToXml<T>(T obj){XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));using var stringWriter = new StringWriter();//让xml文档的命名空间为空,文档显得简洁那么一点点。XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();xmlns.Add("","");//xmlSerializer.Serialize(stringWriter, obj, xmlns);return stringWriter.ToString();}public static T FromXml<T>(string xml){XmlSerializer xmlSerializer = new(typeof(T));return (T)xmlSerializer.Deserialize(new StringReader(xml));}
}

小数位数控制参考:

public struct SceneAreaInfo
{[XmlAttribute("X")]public string strX{get { return x.ToString("0.##"); }set { x = float.Parse(value); }}[XmlIgnore]public float x;//场景区域最左侧坐标[XmlAttribute("Y")]public string strY{get { return y.ToString("0.##"); }set { y = float.Parse(value); }}[XmlIgnore]public float y;//场景区域最下面坐标[XmlAttribute("Width")]public string strWidth{get { return width.ToString("0.##"); }set { width = float.Parse(value); }}[XmlIgnore]public float width;//场景区域宽度[XmlAttribute("Height")]public string strHeight{get { return height.ToString("0.##"); }set { height = float.Parse(value); }}[XmlIgnore]public float height;//场景区域高度[XmlIgnore]public Vector2 size => new Vector2(width, height);public SceneAreaInfo(float x, float y, float width, float height){this.x = x;this.y = y;this.width = width;this.height = height;}public SceneAreaInfo(Rect rect){x = rect.x;y = rect.y;width = rect.width;height = rect.height;}
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • MobaXterm 终端工具使用
  • 从0开始深度学习(5)——线性回归的逐步实现
  • 二进制方式安装K8S
  • 【Python】BeautifulSoup:HTML解析
  • H264结构及RTP封装
  • SQLite3 数据库
  • Linux中全局变量配置,/etc/profile.d还是/etc/profile
  • 数据结构(15)——哈希表(2)
  • C#从入门到精通(22)—Path类的使用
  • 2024 高教社杯 数学建模国赛 (C题)深度剖析|农作物的种植策略|数学建模完整代码+建模过程全解全析
  • 【项目一】基于pytest的自动化测试框架day1
  • CRE6959AM70V055S 超低待机功耗反激式开关电源芯片
  • CSS解析:盒模型
  • linux~~目录结构远程登录教程(xshell+xftp)
  • 鼠标控制dom元素的大小。采用ResizeObserver——监听元素大小的变化
  • Android单元测试 - 几个重要问题
  • Apache Zeppelin在Apache Trafodion上的可视化
  • CentOS 7 防火墙操作
  • HTML-表单
  • HTTP 简介
  • JS基础之数据类型、对象、原型、原型链、继承
  • js继承的实现方法
  • mysql 5.6 原生Online DDL解析
  • MySQL用户中的%到底包不包括localhost?
  • October CMS - 快速入门 9 Images And Galleries
  • Python打包系统简单入门
  • Python代码面试必读 - Data Structures and Algorithms in Python
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • 分享几个不错的工具
  • 汉诺塔算法
  • 悄悄地说一个bug
  • 微信小程序实战练习(仿五洲到家微信版)
  • 在 Chrome DevTools 中调试 JavaScript 入门
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • 教程:使用iPhone相机和openCV来完成3D重建(第一部分) ...
  • 直播平台建设千万不要忘记流媒体服务器的存在 ...
  • ​​​【收录 Hello 算法】9.4 小结
  • ​MySQL主从复制一致性检测
  • #if 1...#endif
  • #数据结构 笔记三
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • (01)ORB-SLAM2源码无死角解析-(56) 闭环线程→计算Sim3:理论推导(1)求解s,t
  • (4)事件处理——(6)给.ready()回调函数传递一个参数(Passing an argument to the .ready() callback)...
  • (9)STL算法之逆转旋转
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (定时器/计数器)中断系统(详解与使用)
  • (二)pulsar安装在独立的docker中,python测试
  • (附源码)python旅游推荐系统 毕业设计 250623
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • .JPG图片,各种压缩率下的文件尺寸
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .net core使用ef 6
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution