コード例 #1
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);
        }
    }
コード例 #2
0
    public void Openfile()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        //ofn.filter = "All Files\0*.*\0\0";
        ofn.filter = "音频文件(*.WAV*.MP3*.OGG)\0*.WAV;*.MP3;*.OGG";
        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 = UnityEngine.Application.streamingAssetsPath;

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

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

        if (WindowDll.GetOpenFileName1(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
    }
コード例 #3
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
        }
    }
コード例 #4
0
ファイル: readImage.cs プロジェクト: yansanbai/geospace
    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));
        }
    }
コード例 #5
0
ファイル: OpenFile.cs プロジェクト: azuse/waifuex
    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("\\", "/");
        }
    }
コード例 #6
0
ファイル: OpenFile.cs プロジェクト: foozc/ScriptArchive
    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);
            }
        }
    }
コード例 #7
0
    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));
            }
        }
    }
コード例 #8
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);
        }
    }
コード例 #9
0
ファイル: FileFrom.cs プロジェクト: yijiahe/peidiansuo
    static string SaveFile(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.GetSaveFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
        return(ofn.file);
    }
コード例 #10
0
    public void Openfile(Text text)
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        //ofn.filter = "All Files\0*.*\0\0";
        //.mov, .mpg, .mpeg, .mp4, .avi, .asf
        ofn.filter = "视频文件(*.mov *.mpg *.mpeg *.mp4 *avi *asf)";
        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 = UnityEngine.Application.streamingAssetsPath;

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

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

        if (WindowDll.GetOpenFileName1(ofn))
        {
            //加载图片到panle
            StartCoroutine(WaitLoad(ofn.file, text));
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
    }
コード例 #11
0
ファイル: OpenFile.cs プロジェクト: Sage-SQ/LoadDllTool
    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);
        }
    }
コード例 #12
0
        private void Update()
        {
            if (Input.GetKey(KeyCode.Z) && Input.GetKeyDown(KeyCode.O))
            {
                string[] strs = WindowDll.ShowOpenFileDialog("打开Excel文件", "Excel files (*.xlsx)|*.xlsx", false);
                if (strs != null)
                {
                    Read(strs[0]);
                }
            }

            //if (Input.GetKey(KeyCode.Z) && Input.GetKeyDown(KeyCode.S))
            //{
            //    string path = WindowDll.ShowSaveFileDialog("打开Excel文件", "Excel files (*.xlsx|*.xlsx", ".xlsx");
            //    if(path!=null)
            //    {
            //        Write(path);
            //    }
            //}

            //if (Input.GetKey(KeyCode.O) && Input.GetKeyDown(KeyCode.P))
            //{
            //    List<Node> allNodes = VRCattleDataBase.instance.GetAllNode();
            //    for(int i = 0; i < allNodes.Count; i++)
            //    {
            //        Debug.Log(allNodes[i].ID);
            //    }
            //}
        }
コード例 #13
0
    public void saveData()
    {
        if (!EditorSelectArea.Instance.hasData())
        {
            return;
        }
        SelectAreaParams saveParas = EditorSelectArea.Instance.save();

        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   = Application.dataPath + "Assets/Resources/Data/Preform";
        ofn.title        = "载入文件";
        FileInfo fi;

        if (WindowDll.GetSaveFileName1(ofn))
        {
            fi = new FileInfo(ofn.file);
        }
        else
        {
            return;
        }

        if (!fi.Directory.Exists)
        {
            fi.Directory.Create();
        }
        _fs          = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
        _fs.Position = 0;
        byte[] lenght = new byte[4];
        Serialization.WriteIntToByteArr(lenght, saveParas.blockTypes.Length);
        _fs.Write(lenght, 0, lenght.Length);
        byte[] width  = new byte[4];
        byte[] depth  = new byte[4];
        byte[] height = new byte[4];
        Serialization.WriteIntToByteArr(width, saveParas.Width);
        Serialization.WriteIntToByteArr(depth, saveParas.Depth);
        Serialization.WriteIntToByteArr(height, saveParas.Height);
        _fs.Write(width, 0, width.Length);
        _fs.Write(depth, 0, depth.Length);
        _fs.Write(height, 0, height.Length);
        _fs.Write(saveParas.blockTypes, 0, saveParas.blockTypes.Length);
        _fs.Write(saveParas.extendIds, 0, saveParas.extendIds.Length);
        _fs.Close();
        _fs.Dispose();
        _fs = null;
    }
コード例 #14
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);
    }
コード例 #15
0
    public static string SaveFileDialog(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.GetSaveFileName(ofn))
        {
            IntPtr filePointer = ofn.file;
            string file        = Marshal.PtrToStringAuto(filePointer);
            return(file);
        }
        return(null);
    }
コード例 #16
0
ファイル: GetHelpFile.cs プロジェクト: PgGames/Attribution
        /// <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);
        }
コード例 #17
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);
        }
    }
コード例 #18
0
ファイル: ExcelScripts.cs プロジェクト: XFSZ/unity3d_txt
    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);
        }
    }
コード例 #19
0
ファイル: OpenFile.cs プロジェクト: Heavenfather/DailyFood
    /// <summary>
    /// 打开window面板选择图片文件并且copy图片到指定目录下
    /// </summary>
    /// <param name="saveName"></param>
    /// <param name="callback"></param>
    public void OpenDialogAndCopyImage(string saveName, Action <UnityEngine.Object> callback)
    {
        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 = "";

        if (string.IsNullOrEmpty(_lastSelectPath))
        {
            path = Application.dataPath;
        }
        else
        {
            path = _lastSelectPath;
        }
        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.GetFile(ofn))
        {
            //记录上次选择的路径
            _lastSelectPath = ofn.file;
            _lastSelectPath = _lastSelectPath.Replace('\\', '/');
            int index = _lastSelectPath.LastIndexOf('/');
            _lastSelectPath = _lastSelectPath.Remove(index);
            StartCoroutine(LoadAndCopyImage(ofn.file, saveName, callback));
        }
    }
コード例 #20
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));
        }
    }
コード例 #21
0
    /// <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();
    }
コード例 #22
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");
    }
コード例 #23
0
    public void SaveFileWin(string fileContent)
    {
        WindowsOpenFile wof = new WindowsOpenFile();

        wof.structSize = Marshal.SizeOf(wof);

        wof.filter = "All Files\0*.*\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 = "json";//显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        wof.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetSaveFileName(wof))
        {
            Debug.Log("SaveFileWin = " + wof.file);
            FileStream fileStream = new FileStream(wof.file, FileMode.Create);
            byte[]     bts        = new UTF8Encoding().GetBytes(fileContent);
            fileStream.Write(bts, 0, bts.Length);
            fileStream.Close();
            //GameReadExcel(wof.file);
        }
    }
コード例 #24
0
ファイル: turntosence.cs プロジェクト: XFSZ/unity3d_txt
    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);
        }
    }
コード例 #25
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);
        }
    }
コード例 #26
0
ファイル: SongeUtil.cs プロジェクト: SongE1989/TradeGame
        /// <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);
                }
            }
        }
コード例 #27
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;
    }
コード例 #28
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);
    }
コード例 #29
0
    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);
        }
    }