public static void OutputGuildTimeLine(GuildTimelineData timelineData, string defaultName) { try { OpenFileName openFileName = new OpenFileName(); openFileName.structSize = Marshal.SizeOf(openFileName); openFileName.filter = "Lua scripts(*.lua)\0*.lua\0"; openFileName.file = new string(new char[256]); openFileName.maxFile = openFileName.file.Length; openFileName.fileTitle = new string(new char[64]); openFileName.maxFileTitle = openFileName.fileTitle.Length; openFileName.initialDir = Application.dataPath; openFileName.title = "选择保存Lua脚本路径"; openFileName.defExt = "lua"; openFileName.file = defaultName; openFileName.flags = 530952; var flag = DllTest.GetSaveFileName(openFileName); var text = openFileName.file.Replace("\\", "/"); if (flag) { SaveTimeline(timelineData, text); } } catch (Exception e) { MainManager.Instance.WindowConfigMessage(e.ToString(), null); } }
public void Save() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = ".xml\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Save Data"; ofn.defExt = "xml"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetSaveFileName(ofn)) { fileName = ofn.file; SortNotes(); xmlTools.WriteXml(fileName); } if (ofn.file == "") { return; } }
public void Open() { OpenFileName ofn = new OpenFileName(); ofn.dlgOwner = DllTest.GetActiveWindow(); // makes the window modal, but also causes flicker, solved by two WaitForEndOfFrame in coroutine ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "PNG Files\0*.png\0All Files\0*.*\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = Environment.CurrentDirectory; ofn.title = "Open Project"; ofn.defExt = "PNG"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetSaveFileName(ofn)) { StartCoroutine(TakeScreenShot(ofn)); } }
public IEnumerator writeXML(List <Lego> voxels) { GameObject target = GameObject.Find("Target"); OBJ obj = target.GetComponent <OBJ> (); string sSavePath = "result.lxfml"; OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "LXFML-Files (*.lxfml)\0*.lxfml\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Save Model"; ofn.defExt = "LXFML"; //显示文件的类型 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR // ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetSaveFileName(ofn)) { // StartCoroutine(WaitLoad(ofn.file));//加载图片到panle sSavePath = ofn.file; Debug.Log("Selected file with full path: {0}" + ofn.file); } /* * SaveFileDialog saveFileDialog = new SaveFileDialog(); * saveFileDialog.Filter = "LXFML-Files (*.lxfml)|*.lxfml" ; * if (saveFileDialog.ShowDialog () == DialogResult.OK) { * sSavePath = saveFileDialog.FileName; * }*/ //string sSavePath = EditorUtility.SaveFilePanel("Save Session","","","lxfml"); StreamWriter writer = File.CreateText(sSavePath); int threshold = (int)Mathf.Floor(((float)voxels.Count) / 10000); if (threshold == 0) { threshold = 1; } Debug.Log(threshold); saving = true; onLoading = true; obj.onProcessing = true; Debug.Log(voxels.Count); LoadingText.GetComponent <Text> ().text = "Saving \n writing to file..."; ref_trans_strs = new List <string> (); writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"); writer.WriteLine("<LXFML versionMajor=\"5\" versionMinor=\"0\" name=\"" + fileName + "\">"); writer.WriteLine(" <Meta>"); writer.WriteLine(" <Application name=\"LEGO Digital Designer\" versionMajor=\"4\" versionMinor=\"3\"/>"); writer.WriteLine(" <Brand name=\"LDD\"/>"); writer.WriteLine(" <BrickSet version=\"1564.2\"/>"); writer.WriteLine(" </Meta>"); writer.WriteLine(" <Cameras>"); writer.WriteLine(" <Camera refID=\"0\" fieldOfView=\"80\" distance=\"69.282035827636719\" transformation=\"0.70710688829421997,0,-0.70710688829421997,-0.40824830532073975,0.81649661064147949,-0.40824830532073975,0.57735037803649902,0.57735013961791992,0.57735037803649902,39.999996185302734,39.999992370605469,39.999996185302734\"/>"); writer.WriteLine(" </Cameras>"); writer.WriteLine(" <Bricks cameraRef=\"0\">"); int counter = 0; foreach (Lego grid in voxels) { int key; string matrix; bool isHorizontal = false; if (grid.getDimen().x > grid.getDimen().y) { //horizontal case key = (int)(grid.getDimen().y *10.0f + grid.getDimen().x); //Debug.Log (key); matrix = "1,0,0,0,1,0,0,0,1,"; if (grid.getDimen().y == 2) { isHorizontal = true; } } else { //vertical case key = (int)(grid.getDimen().x *10.0f + grid.getDimen().y); matrix = "0,0,1,0,1,0,-1,0,0,"; } string designId; if (grid.getType() == LegoType.BRCIK) { designId = brickID[key]; } else { designId = plateID[key]; } writer.WriteLine(" <Brick refID=\"" + counter.ToString() + "\" designID=\"" + designId + "\">"); writer.WriteLine(" <Part refID=\"" + counter.ToString() + "\" designID=\"" + designId + "\" materials=\"" + color2material[(int)grid.getColor()] + "\">"); Vector3 lPos = grid.getLPosition(isHorizontal); string lPos_str = String.Format("{0:0.##},{1:0.##},{2:0.##}", lPos.x, lPos.y, lPos.z); ref_trans_strs.Add(lPos_str); writer.WriteLine(" <Bone refID=\"" + counter.ToString() + "\" transformation=\"" + matrix + lPos_str + "\">"); writer.WriteLine(" </Bone>"); writer.WriteLine(" </Part>"); writer.WriteLine(" </Brick>"); counter++; if (counter % threshold == 0) { percentage = (float)counter / ((float)voxels.Count); } yield return(new WaitForFixedUpdate()); } writer.WriteLine(" </Bricks>"); writer.WriteLine(" <GroupSystems>"); writer.WriteLine(" <GroupSystems>"); writer.WriteLine(" </GroupSystems>"); writer.WriteLine(" </GroupSystems>"); writer.WriteLine(" <BuildingInstructions>"); writer.WriteLine(" </BuildingInstructions>"); writer.WriteLine("</LXFML>"); writer.Close(); Debug.Log("outputed"); obj.onProcessing = false; onLoading = false; yield return(new WaitForFixedUpdate()); saving = false; yield return(new WaitForSeconds(0.0f)); }
} // _LoadActionPlan() //https://forum.unity.com/threads/finally-a-serializable-dictionary-for-unity-extracted-from-system-collections-generic.335797/ // Unity doesn't know how to serialize generic dictionaries. //https://www.codeproject.com/Questions/454134/Serialize-Dictionary-in-csharp void _SaveActionPlan(Dictionary <string, List <ActionPlanController.Action> > myDict) { // string dictPath = UnityEngine.Application.dataPath + "/ActionPlans/" + m_fileName; OpenFileName sfn = new OpenFileName(); sfn.structSize = Marshal.SizeOf(sfn); sfn.filter = "All Files\0*.xml\0\0"; //"All Files\0*.*\0\0". // ofn.filter = "Log files\0*.log\0Batch files\0*.bat\0"; sfn.file = new string(new char[256]); sfn.maxFile = sfn.file.Length; sfn.fileTitle = new string(new char[64]); sfn.maxFileTitle = sfn.fileTitle.Length; sfn.initialDir = UnityEngine.Application.dataPath + "/ActionPlan/"; sfn.title = "Wrtie Action Plan File"; sfn.defExt = "xml"; sfn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR //https://stackoverflow.com/questions/43573907/c-sharp-interop-returning-struct-from-unmanaged-code-with-out-parameter-gives //StartCoroutine(ExecuteAfterTime(10000)); if (!DllTest.GetSaveFileName(sfn)) { Debug.LogError("File Saving Dialog Failed"); return; } //return; //// Open SaveFileDialog //SaveFileDialog save = new SaveFileDialog(); //save.Filter = "ActionPlanFile(*.xml)|*.xml"; //save.InitialDirectory = Directory.GetCurrentDirectory(); //save.Title = "Save Action Plan"; //if (save.ShowDialog() != DialogResult.OK) // return; //m_fileName FileStream fs = new FileStream(sfn.file, FileMode.Create); //FileStream fs = new FileStream(m_fileName, FileMode.Create); TextWriter textWriter = new StreamWriter(fs); SerializableDictionary <string, List <ActionPlanController.Action> > serializableDict = new SerializableDictionary <string, List <ActionPlanController.Action> >(); // copy dictionary to serializable dictionary foreach (var kvp in myDict) { Debug.Log(kvp.Key + ":" + kvp.Value); serializableDict.Add(kvp.Key, kvp.Value); } XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary <string, List <ActionPlanController.Action> >)); serializer.Serialize(textWriter, serializableDict); textWriter.Close(); //BinaryReader br = new BinaryReader(fs); ////var binaryFormatter = new BinaryFormatter(); ////var fi = new System.IO.FileInfo(dictPath); ////try ////{ //// using (var binaryFile = fi.Create()) //// { //// binaryFormatter.Serialize(binaryFile, myDict); //// binaryFile.Flush(); //// binaryFile.Close(); //// } ////} ////catch (Exception ex) ////{ //// Debug.LogError(" Exception: " + ex.ToString()); ////} ////Dictionary<String, List<ActionPlanController.Action>> //// b is this //SerializableDictionary<string, List<ActionPlanController.Action>> b = new SerializableDictionary<string, // List<ActionPlanController.Action>>(); //// copy dictionary to serializable dictionary //foreach (var kvp in myDict) //{ // b.Add(kvp.Key, kvp.Value); //} ////List<string> stringList = new List<string>(); //// stringList.Add("1"); //// b.Add("One", stringList); //XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, // List<ActionPlanController.Action>>)); //TextWriter textWriter = new StreamWriter(saveFileName); //serializer.Serialize(textWriter, b); //textWriter.Close(); //FileStream file = File.Create(dictPath); //FileStream file = new FileStream(dictPath, FileMode.OpenOrCreate, FileAccess.Write); //BinaryFormatter bf = new BinaryFormatter(); //// Serialize(Stream serializationStream, object graph); //try //{ // bf.Serialize(file, myDict); //} //catch (Exception ex) //{ // Debug.LogError(" Exception: " + ex.ToString()) ; //} //file.Close(); ; }// _SaveActionPlan