/* * 特に指定が無い場合は自動書き込み * 独自実装をしたい場合は個別にoverrideしてください * */ virtual protected void save(string _strFilename) { //Debug.LogWarning (string.Format( "kvs.save {0}" , list.Count)); //int test = 0; //Debug.Log(test++); StreamWriter sw; try { string strTempFilename = string.Format("{0}.csv.tmp", _strFilename); EditDirectory.MakeDirectory(strTempFilename); sw = Textreader.Open(Application.persistentDataPath, strTempFilename); //Debug.Log(test++); T dummy = new T(); PropertyInfo[] infoArray = dummy.GetType().GetProperties(); //Debug.Log(test++); bool bIsFirst = true; string strHead = ""; foreach (PropertyInfo info in infoArray) { if (!WritableField(info)) { continue; } if (bIsFirst == true) { bIsFirst = false; } else { strHead += ","; } strHead += info.Name; } //Debug.Log(test++); Textreader.Write(sw, strHead); //Debug.Log(test++); foreach (T data in list) { bIsFirst = true; string strData = ""; foreach (PropertyInfo info in infoArray) { //Debug.Log(test++); if (!WritableField(info)) { //Debug.Log(test++); continue; } if (bIsFirst == true) { bIsFirst = false; //Debug.Log(test++); } else { strData += ","; //Debug.Log(test++); } //Debug.Log(info.Name); //Debug.Log(data); //Debug.Log(data.GetString(info.Name)); strData += data.GetString(info.Name); //Debug.Log(strData); } //Debug.Log(strData); Textreader.Write(sw, strData); } Textreader.Close(sw); fileMove( Application.persistentDataPath, string.Format("{0}.csv.tmp", _strFilename), string.Format("{0}.csv", _strFilename)); } catch (Exception ex) { Debug.LogError(_strFilename); Debug.LogError(ex); return; } return; }
virtual protected void save_editor(string _strPath, string _strFilename) { StreamWriter sw; try { string strLocalFilename = Path.Combine(_strPath, _strFilename); string strTempFileName = string.Format("{0}.csv.temp", strLocalFilename); EditDirectory.MakeDirectory(_strPath, Application.dataPath); sw = Textreader.Open(Application.dataPath, strTempFileName); //Debug.Log(test++); T dummy = new T(); PropertyInfo[] infoArray = dummy.GetType().GetProperties(); //Debug.Log(test++); bool bIsFirst = true; string strHead = ""; foreach (PropertyInfo info in infoArray) { if (!WritableField(info)) { continue; } if (bIsFirst == true) { bIsFirst = false; } else { strHead += ","; } strHead += info.Name; } Textreader.Write(sw, strHead); foreach (T data in list) { bIsFirst = true; string strData = ""; foreach (PropertyInfo info in infoArray) { if (!WritableField(info)) { continue; } if (bIsFirst == true) { bIsFirst = false; } else { strData += ","; } string temp = data.GetString(info.Name); //Debug.Log(string.Format("info.Name{0} value={1}", info.Name, temp)); //temp = temp.Replace("\n", "\\n"); /* * if (temp.Contains("\n")) * { * //Debug.Log(temp); * } */ strData += temp; } strData = strData.Replace("\n", "\\n"); Textreader.Write(sw, strData); } Textreader.Close(sw); fileMove( Application.dataPath, string.Format("{0}", strTempFileName), string.Format("{0}.csv", strLocalFilename)); } catch (Exception ex) { Debug.LogError(_strFilename); Debug.LogError(ex); return; } return; }
// Update is called once per frame void Update() { bool bInit = false; if (m_eStepPre != m_eStep) { m_eStepPre = m_eStep; bInit = true; } switch (m_eStep) { case STEP.SCREENSHOT: if (bInit) { StartCoroutine(startScreenshot()); m_bScreenshot = false; EditDirectory.MakeDirectory(CsvSave.FILE_DIRECTORY); } if (m_bScreenshot) { m_goDispRoot.SetActive(true); m_eType = SaveBanner.TYPE.SAVE; if (m_bLoadOnly) { m_btnTabSave.gameObject.SetActive(false); m_eType = SaveBanner.TYPE.LOAD; } m_closeButton = PrefabManager.Instance.MakeObject("prefab/CloseButton", m_goDispRoot).GetComponent <ButtonBase> (); m_eStep = STEP.IDLE; if (m_bLoadOnly == false) { NendAdInterstitial.Instance.Show(); } } break; case STEP.IDLE: if (m_eType == SaveBanner.TYPE.SAVE) { m_eStep = STEP.SAVE_PAGE; } else { m_eStep = STEP.LOAD_PAGE; } m_eStep = STEP.SAVE_PAGE; break; case STEP.SAVE_PAGE: if (bInit) { if (m_saveBannerRoot == null) { m_saveBannerRoot = PrefabManager.Instance.MakeScript <SaveBannerRoot> ("prefab/SaveBannerRoot", m_goDispRoot); } // ここの10は特に可変にはしてません m_saveBannerRoot.Initialize(m_eType, 10); m_saveBannerRoot.TriggerClearAll(); m_closeButton.TriggerClear(); m_btnTabSave.TriggerClear(); m_btnTabLoad.TriggerClear(); } if (m_saveBannerRoot.ButtonPushed) { m_iCheckNo = m_saveBannerRoot.Index + 1; // あんまよくないけどここで補正 m_saveBannerRoot.TriggerClearAll(); m_eStep = STEP.SAVE_CHECK; bool bSound = true; if (m_eType == SaveBanner.TYPE.LOAD) { CsvSave save = new CsvSave(); save.Load(m_iCheckNo); if (false == save.m_bExistData) { m_eStep = m_eStepPre; bSound = false; } else { m_strSaveTime = save.Read("save_time"); } } if (bSound) { SoundHolder.Instance.Call(DataManager.Instance.SOUND_NAME_CURSOR); } else { SoundHolder.Instance.Call(DataManager.Instance.SOUND_NAME_CANCEL); } } if (m_btnTabLoad.ButtonPushed) { m_eType = SaveBanner.TYPE.LOAD; m_eStep = STEP.IDLE; } if (m_btnTabSave.ButtonPushed) { m_eType = SaveBanner.TYPE.SAVE; m_eStep = STEP.IDLE; } if (m_closeButton.ButtonPushed) { m_eStep = STEP.END; } break; case STEP.SAVE_CHECK: if (bInit) { m_saveCheck = PrefabManager.Instance.MakeScript <SaveCheck> ("prefab/SaveCheck", gameObject); m_saveCheck.Initialize(m_eType, m_iCheckNo, m_strSaveTime, m_bLoadOnly); } if (m_saveCheck.IsEnd()) { m_bDecide = m_saveCheck.m_bDecide; m_eStep = STEP.IDLE; if (m_bDecide) { if (m_bLoadOnly) { m_eStep = STEP.END; } SoundHolder.Instance.Call(DataManager.Instance.SOUND_NAME_DECIDE); } else { SoundHolder.Instance.Call(DataManager.Instance.SOUND_NAME_CANCEL); } Destroy(m_saveCheck.gameObject); } break; case STEP.LOAD_PAGE: if (m_closeButton.ButtonPushed) { m_eStep = STEP.END; } break; case STEP.LOAD_CHECK: break; case STEP.END: if (bInit) { SpriteManager.Instance.Unload(TEMP_SCREENSHOT_NAME); if (m_bLoadOnly == false) { NendAdInterstitial.Instance.Show(); } m_bIsEnd = true; } break; case STEP.MAX: default: break; } }