Example #1
0
    public void OpenFileWin()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);
        ofn.filter     = "All Files\0*.*\0\0";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path           = path.Replace('/', '\\');
        ofn.initialDir = path;
        ofn.title      = "Open Model";

        ofn.defExt = "JSON";                                                        //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
            Path.text = ofn.file.Replace("\\", "/");
        }
    }
    void OnGUI()
    {
        if (isPlay)
        {
            GUI.DrawTexture(new Rect(0, 0, 320, 240), cameraTexture, ScaleMode.ScaleAndCrop);
        }

        if (GUI.Button(new Rect(20, 650, 100, 35), "ChooseFile"))
        {
            OpenFileName ofn = new OpenFileName();
            ofn.structSize   = Marshal.SizeOf(ofn);
            ofn.filter       = "All Files\0*.*\0\0";
            ofn.file         = new string(new char[256]);
            ofn.maxFile      = ofn.file.Length;
            ofn.fileTitle    = new string(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;
            string path = Application.streamingAssetsPath;
            path = path.Replace('/', '\\');
            //默认路径
            // ofn.InitialDirectory = path;
            //ofn.InitialDirectory = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
            ofn.title  = "Open Project";
            ofn.defExt = "JPG";                                                         //显示文件的类型
            //注意 一下项目不一定要全选 但是0x00000008项不要缺少
            ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
            if (WindowDll.GetOpenFileName(ofn))
            {
                UnityEngine.Debug.Log("Selected file with full path: " + ofn.file);
                StartCoroutine(IEHttpGet(ofn.file));
            }
        }
    }
Example #3
0
    public void OpenFileWin()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "All Files\0*.*\0\0";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        ofn.initialDir = path;

        ofn.title = "Open Project";

        ofn.defExt = "JPG";                                                         //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            Debug.Log("path is " + ofn.file);
            //选择E:\Work\controlTest\Assets\StreamingAssets\x86_64下的dll测试
            string outResult = WindowDll.LoadLibraryTool("inputtest", ofn.file, "testDllMethod111");
            Debug.Log("output is " + outResult);
        }
    }
Example #4
0
    static string OpenFile(string path, string title, bool multiselect, string filter)
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = filter;

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;

        path = path.Replace('/', '\\');
        //默认路径
        ofn.initialDir = path;
        //ofn.InitialDirectory = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        ofn.title = title;

        ofn.defExt = "unity3d";                                                     //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
        return(ofn.file);
    }
Example #5
0
    public void onRead()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        ofn.initialDir = path;

        ofn.title = "Open Project";

        ofn.defExt = "JPG";                                                         //显示文件的类型
                                                                                    //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            StartCoroutine(Load(ofn.file));
        }
    }
Example #6
0
    public void OpenFileWin()
    {
        WindowsOpenFile wof = new WindowsOpenFile();

        wof.structSize = Marshal.SizeOf(wof);

        //wof.filter = "All Files\0*.*\0\0";
        wof.filter = "excel文件 (*.xlsx; *.xls)\0 *.xlsx; *.xls\0\0";

        wof.file = new string(new char[256]);

        wof.maxFile = wof.file.Length;

        wof.fileTitle = new string(new char[64]);

        wof.maxFileTitle = wof.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        wof.initialDir = path;
        //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        wof.title = "Open Project";

        wof.defExt = "xls";                                                         //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        wof.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(wof))
        {
            Debug.Log("Selected file with full path: {0} = " + wof.file);
            GameReadExcel(wof.file);
        }
    }
Example #7
0
    public static void OpenPhoto()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "(*.jpg*.png)\0*.jpg;*.png";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;

        ofn.initialDir = UnityEngine.Application.dataPath;// 默认路径

        ofn.title = "Open Project";

        // ofn.defExt = "jpg";// 显示文件的类型

        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            //Debug.Log("Selected file with full path: {0}" + ofn.file);

            ////需要增加压缩处理
            //OnPhotoCameraFileResult(ofn.file);
            OpenFile(ofn.file);
        }
    }
