Пример #1
0
    public string SaveFile()
    {
        SaveFileBrowse pth = new SaveFileBrowse();

        pth.structSize = System.Runtime.InteropServices.Marshal.SizeOf(pth);
        //pth.filter = "txt files(.txt)|.txt";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath; // default path
        pth.title        = "保存项目";
        pth.defExt       = "txt";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;//选择的文件路径;

            File.WriteAllText(filepath, inputText.text);

            return(filepath);
        }

        return("NullPath");
    }
Пример #2
0
    public void SaveProject()
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = Marshal.SizeOf(pth);
        pth.filter       = "All files (*.*)|*.*";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath;
        pth.title        = "Save Project";
        pth.defExt       = "dat";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;
            Debug.Log(filepath);

            StreamWriter sw = new StreamWriter(filepath);


            string   result = sb.ToString().Substring(0, sb.ToString().Length - 1);
            string[] s      = result.Split(',');
            for (int i = 0; i < s.Count() / 3; i++)
            {
                sw.WriteLine(s[i * 3] + "," + s[i * 3 + 1] + "," + s[i * 3 + 2]);
            }

            sw.Flush();
            sw.Close();
        }
    }
Пример #3
0
    /// <summary>
    /// 保存文件
    /// </summary>
    /// <returns></returns>
    public static string SaveFile()
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = System.Runtime.InteropServices.Marshal.SizeOf(pth);
        pth.filter       = "txt (*.txt)";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath; // default path
        pth.title        = "保存项目";
        pth.defExt       = "txt";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;//选择的文件路径;
            Debug.Log(filepath);
            return(filepath);
        }
        else
        {
            return("");
        }
    }
Пример #4
0
 /// <summary>
 /// 打开窗口
 /// </summary>
 /// <returns></returns> 和该文件相关的数据
 public SaveDialogData SaveFileDlg()
 {
     if (SaveFileDialog.GetSaveFileName(CustomSaveData))
     {
         return(CustomSaveData);
     }
     return(null);
 }
Пример #5
0
    public void Btn_Stop_Click()
    {
        hawkNum.enabled   = true;
        doveNum.enabled   = true;
        foodNum.enabled   = true;
        foodValue.enabled = true;
        injury.enabled    = true;
        bluffing.enabled  = true;
        baseReq.enabled   = true;

        btn_Next.enabled  = false;
        btn_Stop.enabled  = false;
        btn_Start.enabled = true;

        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = Marshal.SizeOf(pth);
        pth.filter       = "All files (*.*)|*.*";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath;
        pth.title        = "Save Project";
        pth.defExt       = "dat";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;
            Debug.Log(filepath);

            StreamWriter sw = new StreamWriter(filepath);


            string   result = sb.ToString().Substring(0, sb.ToString().Length - 1);
            string[] s      = result.Split(',');
            for (int i = 0; i < s.Count() / 3; i++)
            {
                sw.WriteLine(s[i * 3] + "," + s[i * 3 + 1] + "," + s[i * 3 + 2]);
            }

            sw.Flush();
            sw.Close();
        }
    }
Пример #6
0
    /// <summary>
    /// 保存文件项目
    /// </summary>
    public void SaveProject(FileType fileType)
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize = Marshal.SizeOf(pth);
        switch (fileType)
        {
        case FileType.All:
            pth.filter = "All files (*.*)\0*.*";
            break;

        case FileType.png:
            pth.filter = "All files (*.png)\0*.png";
            break;

        case FileType.jpg:
            pth.filter = "All files (*.jpg)\0*.jpg";
            break;

        case FileType.txt:
            pth.filter = "All files (*.txt)\0*.txt";
            break;

        case FileType.json:
            pth.filter = "All files (*.json)\0*.json";
            break;

        default:
            break;
        }
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath; //默认路径
        pth.title        = "保存项目";
        pth.defExt       = "dat";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file; //选择的文件路径;
            Debug.Log(filepath);
        }
    }
Пример #7
0
    public static string GetSaveFilePath()
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = System.Runtime.InteropServices.Marshal.SizeOf(pth);
        pth.filter       = "REC (*.rec)\0*.rec\0\0";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.title        = "选择存档保存的位置";
        pth.defExt       = "rec";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008 | 0x00000002;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;
            return(filepath);
        }
        return(null);
    }
