Unity 深拷贝
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; 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); }}
页:
[1]