Implement preset path in file dialog.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -27,6 +28,12 @@ namespace Cryville.Common.Unity {
|
|||||||
set { m_filter = value; }
|
set { m_filter = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||||
|
public Dictionary<string, string> PresetPaths {
|
||||||
|
get { return m_presetPaths; }
|
||||||
|
set { m_presetPaths = value; }
|
||||||
|
}
|
||||||
|
|
||||||
GameObject prefabButton;
|
GameObject prefabButton;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
@@ -68,7 +75,7 @@ namespace Cryville.Common.Unity {
|
|||||||
void ChangeDirectory(DirectoryInfo s) {
|
void ChangeDirectory(DirectoryInfo s) {
|
||||||
CurrentDirectory = s;
|
CurrentDirectory = s;
|
||||||
UpdateGUI(1);
|
UpdateGUI(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectFile(string s) {
|
void SelectFile(string s) {
|
||||||
fileName = s;
|
fileName = s;
|
||||||
@@ -79,23 +86,33 @@ namespace Cryville.Common.Unity {
|
|||||||
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
||||||
|
|
||||||
if (depth <= 0) {
|
if (depth <= 0) {
|
||||||
CallHelper.Purge(drives);
|
CallHelper.Purge(drives);
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
var dl = Directory.GetLogicalDrives();
|
var dl = Directory.GetLogicalDrives();
|
||||||
foreach (string d in dl) {
|
foreach (string d in dl) {
|
||||||
GameObject btn = Instantiate(prefabButton);
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d;
|
btn.GetComponentInChildren<Text>().text = d;
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(d)));
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(d)));
|
||||||
btn.transform.SetParent(drives, false);
|
btn.transform.SetParent(drives, false);
|
||||||
}
|
}
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
GameObject sbtn = GameObject.Instantiate<GameObject>(prefabButton);
|
GameObject sbtn = GameObject.Instantiate<GameObject>(prefabButton);
|
||||||
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
||||||
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged(new DirectoryInfo(androidStorage)));
|
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged(new DirectoryInfo(androidStorage)));
|
||||||
sbtn.transform.SetParent(drives, false);
|
sbtn.transform.SetParent(drives, false);
|
||||||
#else
|
#else
|
||||||
#error No update GUI logic
|
#error No update GUI logic
|
||||||
#endif
|
#endif
|
||||||
|
foreach (var p in m_presetPaths) {
|
||||||
|
var d = new DirectoryInfo(p.Value);
|
||||||
|
if (d.Exists) {
|
||||||
|
GameObject btn = Instantiate(prefabButton);
|
||||||
|
btn.GetComponentInChildren<Text>().text = p.Key;
|
||||||
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(d));
|
||||||
|
btn.transform.SetParent(drives, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CallHelper.Purge(dirs);
|
CallHelper.Purge(dirs);
|
||||||
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
||||||
@@ -117,10 +134,10 @@ namespace Cryville.Common.Unity {
|
|||||||
foreach (string ext in m_filter) {
|
foreach (string ext in m_filter) {
|
||||||
if (d.Extension == ext) {
|
if (d.Extension == ext) {
|
||||||
GameObject btn = Instantiate(prefabButton);
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
||||||
var ts = d.FullName;
|
var ts = d.FullName;
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => SelectFile(ts));
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => SelectFile(ts));
|
||||||
btn.transform.SetParent(files, false);
|
btn.transform.SetParent(files, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Cryville.Crtr.Browsing {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
public interface IResourceManager<T> {
|
public interface IResourceManager<T> {
|
||||||
string[] CurrentDirectory { get; }
|
string[] CurrentDirectory { get; }
|
||||||
int ChangeDirectory(string[] dir);
|
int ChangeDirectory(string[] dir);
|
||||||
@@ -10,5 +12,6 @@
|
|||||||
|
|
||||||
bool ImportItemFrom(string path);
|
bool ImportItemFrom(string path);
|
||||||
string[] GetSupportedFormats();
|
string[] GetSupportedFormats();
|
||||||
|
Dictionary<string, string> GetPresetPaths();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
static readonly Dictionary<string, List<ResourceConverter>> converters
|
static readonly Dictionary<string, List<ResourceConverter>> converters
|
||||||
= new Dictionary<string, List<ResourceConverter>>();
|
= new Dictionary<string, List<ResourceConverter>>();
|
||||||
|
static readonly Dictionary<string, string> localRes
|
||||||
|
= new Dictionary<string, string>();
|
||||||
|
|
||||||
public LegacyResourceManager(string rootPath) {
|
public LegacyResourceManager(string rootPath) {
|
||||||
_rootPath = rootPath;
|
_rootPath = rootPath;
|
||||||
@@ -35,14 +37,23 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
if (fs == null) continue;
|
if (fs == null) continue;
|
||||||
foreach (var f in fs) {
|
foreach (var f in fs) {
|
||||||
if (f == null) continue;
|
if (f == null) continue;
|
||||||
if (!converters.ContainsKey(f))
|
if (!converters.ContainsKey(f))
|
||||||
converters.Add(f, new List<ResourceConverter> { c });
|
converters.Add(f, new List<ResourceConverter> { c });
|
||||||
else converters[f].Add(c);
|
else converters[f].Add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
|
var fs2 = ext.GetResourceFinders();
|
||||||
|
if (fs2 != null) {
|
||||||
|
foreach (var f in fs2) {
|
||||||
|
var name = f.Name;
|
||||||
|
var path = f.GetRootPath();
|
||||||
|
if (name != null && path != null)
|
||||||
|
localRes.Add(name, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
|
||||||
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
|
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
|
||||||
}
|
}
|
||||||
@@ -211,5 +222,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public string[] GetSupportedFormats() {
|
public string[] GetSupportedFormats() {
|
||||||
return converters.Keys.ToArray();
|
return converters.Keys.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, string> GetPresetPaths() {
|
||||||
|
return localRes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||||
_dialog.gameObject.SetActive(false);
|
_dialog.gameObject.SetActive(false);
|
||||||
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
||||||
|
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
|
||||||
_dialog.OnClose += OnAddDialogClosed;
|
_dialog.OnClose += OnAddDialogClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user