Example #8
0
    public void OpenFileDiaLog(Action <string> action)
    {
        OpenFileDialogTest ofn = new OpenFileDialogTest();

        ofn.structSize = Marshal.SizeOf(ofn);
        //ofn.filter = "三菱(*.gxw)\0*.gxw\0西门子(*.mwp)\0*.mwp\0All Files\0*.*\0\0";
        ofn.filter       = fileSuffix;
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path           = path.Replace('/', '\\');//默认路径
        ofn.initialDir = path;
        ofn.title      = openWindowName;
        //ofn.defExt = "JPG";//显示文件的类型
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;        //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))
        {
            if (action != null)
            {
                action(ofn.file);
            }
        }
    }
Example #9
0
    //加载头像图片
    public void OpenFile()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "图片文件(*.jpg*.png*.jpeg)\0*.jpg;*.png;*.jpeg";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;

        ofn.initialDir = UnityEngine.Application.dataPath;//默认路径

        ofn.title = "选择图片";

        ofn.defExt = "PNG";                                                         //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            this.loadingImg.SetActive(true);
            StartCoroutine(GetTexture(ofn.file));//加载图片到panle
        }
    }
Example #10
0
    public void OpenFileWin()
    {
        //GameObject.FindWithTag("moviePlayer").GetComponent<VideoPlayer>().Pause();

        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "All Files\0*.*\0\0";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        ofn.initialDir = path;
        //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        ofn.title = "Open Project";

        ofn.defExt = "JPG";                                                         //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
        //此处更改了大部分答案的协程方法,在这里是采用unity的videoplayer.url方法播放视频;
        //

        /*而且我认为大部分的其他答案,所给的代码并不全,所以,想要其他功能的人,可以仿照下面的代码,直接在此类中写功能。
         * //*/
        //https://blog.csdn.net/weixin_38472903/article/details/78204366  原地址


        ChangeTexture(needChange, ofn.file);
    }
    public static string OpenFileDialog(AssetFileType fileType, string windowTitle = "打开文件", string initPath = null)
    {
        OpenFileName ofn = InitDialogCommon(windowTitle, initPath);

        GetFliter(fileType, out ofn.filter, out ofn.defExt);
        ofn.flags = (int)(
            OpenFileNameFlags.OFN_EXPLORER
            | OpenFileNameFlags.OFN_FILEMUSTEXIST
            | OpenFileNameFlags.OFN_PATHMUSTEXIST
            | OpenFileNameFlags.OFN_NOCHANGEDIR
            );

        if (WindowDll.GetOpenFileName(ofn))
        {
            IntPtr filePointer = ofn.file;
            string file        = Marshal.PtrToStringAuto(filePointer);
            return(file);
        }
        return(null);
    }
Example #12
0
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="Title">标题</param>
        /// <param name="path">默认路径</param>
        /// <param name="filter">文件类型</param>
        /// <returns></returns>
        public static string OpenFileGetPath(string Title, string path, string filter)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new Exception("path is not null(HelpGetFile.cs)");
            }
            OpenFileName openFile = new OpenFileName();

            openFile.structSize = Marshal.SizeOf(openFile);
            if (string.IsNullOrEmpty(filter))
            {
                filter = "All Files\0*.*\0\0";
            }
            openFile.filter = filter;

            openFile.file = new string(new char[256]);

            openFile.maxFile      = openFile.file.Length;
            openFile.fileTitle    = new string(new char[256]);
            openFile.maxFileTitle = openFile.fileTitle.Length;
            //string path = Application.streamingAssetsPath;
            path = path.Replace('/', '\\');
            //默认路径
            openFile.initialDir = path;
            //窗口标题
            if (string.IsNullOrEmpty(Title))
            {
                Title = "Open Project";
            }
            openFile.title = Title;

            openFile.defExt = "JPG";                                                         //显示文件的类型
            //注意 一下项目不一定要全选 但是0x00000008项不要缺少
            openFile.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

            if (WindowDll.GetOpenFileName(openFile))
            {
                return(openFile.file);
            }
            return(null);
        }
