OpenFileName.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Runtime.InteropServices;
  5. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  6. public class OpenDialogFile
  7. {
  8. public int structSize = 0;
  9. public IntPtr dlgOwner = IntPtr.Zero;
  10. public IntPtr instance = IntPtr.Zero;
  11. public String filter = null;
  12. public String customFilter = null;
  13. public int maxCustFilter = 0;
  14. public int filterIndex = 0;
  15. public String file = null;
  16. public int maxFile = 0;
  17. public String fileTitle = null;
  18. public int maxFileTitle = 0;
  19. public String initialDir = null;
  20. public String title = null;
  21. public int flags = 0;
  22. public short fileOffset = 0;
  23. public short fileExtension = 0;
  24. public String defExt = null;
  25. public IntPtr custData = IntPtr.Zero;
  26. public IntPtr hook = IntPtr.Zero;
  27. public String templateName = null;
  28. public IntPtr reservedPtr = IntPtr.Zero;
  29. public int reservedInt = 0;
  30. public int flagsEx = 0;
  31. }
  32. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  33. public class OpenDialogDir
  34. {
  35. public IntPtr hwndOwner = IntPtr.Zero;
  36. public IntPtr pidlRoot = IntPtr.Zero;
  37. public String pszDisplayName = null;
  38. public String lpszTitle = null;
  39. public UInt32 ulFlags = 0;
  40. public IntPtr lpfn = IntPtr.Zero;
  41. public IntPtr lParam = IntPtr.Zero;
  42. public int iImage = 0;
  43. }
  44. public class DllOpenFileDialog
  45. {
  46. [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
  47. public static extern bool GetOpenFileName([In, Out] OpenDialogFile ofn);
  48. [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
  49. public static extern bool GetSaveFileName([In, Out] OpenDialogFile ofn);
  50. [DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
  51. public static extern IntPtr SHBrowseForFolder([In, Out] OpenDialogDir ofn);
  52. [DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
  53. public static extern bool SHGetPathFromIDList([In] IntPtr pidl, [In, Out] char[] fileName);
  54. }