/// 保存路标点至XML<summary> /// 保存路标点至XML /// </summary> /// <param name="xmlFileName">xml文件名(不包含路径)</param> /// <param name="all">路标点集合(父物体)</param> public void SaveWaypointsToXml(WaypointMessage all, string xmlPath) { WaypointsXML temWaypointsXML = new WaypointsXML(); int number = 0; //xml是否存在,如果存在就删除 //否则会叠加 if (File.Exists(xmlPath)) { File.Delete(xmlPath); } foreach (Transform child in all.transform) { number++; WaypointsModel temWM = new WaypointsModel(); temWM.Index = int.Parse(child.transform.name); temWM.Position = child.position; temWM.Rotation = child.rotation; temWM.Scale = child.localScale; temWaypointsXML.AddXmlData(temWM, xmlPath); } //保存后刷新路标点 LoadXmlToWaypoints(all, xmlPath); if (Debug.isDebugBuild) { Debug.Log("【" + all.WaypointsModelAll.Count.ToString() + "】保存完成:" + all.curWaypointsXMLPath); } }
/// 加载XML至路标点 <summary> /// 加载XML至路标点 /// </summary> /// <param name="xmlFileName">xml文件名(不包含路径)</param> /// <param name="all">路标点集合(父物体)</param> public void LoadXmlToWaypoints(WaypointMessage all, string xmlPath = null, string xmlString = null) { WaypointsXML temWaypointsXML = new WaypointsXML(); WaypointsModel temWM = new WaypointsModel(); int number = 0; all.WaypointsModelAll.Clear(); //销毁子物体 DestroyChild(all.transform); //获取XML数据至集合 temWaypointsXML.GetXmlData(all.WaypointsModelAll, xmlPath, xmlString); for (int i = 0; i < all.WaypointsModelAll.Count; i++) { number++; //在编辑器中则创建 if (Application.platform == RuntimePlatform.WindowsEditor) { GameObject go = new GameObject(); go.transform.parent = all.transform; go.name = all.WaypointsModelAll[i].Index.ToString(); go.transform.position = all.WaypointsModelAll[i].Position; go.transform.rotation = all.WaypointsModelAll[i].Rotation; go.transform.localScale = all.WaypointsModelAll[i].Scale; } } if (Debug.isDebugBuild) { Debug.Log("【" + all.WaypointsModelAll.Count.ToString() + "】加载完成:" + all.curWaypointsXMLPath); } }