Example #13
0
    public static void openFileSelect(string title)
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.filter       = "All Files\0*.*\0\0";
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        ofn.initialDir   = UnityEngine.Application.dataPath;//默认路径
        ofn.title        = title;
        //ofn.defExt = "JPG";//显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))
        {
            SELECT_FILE_NAME = ofn.file;
            Debug.Log("Selected file with full path: {0}" + SELECT_FILE_NAME);
        }
    }
Example #14
0
    void PC_openfile()  //打开文件
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.filter       = "Excel files(*.xlsx)|*.xlsx";
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        ofn.initialDir   = UnityEngine.Application.dataPath;                        //默认路径
        ofn.title        = "打开文件";
        ofn.defExt       = "xlsx";                                                  //显示文件的类型
                                                                                    //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))                                         //windows平台下的文件调出窗口
        {
            FileRead(ofn);
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
    }
    /// <summary>
    /// Window打开
    /// </summary>
    public void OpenWindowsPick()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        ofn.initialDir   = UnityEngine.Application.dataPath;//默认路径
        ofn.title        = "Open Project";
        ofn.filter       = "图片文件(*.jpg*.png)\0*.jpg;*.png";
        ofn.defExt       = "JPG";                                                          //显示文件的类型
        ofn.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))
        {
            FilePath = ofn.file;
            LoadPicByUrl(FilePath);
            return;
        }
        CandleShowPhoto();
    }
Example #16
0
    public void UploadTexture(Image image)
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.filter       = "All Files\0*.*\0\0";
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        ofn.initialDir   = UnityEngine.Application.dataPath;                        //默认路径
        ofn.title        = ContentHelper.Read(ContentHelper.SelectHeadText);
        ofn.defExt       = "JPG";                                                   //显示文件的类型
                                                                                    //注意 以下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))
        {
            _uploadTexture = null;
            _uploadSprite  = null;
            StartCoroutine(GetUploadTexture(ofn.file, image));
        }
    }
Example #17
0
    public void OpenFileWin()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = "All Files\0*.*\0\0";

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        //ofn.initialDir = path;
        ofn.initialDir = Application.dataPath + "/../Worlds/";
        //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        ofn.title = "Open Project";

        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
        //此处更改了大部分答案的协程方法,在这里是采用unity的videoplayer.url方法播放视频;
        //而且我认为大部分的其他答案,所给的代码并不全

        Globe.worldPath     = ofn.file;
        Globe.isChooseWorld = true;
        SceneManager.LoadScene("Loading");
    }
Example #18
0
    void PC_openfile2()  //打开文件
    {
        PlayerPrefs.SetString("wordhttp", inputText.GetComponent <InputField>().text);
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);
        //   ofn.filter = "Excel files(*.xlsx)|*.xlsx";
        ofn.file         = new string(new char[256]);
        ofn.maxFile      = ofn.file.Length;
        ofn.fileTitle    = new string(new char[64]);
        ofn.maxFileTitle = ofn.fileTitle.Length;
        ofn.initialDir   = UnityEngine.Application.dataPath;//默认路径
        ofn.title        = "打开文件";
        //   ofn.defExt = "xlsx";//显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
        if (WindowDll.GetOpenFileName(ofn))                                         //windows平台下的文件调出窗口
        {
            StartCoroutine(Android_file_Update(ofn.file));
            //   FileRead(ofn);
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
    }
Example #19
0
    public void ClickButton()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        //ofn.filter = "All Files\0*.*\0\0";


        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;

        ofn.initialDir = UnityEngine.Application.dataPath;//默认路径

        ofn.title = "Open Project";

        ofn.defExt = "OGG";//显示文件的类型

        ofn.filter = "视频文件(*.ogg)\0*.ogg;*.mp4;*.mov;*.avi;";
        //ofn.filter = "音频文件(*.ogg)\0*.ogg;*.wav;*.mp3";
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetOpenFileName(ofn))
        {
            filePath = ofn.file;
            Debug.Log("找到文件了");
            filePath = "file://" + filePath;
            // LoadMusic._instance.Loadmusic(filePath);
            Debug.Log("Selected file with full path:  " + ofn.file);
        }
    }
