コード例 #1
0
        public static IEnumerator Download(string _strUrl, string _strLocalPath, string _strFilename, Action <float> _onProgress, Action <bool> _onFinished)
        {
            string server_file_path = System.IO.Path.Combine(_strUrl, _strLocalPath);

            server_file_path = System.IO.Path.Combine(server_file_path, _strFilename);

            if (_strLocalPath.Equals("") == false)
            {
                // 拡張子なしファイルがあるので、無理やり拡張子をつける
                EditDirectory.MakeDirectory(_strLocalPath + "/" + _strFilename + ".dummy");
                server_file_path = string.Format("{0}/{1}/{2}", _strUrl, _strLocalPath, _strFilename);
            }
            else
            {
                // ファイル名に階層が入ることもあるので・・・
                EditDirectory.MakeDirectory(_strFilename + ".dummy");
                server_file_path = string.Format("{0}/{1}", _strUrl, _strFilename);
            }

            string persisten_file_path = System.IO.Path.Combine(Application.persistentDataPath, _strLocalPath);

            persisten_file_path = System.IO.Path.Combine(persisten_file_path, _strFilename);

            Debug.Log(server_file_path);
            WWW www = new WWW(server_file_path);

            bool bResult = false;

#if !UNITY_WEBPLAYER
            while (!www.isDone)
            {
                _onProgress(www.progress);
                yield return(new WaitForEndOfFrame());
            }
            if (www.error == null)
            {
                bResult = true;
                File.WriteAllBytes(persisten_file_path, www.bytes);
            }
            else
            {
                Debug.LogError(www.error);
                Debug.LogError(_strUrl);
                Debug.LogError(_strLocalPath);
                Debug.LogError(_strFilename);
            }
#endif

            _onFinished.Invoke(bResult);
            yield return(0);
        }
コード例 #2
0
        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();
                FieldInfo[] infoArray = dummy.GetType().GetFields();
                //Debug.Log(test++);
                bool   bIsFirst = true;
                string strHead  = "";
                foreach (FieldInfo 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 (FieldInfo 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;
        }
コード例 #3
0
        /*
         * 特に指定が無い場合は自動書き込み
         * 独自実装をしたい場合は個別に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();
                FieldInfo[] infoArray = dummy.GetType().GetFields();
                //Debug.Log(test++);
                bool   bIsFirst = true;
                string strHead  = "";
                foreach (FieldInfo 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 (FieldInfo 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;
        }