Пример #8
0
    /// <summary>
    /// 保存文件项目
    /// </summary>
    public void SaveProject()
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = Marshal.SizeOf(pth);
        pth.filter       = "All files (*.*)|*.*";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath; //默认路径
        pth.title        = "保存项目";
        pth.defExt       = "dat";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file; //选择的文件路径;
            UnityEngine.Debug.Log(filepath);
        }
    }
Пример #9
0
    /// <summary>
    /// 保存项目
    /// </summary>
    public string SaveProject(Action <string> _event)
    {
        SaveFileDlg _openFileDlg = new SaveFileDlg();

        _openFileDlg.structSize   = Marshal.SizeOf(_openFileDlg);
        _openFileDlg.filter       = filter;
        _openFileDlg.file         = defaultFileName + new string(new char[256 - defaultFileName.Length]);
        _openFileDlg.maxFile      = _openFileDlg.file.Length;
        _openFileDlg.fileTitle    = new string(new char[64]);
        _openFileDlg.maxFileTitle = _openFileDlg.fileTitle.Length;
        _openFileDlg.initialDir   = defaultPath; //默认路径
        _openFileDlg.title        = windowTitle;
        _openFileDlg.defExt       = defaultExt;
        _openFileDlg.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (SaveFileDialog.GetSaveFileName(_openFileDlg))
        {
            string _filepath = _openFileDlg.file;//选择的文件路径;
            _event(_filepath);
            return(_filepath);
        }
        return(null);
    }
Пример #10
0
    private void Save()
    {
        SaveFileDlg pth = new SaveFileDlg();

        pth.structSize   = Marshal.SizeOf(pth);
        pth.filter       = "bytes (*.bytes)";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath + "/HotUpdateRes/Story";        // default path
        UDebug.Log(Application.dataPath + "/HotUpdateRes/Story");
        pth.title  = "保存story数据";
        pth.defExt = "bytes";
        pth.flags  = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;

        Dictionary <string, int> plottext = new Dictionary <string, int>();
        string path = Application.dataPath + "/HotUpdateRes/Config/PlotTextConfig.txt";

        if (!File.Exists(path))
        {
            UDebug.LogError("can not find file : " + path);
            return;
        }
        string[] text           = File.ReadAllLines(path);
        bool     isChangeConfig = false;

        for (int i = 2; i < text.Length; i++)
        {
            if (string.IsNullOrEmpty(text[i]))
            {
                continue;
            }
            string[] plot = text[i].Split('\t');
            try
            {
                plottext.Add(plot[1], int.Parse(plot[0]));
            }
            catch (Exception e)
            {
                UDebug.Log(e.Message);
                UDebug.LogError("第一段:" + plot[0]);
                UDebug.LogError("第二段:" + plot[1]);
                throw;
            }
        }
        for (int i = 0; i < nodeRootList.Count; i++)
        {
            if (string.IsNullOrEmpty(((StoryNode)nodeRootList[i]).text))
            {
                ((StoryNode)nodeRootList[i]).textId = 0;
            }
            else if (plottext.ContainsKey(((StoryNode)nodeRootList[i]).text))
            {
                ((StoryNode)nodeRootList[i]).textId = plottext[((StoryNode)nodeRootList[i]).text];
            }
            else
            {
                int pltid = plottext[plottext.Keys.Last <string>()] + 1;
                plottext.Add(((StoryNode)nodeRootList[i]).text, pltid);
                ((StoryNode)nodeRootList[i]).textId = pltid;
                isChangeConfig = true;
            }
        }
        if (isChangeConfig)
        {
            string[] newtext = new string[plottext.Count + 2];
            int      i       = 2;
            newtext[0] = "id" + "\t" + "text";
            newtext[1] = "int" + "\t" + "string";
            foreach (var item in plottext)
            {
                newtext[i] = item.Value + "\t" + item.Key;
                i++;
            }
            File.WriteAllLines(Application.dataPath + "/HotUpdateRes/Config/PlotTextConfig.txt", newtext);
        }

        if (SaveFileDialog.GetSaveFileName(pth))
        {
            string filepath = pth.file;            //选择的文件路径;
            if (!OnSaveCheck())
            {
                return;
            }
            bool isSuccess = BinaryUtil.ObjectToFile(filepath, nodeRootList[0]);
            if (isSuccess)
            {
                path = filepath;
                UDebug.Log("Save succeed!");
            }
            else
            {
                UDebug.LogError("Save failed!");
            }
        }
    }