找回密码
 立即注册
查看: 232|回复: 0

Unity 深拷贝

[复制链接]
发表于 2022-12-19 16:59 | 显示全部楼层 |阅读模式
using System.IO;using System.Xml.Serialization;using UnityEngine;void Start(){    List<List<Vector3>> lData = new List<List<Vector3>>();    List<Vector3> pList = new List<Vector3>();    pList.Add(new Vector3(0.3f, 0.6f, 0));    pList.Add(new Vector3(1.2f, 1.8f, 0));    List<Vector3> pList1 = Clone<List<Vector3>>(pList);    lData.Add(pList1);    //lData.Add(pList);    pList.RemoveAt(0);    List<Vector3> l = lData[0];    print("----count :" + l.Count);}public static T Clone<T>(T RealObject){    using (System.IO.Stream stream = new MemoryStream())    {        XmlSerializer serializer = new XmlSerializer(typeof(T));        serializer.Serialize(stream, RealObject);        stream.Seek(0, SeekOrigin.Begin);        return (T)serializer.Deserialize(stream);    }}
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-15 22:57 , Processed in 0.087813 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表