zoukankan      html  css  js  c++  java
  • C# 文件选择对话框,Unity3d文件保存对话框

    using OpenWinForm = System.Windows.Forms;

    在unity3d中,使用FileDialog应该把System.Windows.Forms.dll拷贝到unity工程的plugins目录,

    并且把Player Setting中Other Settings下的api compatibility Level改为.NET2.0。要不无法编译通过。

    //比如unity3d要让用户选择某一个音乐文件播放;

    private void SelectMusic(){
            OpenWinForm.OpenFileDialog op = new OpenWinForm.OpenFileDialog();
            op.Title = "音乐";
            op.Filter = "音频文件(*.wav;*.ogg)|*.wav;*.ogg";
            if (op.ShowDialog() == OpenWinForm.DialogResult.OK || op.ShowDialog() == OpenWinForm.DialogResult.Yes)
            {
                string selectName = op.FileName;
                customBgmPath.text = selectName;

                string path = customBgmPath.text;      
                WWW www = new WWW("file://"+path);
                if(www.audioClip){
                    AudioClip clip = www.audioClip;
                    AudioPlayCtr.instance.ChangeBgMusic(clip);
                }

            }
            else {
                return;
            }
        }

        //自定义文件保存文件夹;
        private void SaveCutScreenPath()
        {
            OpenWinForm.FolderBrowserDialog fb = new OpenWinForm.FolderBrowserDialog();
            fb.ShowNewFolderButton = true;
            fb.RootFolder = Environment.SpecialFolder.MyDocuments;
            fb.SelectedPath = "C:";
            fb.Description = "请选择截图保存目录";
            fb.RootFolder = Environment.SpecialFolder.MyDocuments;
            if (fb.ShowDialog() == OpenWinForm.DialogResult.OK || fb.ShowDialog() == OpenWinForm.DialogResult.Yes)
            {
                string selectName = fb.SelectedPath;
                customCutScreenPath.text = selectName;
            }
            else {
                return;
            }
        }

    //比如unity3d截图后,弹出对话框用户选择保存路径;

    public IEnumerator CutScreent() {
            int width = Screen.width;
            int height = Screen.height;
            yield return new WaitForEndOfFrame();
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);//设置Texture2D
            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);//获取Pixels           
            tex.Apply();//应用改变
            byte[] bytes = tex.EncodeToPNG();//转换为byte[]
            Destroy(tex);

            OpenWinForm.SaveFileDialog saveFileDialog = new OpenWinForm.SaveFileDialog();
            saveFileDialog.Filter = "图像文件(*.png)|*.png";
            saveFileDialog.FilterIndex = 2;
            saveFileDialog.RestoreDirectory = true;
            if (saveFileDialog.ShowDialog() == OpenWinForm.DialogResult.OK)
            {
                string fName = saveFileDialog.FileName;
                Stream flstr = new FileStream(fName, FileMode.Create);//文件操作
                BinaryWriter sw = new BinaryWriter(flstr, System.Text.Encoding.Unicode);
                sw.Write(bytes);
                sw.Close();
                flstr.Close();
            }
        }

  • 相关阅读:
    CSS3——过渡
    CSS——优雅降级和渐进增强
    jq1 颜色填充器 和清空指定颜色
    1. 初识node
    javaSE- 01
    鼠标悬浮图片时弹出透明提示图层的jQuery特效
    通过jQuery制作电子时钟表的代码
    9种网页Flash焦点图和jQuery焦点图幻灯片
    7种网页图片切换方式代码
    21种网页在线客服代码实例演示
  • 原文地址:https://www.cnblogs.com/2Yous/p/5079991.html
Copyright © 2011-2022 走看看