/// <summary> /// 开启一个文件与文件夹选择窗体 /// </summary> /// <param name="fileSystemInfo">指向的文件系统信息,默认指向当前文件夹</param> /// <returns>窗体实例</returns> public static FileAndDirectoryWindow OpenWindow(FileSystemInfo fileSystemInfo = null) { if (fileSystemInfo is null) { fileSystemInfo = new DirectoryInfo(Environment.CurrentDirectory); } // 当一个文件不存在时,不要试图拿取文件夹 if (!fileSystemInfo.Exists) { fileSystemInfo = null; } GameObject go = GameSystemData.Instance.InstantiateGo(nameof(FileAndDirectoryWindow)); FileAndDirectoryWindow window = null; foreach (UpdatableComponent updatableComponent in go.GetComponents <UpdatableComponent>()) { if (typeof(FileAndDirectoryWindow).FullName.Equals(updatableComponent.ILTypeFullName)) { window = updatableComponent.InstanceObject as FileAndDirectoryWindow; break; } } if (window is null) { throw new NullReferenceException($"Not found {nameof(FileAndDirectoryWindow)} in {nameof(UpdatableComponent)}."); } window.SelectedFileSystemInfo = fileSystemInfo; window.RefreshUI(); return(window); }
public void OnClickLoadFontButton() { Debug.Log($"{nameof(MenuWindow)}.{nameof(OnClickLoadFontButton)}"); string latestBMPFontPath = Setting.Instance.LatestBMPFontPath; FileInfo fontFileInfo = null; if (!string.IsNullOrWhiteSpace(latestBMPFontPath)) { fontFileInfo = new FileInfo(latestBMPFontPath); } FileAndDirectoryWindow window = FileAndDirectoryWindow.OpenWindow(fontFileInfo); window.Title = "读取一个 *.fnt 文件"; window.OKCallback += (_) => { string fontPath = window.SelectedFileSystemInfo.FullName; Debug.Log($"{window.SelectedFileSystemInfo.GetType().Name} : {fontPath}"); Setting.Instance.LatestBMPFontPath = fontPath; Setting.Instance.SaveOutPlayerPrefs(); GameSystemData.Instance.Font?.Dispose(); BMPFont font = new BMPFont(); font.LoadFontFromFile(window.SelectedFileSystemInfo.FullName); font.UseIt(); }; }