Example #20
0
        /// <summary>打开文件选取对话框</summary>
        public static void OpenFileDialog(Action <string> onFileOpen)
        {
            //Debug.Log("openDialog");
            OpenFileName ofn = new OpenFileName();

            ofn.structSize = System.Runtime.InteropServices.Marshal.SizeOf(ofn);

            ofn.filter = "All Files\0*.*\0\0";

            ofn.file = new string(new char[256]);

            ofn.maxFile = ofn.file.Length;

            ofn.fileTitle = new string(new char[64]);

            ofn.maxFileTitle = ofn.fileTitle.Length;

            ofn.initialDir = UnityEngine.Application.dataPath;//默认路径

            ofn.title = "Open Project";

            ofn.defExt = "JPG";                                                         //显示文件的类型
            //注意 一下项目不一定要全选 但是0x00000008项不要缺少
            ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

            if (WindowDll.GetOpenFileName(ofn))
            {
                //Debug.Log("Selected file with full path: {0}" + ofn.file);

                //this.pathOver(ofn.file);
                if (onFileOpen != null)
                {
                    onFileOpen(ofn.file);
                }
            }
        }
Example #21
0
    private void OnGUI()
    {
        GUI.skin.label.normal.textColor = new Color(0, 0, 0);

        // Find file path and open file
        if (GUI.Button(new Rect(20, 20, 160, 20), "Open Cap File"))
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize = Marshal.SizeOf(ofn);

            ofn.filter = "All Files\0*.*\0\0";

            ofn.file = new string(new char[256]);

            ofn.maxFile = ofn.file.Length;

            ofn.fileTitle = new string(new char[64]);

            ofn.maxFileTitle = ofn.fileTitle.Length;
            string path = Application.streamingAssetsPath;
            path           = path.Replace('/', '\\');
            ofn.initialDir = m_path;
            ofn.title      = "Open Project";
            ofn.defExt     = "txt";
            ofn.flags      = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

            if (WindowDll.GetOpenFileName(ofn))
            {
                if (t_reader != null)
                {
                    t_reader.Close();
                    t_reader.Dispose();
                }
                index = 0;

                t_info = new FileInfo(ofn.file);
                if (!t_info.Exists)
                {
                    print("File not found");
                }
                else
                {
                    t_reader = null;
                    try
                    {
                        t_reader    = File.OpenText(ofn.file);
                        m_initialed = false;
                    }
                    catch
                    {
                        print("Read error!");
                        return;
                    }
                }
            }
        }

        GUI.Label(new Rect(20, 0, 160, 20), state);
        GUI.Label(new Rect(50, 0, 160, 20), state2);
        GUI.Label(new Rect(80, 0, 160, 20), state3);
        GUI.Label(new Rect(150, 0, 160, 20), state4);

        int       pos     = 160;
        int       count   = 0;
        ArrayList window1 = new ArrayList();

        foreach (string str in q1)
        {
            //GUI.Label(new Rect(20, pos + count * 20, 160, 20), str);
            window1.Add(str);
            count++;
        }
        if (window1[5].Equals("shoot"))
        {
            if (window1.Contains("ready"))
            {
                GUI.Label(new Rect(20, 100, 160, 20), "Press shoot");
                if (!window1.Equals(window1_last))
                {
                    SimKey.SendMessage("ReceiveControl", "Shoot", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        if (window1[3].Equals("ready"))
        {
            if (!window1.Contains("shoot"))
            {
                GUI.Label(new Rect(20, 100, 160, 20), "Press fake");
                if (!window1.Equals(window1_last))
                {
                    SimKey.SendMessage("ReceiveControl", "Fake", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        window1_last = window1;


        pos   = 160;
        count = 0;
        ArrayList window2 = new ArrayList();

        foreach (string str in q2)
        {
            //GUI.Label(new Rect(50, pos + count * 20, 160, 20), str);
            window2.Add(str);
            count++;
        }
        if (window2[3].Equals("catch"))
        {
            if (window2[4].Equals("hold") || window2[5].Equals("hold"))
            {
                GUI.Label(new Rect(20, 120, 160, 20), "Press pass");
                if (!window2.Equals(window2_last))
                {
                    SimKey.SendMessage("ReceiveControl", "Pass", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        window2_last = window2;


        pos   = 160;
        count = 0;
        ArrayList window3 = new ArrayList();

        foreach (string str in q3)
        {
            //GUI.Label(new Rect(80, pos + count * 20, 160, 20), str);
            window3.Add(str);
            count++;
        }
        if (window3[3].Equals("HandUp"))
        {
            if (window3[4].Equals("HandDown") || window3[5].Equals("HandDown") && (!window1.Contains("shoot")))
            {
                GUI.Label(new Rect(20, 150, 160, 20), "Press block");
                if (!window3.Equals(window3_last))
                {
                    SimKey.SendMessage("ReceiveControl", "Block", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        window3_last = window3;


        pos   = 160;
        count = 0;
        ArrayList window4 = new ArrayList();

        foreach (string str in q4)
        {
            //GUI.Label(new Rect(150, pos + count * 20, 160, 20), str);
            window4.Add(str);
            count++;
        }
        if (window4[3].Equals("Fancy1"))
        {
            if (window4.Contains("Fancy2"))
            {
                GUI.Label(new Rect(20, 180, 160, 20), "Press fancy");
                if (state4_reset)
                {
                    state4_reset = false;
                    if (!window4.Equals(window4_last))
                    {
                        SimKey.SendMessage("ReceiveControl", "Fancy", SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
        }
        else if (!(window4.Contains("Fancy1") || window4.Contains("Fancy2")))
        {
            state4_reset = true;
        }
        window4_last = window4;
    }
    public static string[] OpenMutiFileDialog(AssetFileType fileType, string dialogTitle = "选择多个文件", string initPath = null)
    {
        const int MAX_FILE_LENGTH = 2048;

        OpenFileName ofn = InitDialogCommon(dialogTitle, initPath);

        GetFliter(fileType, out ofn.filter, out ofn.defExt);
        ofn.flags = (int)(
            OpenFileNameFlags.OFN_EXPLORER
            | OpenFileNameFlags.OFN_FILEMUSTEXIST
            | OpenFileNameFlags.OFN_PATHMUSTEXIST
            | OpenFileNameFlags.OFN_NOCHANGEDIR
            | OpenFileNameFlags.OFN_ALLOWMULTISELECT
            );

        // Initialize buffer with NULL bytes
        for (int i = 0; i < MAX_FILE_LENGTH * Marshal.SystemDefaultCharSize; i++)
        {
            Marshal.WriteByte(ofn.file, i, 0);
        }

        if (WindowDll.GetOpenFileName(ofn))
        {
            List <string> selectedFilesList = new List <string>();

            IntPtr filePointer = ofn.file;
            long   pointer     = (long)filePointer;
            string file        = Marshal.PtrToStringAuto(filePointer);

            // Retrieve file names
            while (file.Length > 0)
            {
                selectedFilesList.Add(file);

                pointer    += file.Length * Marshal.SystemDefaultCharSize + Marshal.SystemDefaultCharSize;
                filePointer = (IntPtr)pointer;
                file        = Marshal.PtrToStringAuto(filePointer);
            }

            if (selectedFilesList.Count == 1)
            {
                // Only one file selected with full path
                Marshal.FreeHGlobal(ofn.file);
                return(selectedFilesList.ToArray());
            }
            else
            {
                // Multiple files selected, add directory
                string[] selectedFiles = new string[selectedFilesList.Count - 1];

                for (int i = 0; i < selectedFiles.Length; i++)
                {
                    selectedFiles[i] = selectedFilesList[0];

                    if (!selectedFiles[i].EndsWith("\\"))
                    {
                        selectedFiles[i] += "\\";
                    }

                    selectedFiles[i] += selectedFilesList[i + 1];
                }

                // Return selected files
                Marshal.FreeHGlobal(ofn.file);
                return(selectedFiles);
            }
        }
        else
        {
            // "Cancel" pressed
            Marshal.FreeHGlobal(ofn.file);
            return(null);
        }
    }
Example #23
0
    private void OnGUI()
    {
        //GUI.BeginScrollView(new Rect(5, 5, 600, 450), Vector2.one, new Rect(5, 5, 300, 100));
        GUI.Label(new Rect(5, 5, 100, 20), "Python.exe path:");
        GUI.TextField(new Rect(115, 5, 400, 20), pythonexePath);
        if (GUI.Button(new Rect(523, 5, 80, 20), "..."))
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize   = System.Runtime.InteropServices.Marshal.SizeOf(ofn);
            ofn.filter       = "EXE文件(*.exe)\0*.exe";
            ofn.file         = new string(new char[256]);
            ofn.maxFile      = ofn.file.Length;
            ofn.fileTitle    = new string(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;
            ofn.title        = "Select Python.exe";
            ofn.defExt       = "EXE";
            ofn.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;

            if (WindowDll.GetOpenFileName(ofn))
            {
                pythonexePath = ofn.file;
                PlayerPrefs.SetString("pythonexe", ofn.file);
                Debug.Log(ofn.file);
            }
        }
        GUI.Label(new Rect(5, 30, 140, 20), "Excute python file path:");
        GUI.TextField(new Rect(155, 30, 360, 20), pythonFilePath);
        if (GUI.Button(new Rect(523, 30, 80, 20), "..."))
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize   = System.Runtime.InteropServices.Marshal.SizeOf(ofn);
            ofn.filter       = "Python文件(*.py)\0*.py";
            ofn.file         = new string(new char[256]);
            ofn.maxFile      = ofn.file.Length;
            ofn.fileTitle    = new string(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;
            ofn.title        = "Select Python File";
            ofn.defExt       = "py";
            ofn.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;

            if (WindowDll.GetOpenFileName(ofn))
            {
                pythonFilePath = ofn.file;
                PlayerPrefs.SetString("pythonfile", ofn.file);
                Debug.Log(ofn.file);
            }
        }
        if (GUI.Button(new Rect(260, 60, 160, 40), "create python model"))
        {
            string path = Path.Combine(Path.GetDirectoryName(pythonFilePath), "Py2Unity.py");
            if (File.Exists(path))
            {
                Debug.LogWarning("python model has been created allready!");
            }
            else
            {
                FileInfo     fileInfo = new FileInfo(path);
                StreamWriter sw       = fileInfo.CreateText();
                sw.WriteLine("import socket");
                sw.WriteLine("import sys");
                sw.WriteLine();
                sw.WriteLine("class Py2Unity:");
                sw.WriteLine("    def __init__(self):");
                sw.WriteLine("        self.__conn = self.__Connect()");
                sw.WriteLine("    def SendToUnity(self,data):");
                sw.WriteLine("        self.__conn.sendall(bytes(str(data),encoding='utf-8'))");
                sw.WriteLine();
                sw.WriteLine("    def RecFromUnity(self):");
                sw.WriteLine("        data = self.__conn.recv(1024)");
                sw.WriteLine("        if data == \"exit\":");
                sw.WriteLine("            sys.exit()");
                sw.WriteLine("        return data");
                sw.WriteLine();
                sw.WriteLine("    def __Connect(self):");
                sw.WriteLine("        s = socket.socket()");
                sw.WriteLine("        s.bind((\"127.0.0.1\",7758))");
                sw.WriteLine("        s.listen(1)");
                sw.WriteLine("        print(\"wait for connect...\")");
                sw.WriteLine("        return s.accept()[0]");
                sw.Flush();
                sw.Close();
                Debug.Log("created!");
            }
        }

        GUI.Label(new Rect(5, 110, 2000, 20), "click this button to create python model,you will find a python file named \"Py2Unity.py\" in your select python file folder");

        GUI.Label(new Rect(100, 150, 100, 20), "Unity Example");
        GUI.Label(new Rect(440, 150, 100, 20), "Python Example");
        GUI.TextArea(new Rect(30, 180, 250, 400), unityExample);
        GUI.TextArea(new Rect(350, 180, 250, 400), pythonExample);
    }