3using System.Collections;
4using System.Collections.Generic;
19 private Stack<string> back =
new Stack<string>();
20 private Stack<string> forward =
new Stack<string>();
53 private bool _isFileBrowser =
false;
58 private string _filePattern =
"";
91 private bool mInitialized =
false;
105 upButton.onClick.RemoveAllListeners();
115 UpdateNavButtonInteractibility();
127 if( ValidDir(directory) )
147#if UNITY_WEBGL || USENETWORK
148 string[] children =
null;
153 UpdateNavButtonInteractibility();
167 for(
int n = 0; n < children.Length; n++)
186#if UNITY_WEBGL || USENETWORK
192 children = CourseListLogic(children, courses, ref i);
198 children = CourseListLogic(children, courses, ref i);
204 children = CourseListLogic(children, courses, ref i);
213 children = NetworkManager.instance.CourseArrayToNameList(courses, out var ids).ToArray();
214 for(int n = 0; n < children.Length; n++)
216 pb_SaveDialogButton button = GameObject.Instantiate(rowButtonPrefab);
217 button.SetDelegateAndPath(SetFile, children[n]);
219 pb_GUIStyleApplier style = button.GetComponent<pb_GUIStyleApplier>();
220 style.style = i++ % 2 == 0 ? evenRowStyle : oddRowStyle;
223 button.transform.SetParent(scrollContent.transform);
238#if UNITY_WEBGL || USENETWORK
239 children =
new string[0];
241 var fdd = FindObjectOfType<FileDragAndDrop>();
242 var t = fdd.paretnObject.transform;
243 var allModel = t.GetComponentsInChildren<
UploadedFile>(
true);
245 foreach (var uploadedFile
in allModel)
247 if (uploadedFile.fileName.EndsWith(endswith))
249 children = children.Concat(
new[] {uploadedFile.fileName}).ToArray();
257 for(
int n = 0; n < children.Length; n++)
277 for (
int n = 0; n < children.Length; n++)
279 pb_SaveDialogButton button = GameObject.Instantiate(rowButtonPrefab);
280 button.SetDelegateAndPath(SetFile, children[n]);
284 button.transform.GetChild(1).GetComponent<
Button>().onClick.AddListener(() =>
286 Debug.Log(courses.courses[index].id);
287 Debug.Log(courses.courses[index].name);
289 courses.courses[index].id,
292 Debug.Log($
"course {courses.courses[index].name}, deleted successfuly");
293 UpdateDirectoryContents();
296 $
"Do you want to delete course '{children[index]}'?");
301 Destroy(button.transform.GetChild(1));
304 pb_GUIStyleApplier style = button.GetComponent<pb_GUIStyleApplier>();
305 style.style = i++ % 2 == 0 ? evenRowStyle : oddRowStyle;
308 button.transform.SetParent(scrollContent.transform);
311 scrollContent.SetActive(
true);
315 public static IEnumerable<string>
GetFiles(
string path,
316 string[] searchPatterns,
317 SearchOption searchOption = SearchOption.TopDirectoryOnly)
319 return searchPatterns.AsParallel()
320 .SelectMany(searchPattern =>
321 Directory.EnumerateFiles(path, searchPattern, searchOption));
324 private void ClearScrollRect()
326 foreach(Transform t
in scrollContent.transform)
327 pb_ObjectUtility.Destroy(t.gameObject);
330 private bool ValidDir(
string dir)
332 return !
string.IsNullOrEmpty(dir) &&
Directory.Exists(dir);
335 private void UpdateNavButtonInteractibility()
337 backButton.interactable = back.Count > 0;
338 forwardButton.interactable = forward.Count > 0;
339 upButton.interactable = ValidDir(currentDirectory) &&
Directory.GetParent(currentDirectory) !=
null;
344 DirectoryInfo parent =
Directory.GetParent(currentDirectory);
349 SetDirectory(parent.FullName);
354 fileInputField.text = Path.GetFileName(path);
365 forward.Push(currentDirectory);
366 currentDirectory = back.Pop();
367 UpdateDirectoryContents();
373 if(forward.Count > 0)
375 back.Push(currentDirectory);
376 currentDirectory = forward.Pop();
377 UpdateDirectoryContents();
400 OnSave( currentDirectory +
"/" + GetFilePath() );
402 Debug.LogWarning(
"File dialog was dismissed by user but no callback is registered to perform the action!");
410 private string GetFilePath()
412 string path = fileInputField.text;
UnityEngine.UI.Button Button
bool limitToCourses
Only show training files.
pb_GUIStyle oddRowStyle
pb_GUIStyle to apply to odd and even rows.
Callback< string > OnSave
InputField directoryCrumbsField
The input field that shows the directory path.
void OpenParentDirectory()
GameObject scrollContent
Where to put current directory folder buttons.
string currentDirectory
The directory currently being inspected.
void SetFile(string path)
pb_SaveDialogButton rowButtonPrefab
The prefab to populate scrollview contents with.
Button backButton
Buttons to navigate folder structures.
InputField fileInputField
The input field that allows user to type in file or folder name.
Button saveButton
Save and cancel buttons. onClick delegates will automatically be added by this script.
string filePattern
If isFileBrowser is true, this string my be used to filter file results (see https://msdn....
Callback OnCancel
Called if the user cancels this action.
void AddOnCancelListener(Callback listener)
void UpdateDirectoryContents()
CourseType manualLogonCourseType
void AddOnSaveListener(Callback< string > listener)
static IEnumerable< string > GetFiles(string path, string[] searchPatterns, SearchOption searchOption=SearchOption.TopDirectoryOnly)
void SetDirectory(string directory)
SavedUser.CourseType CourseType