using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using UnityEngine.UI; using System; using System.Threading; using System.Linq; public class WindowFormsShowModelPath : MonoBehaviour { string str_path = ""; string modelname = ""; private void Start() { OopsWindowsThreadStart(); System.Windows.Forms.MessageBox.Show("start..."); ThreadRunning = false; } private void Update() { if (Input.GetKeyDown(KeyCode.P)) { OopsWindowsThreadStart(); System.Windows.Forms.OpenFileDialog Dialog = new System.Windows.Forms.OpenFileDialog(); Dialog.Filter = "文件(*.FBX)|*.FBX"; if (Dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { str_path = Path.GetDirectoryName(Dialog.FileName); modelname = Path.GetFileNameWithoutExtension(Dialog.FileName); System.Windows.Forms.MessageBox.Show(str_path + "\\" + modelname); } else { str_path = ""; modelname = ""; System.Windows.Forms.MessageBox.Show(null...); } ThreadRunning = false; } } #region Close Window Oops private System.Threading.Thread CloseOops; private bool ThreadRunning = true; private void OopsWindowsThreadStart() { CloseOops = new System.Threading.Thread(ClearOopsWindows) { IsBackground = true }; ThreadRunning = true; CloseOops.Start(); } private void ClearOopsWindows() { while (ThreadRunning) { FindAndCloseWindow(); } } [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_CLOSE = 0xF060; public static void FindAndCloseWindow() { IntPtr lHwnd = FindWindow(null, "Oops"); if (lHwnd != IntPtr.Zero) { SendMessage(lHwnd, WM_SYSCOMMAND, SC_CLOSE, 0); } } #endregion }
支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)