/// <summary> /// 将数据存入文件 /// </summary> /// <param name="headData">文件头部数据</param> /// <param name="strFileName">文件存储全路径</param> /// <param name="StartFrame">原数据的有效起始帧</param> /// <param name="EndFrame">原数据的有效终止帧</param> public void SaveDataToFile(MovieHeadData headData, string strFileName, int StartFrame = -1, float EndFrame = -1) { if (StartFrame < 0 || StartFrame >= cacheDataList.Count) { StartFrame = 0; } if (EndFrame < 1 || EndFrame >= cacheDataList.Count) { EndFrame = cacheDataList.Count; } try { using (StreamWriter sw = new StreamWriter(strFileName, false)) { //文件头 sw.Write(headData.toStr()); //数据 for (int i = StartFrame; i < EndFrame; ++i) { sw.Write(cacheDataList[i].toStr()); } sw.Close(); } } catch (Exception e) { Debug.Log("The file could not be write:"); Debug.Log(e); } }
//用文件路径初始化对象 public FileReader(string strFilePath) { m_filepath = strFilePath; m_head_data = GetHeadFromFile(strFilePath); if (m_head_data.strIdentify == "MOVIE_DATA") { readTxtFile(m_filepath, ref m_data_list); } else { Debug.Log("FILE TYPE ERROR!"); } }
public void Btn_Save() { if (string.IsNullOrEmpty(m_InputDoctorName.text) || string.IsNullOrEmpty(m_InputFilePath.text)) { m_InputDoctorName.placeholder.GetComponent <Text>().color = Color.red; m_InputFilePath.placeholder.GetComponent <Text>().color = Color.red; } else { //根据输入的文件名和选择的头像,将文件存储到默认存储文件夹,将头像图片复制到默认头像存储文件夹 m_FilePath = ToolFunction.GetMovieSaveFilePath(m_InputFilePath.text, ".txt"); var tempPortrait = ToolFunction.GenerateStringID(); ToolFunction.ImageSaveLocal(m_PortraitImage.mainTexture, ToolFunction.GetDefaultPortraitPathByName(tempPortrait, ".jpg")); int tempTimeCount = m_RecordManager.GetFrameCount(); int tempStartTime = (int)(tempTimeCount * m_fLeftSliderValue); int tempEndTime = (int)(tempTimeCount * m_fRightSliderValue); MovieHeadData tempData = new MovieHeadData( "MOVIE_DATA", m_InputDoctorName.text, tempPortrait, System.DateTime.Now.ToString("MM/dd/yyyy H:mm:ss"), tempEndTime - tempStartTime, 0, ConfigCenter.Instance().GetFPS() ); m_RecordManager.SaveDataToFile( tempData, m_FilePath, tempStartTime, tempEndTime ); m_SavePanel.SetActive(false); m_InfoSaved.SetActive(true); } }
public void SaveDataToFile(MovieHeadData headData, string strFileName, int nStartTime = -1, int nEndTime = -1) { m_FileWriter.SaveDataToFile(headData, strFileName, nStartTime, nEndTime); }