├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── TimeManager.asset ├── AudioManager.asset ├── EditorSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── DynamicsManager.asset ├── GraphicsSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset ├── Physics2DSettings.asset └── UnityConnectSettings.asset ├── UnityPackageManager └── manifest.json ├── Assets ├── Example │ ├── MainScene.unity │ └── MainScene.unity.meta ├── Resources │ ├── FileBrowser │ │ ├── drive.png │ │ ├── file.png │ │ ├── folder.png │ │ ├── BasePanel.prefab │ │ ├── FileBrowser.prefab │ │ ├── GMessageBox.prefab │ │ ├── GMessageBox.prefab.meta │ │ ├── BasePanel.prefab.meta │ │ ├── FileBrowser.prefab.meta │ │ ├── file.png.meta │ │ ├── drive.png.meta │ │ └── folder.png.meta │ └── FileBrowser.meta ├── Scripts │ ├── GFile.cs │ ├── GFolder.cs │ ├── GDrive.cs │ ├── Browser.cs.meta │ ├── GBase.cs.meta │ ├── GDrive.cs.meta │ ├── GFile.cs.meta │ ├── GFolder.cs.meta │ ├── Utilities.cs.meta │ ├── BrowserDrive.cs.meta │ ├── BrowserFile.cs.meta │ ├── GComponent.cs.meta │ ├── GFileBrowser.cs.meta │ ├── MainController.cs.meta │ ├── SystemCalls.cs.meta │ ├── UINavigator.cs.meta │ ├── UIClickListener.cs.meta │ ├── UIWindowMoveable.cs.meta │ ├── GBase.cs │ ├── UIWindowMoveable.cs │ ├── BrowserDrive.cs │ ├── GComponent.cs │ ├── UIClickListener.cs │ ├── Utilities.cs │ ├── Browser.cs │ ├── SystemCalls.cs │ ├── MainController.cs │ ├── BrowserFile.cs │ ├── GFileBrowser.cs │ └── UINavigator.cs ├── Example.meta ├── Plugins.meta ├── Resources.meta ├── Scripts.meta ├── TEST.cs.meta └── TEST.cs ├── .gitignore ├── .vscode └── launch.json ├── LICENSE ├── README.md └── .gitattributes /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2017.3.1f1 2 | -------------------------------------------------------------------------------- /UnityPackageManager/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | } 4 | } 5 | -------------------------------------------------------------------------------- /Assets/Example/MainScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Example/MainScene.unity -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/drive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/drive.png -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/file.png -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/folder.png -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/BasePanel.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/BasePanel.prefab -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/FileBrowser.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/FileBrowser.prefab -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/GMessageBox.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltraWelfare/GFileBrowser/HEAD/Assets/Resources/FileBrowser/GMessageBox.prefab -------------------------------------------------------------------------------- /Assets/Example/MainScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 146ed470673b70b48ba341c392e9607e 3 | timeCreated: 1476967274 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/GFile.cs: -------------------------------------------------------------------------------- 1 | namespace GFB { 2 | public class GFile : GBase { 3 | /// 4 | /// See documentation of GBase 5 | /// 6 | public GFile(string path) : base(path) { } 7 | } 8 | } -------------------------------------------------------------------------------- /Assets/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2869d8887643d704c9c8ee75213f9bff 3 | folderAsset: yes 4 | timeCreated: 1477125115 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b66586de8459ce94a8b0e2ed12858a41 3 | folderAsset: yes 4 | timeCreated: 1472554233 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ee4091535bc48e4db2e531f6e9f007b 3 | folderAsset: yes 4 | timeCreated: 1467732854 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/GMessageBox.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: edb2025e533352f47b26c9e287be1ba5 3 | timeCreated: 1473588939 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/GFolder.cs: -------------------------------------------------------------------------------- 1 | namespace GFB { 2 | public class GFolder : GBase { 3 | /// 4 | /// See documentation of GBase 5 | /// 6 | public GFolder(string path) : base(path) { } 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1d20e886bd9c554eab2546527012fc0 3 | folderAsset: yes 4 | timeCreated: 1467805260 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/GDrive.cs: -------------------------------------------------------------------------------- 1 | namespace GFB { 2 | public class GDrive : GBase { 3 | /// 4 | /// See documentation of GBase 5 | /// 6 | public GDrive(string path) : base(path) { } 7 | } 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93de6c1fb175e044aa7676865f8dd417 3 | folderAsset: yes 4 | timeCreated: 1512564666 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/BasePanel.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 620a66d202b24d14bbee5f89eee0de43 3 | timeCreated: 1520442400 4 | licenseType: Free 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 100100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/FileBrowser.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59d6cd675a5081f479290081b0089f4d 3 | timeCreated: 1520642235 4 | licenseType: Free 5 | NativeFormatImporter: 6 | externalObjects: {} 7 | mainObjectFileID: 100100000 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/TEST.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86771a571bd5b034788e102d31ce89b4 3 | timeCreated: 1516120103 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/Browser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63344e6bd0831ff49915c8ef5e0b4bb6 3 | timeCreated: 1520430261 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e475011393ab2d45a3ba13f8077866a 3 | timeCreated: 1520636446 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GDrive.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fa613e1835d94245b5e2fadf5b83260 3 | timeCreated: 1520636447 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5c0a6c7d16544df4cb1a8f522575b6e7 3 | timeCreated: 1520636447 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GFolder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76f7a867b54a477438e251a278360106 3 | timeCreated: 1520636447 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/Utilities.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 828c3276d33dcd24da150eb313ee5b1a 3 | timeCreated: 1513798524 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/BrowserDrive.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d37e3c83bad15894da6afafd94df3559 3 | timeCreated: 1520630003 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/BrowserFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a82b28dd14e47d2478ed363163cf0fb1 3 | timeCreated: 1520630003 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GComponent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2013e25849a8bf04da9f5d8515269983 3 | timeCreated: 1520636447 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/GFileBrowser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6007ce8d3114e45458ebe8f8eeb98f1f 3 | timeCreated: 1512564674 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/MainController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1cae74468b4bba44ba5c85f7b054d5dc 3 | timeCreated: 1516120102 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/SystemCalls.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40c149ef078b110449b39e0ee207caf3 3 | timeCreated: 1520720335 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/UINavigator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46aaaf534d3f9484296ac7542dbdc464 3 | timeCreated: 1516120103 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/UIClickListener.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 398868db1bbedb14184b20bcc3d09ed5 3 | timeCreated: 1520730118 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Scripts/UIWindowMoveable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e385c5dabc837b648bd29704c9910215 3 | timeCreated: 1520780536 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/TEST.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using GFB; 4 | public class TEST : MonoBehaviour 5 | { 6 | public GameObject canv; 7 | // Use this for initialization 8 | void Start() 9 | { 10 | GFileBrowser.IsMoveable = true; // Should be placed before init 11 | GFileBrowser.Init(canv); 12 | GFileBrowser.ShowDialog("C:/"); 13 | GFileBrowser.onFileSelected = onFile; 14 | } 15 | 16 | void onFile(GBase file){ 17 | Debug.Log(file.Name); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | *.pdb.meta 29 | 30 | # Unity3D Generated File On Crash Reports 31 | sysinfo.txt 32 | 33 | # Builds 34 | *.apk 35 | *.unitypackage 36 | .vscode/settings.json 37 | omnisharp.json 38 | -------------------------------------------------------------------------------- /Assets/Scripts/GBase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace GFB { 6 | public abstract class GBase { 7 | string path, name; 8 | 9 | public string Name { get { return name; } } 10 | public string Path { get { return path; } } 11 | 12 | /// 13 | /// GBase is the abstract class for GFile, GFolder, GDrive. 14 | /// Constructor gets a paramater p, which is the path. 15 | /// Note : The name of the file will be automatically extracted. 16 | /// 17 | public GBase(string p) { 18 | this.path = p; 19 | name = Utilities.splitNamePath(this.path); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Assets/Scripts/UIWindowMoveable.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using GFB; 3 | public class UIWindowMoveable : MonoBehaviour { 4 | 5 | public GameObject canvas; 6 | bool isDragging = false; 7 | Vector2 previousPos; 8 | 9 | public void setCanvas(GameObject canvas) { 10 | this.canvas = canvas; 11 | } 12 | 13 | public void StartDragging() { 14 | previousPos = Utilities.CalculateCanvasMousePos(canvas); 15 | isDragging = true; 16 | } 17 | 18 | public void StopDragging() { 19 | isDragging = false; 20 | } 21 | 22 | public void Update() { 23 | if (isDragging) { 24 | onDragging(); 25 | } 26 | } 27 | 28 | private void onDragging() { 29 | Vector2 worldPoint = Utilities.CalculateCanvasMousePos(canvas); 30 | GetComponent().anchoredPosition += (worldPoint - previousPos); 31 | previousPos = worldPoint; 32 | } 33 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Unity Editor", 9 | "type": "unity", 10 | "request": "launch" 11 | }, 12 | { 13 | "name": "Windows Player", 14 | "type": "unity", 15 | "request": "launch" 16 | }, 17 | { 18 | "name": "OSX Player", 19 | "type": "unity", 20 | "request": "launch" 21 | }, 22 | { 23 | "name": "Linux Player", 24 | "type": "unity", 25 | "request": "launch" 26 | }, 27 | { 28 | "name": "iOS Player", 29 | "type": "unity", 30 | "request": "launch" 31 | }, 32 | { 33 | "name": "Android Player", 34 | "type": "unity", 35 | "request": "launch" 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 George Tsomlektsis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assets/Scripts/BrowserDrive.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.EventSystems; 5 | 6 | namespace GFB { 7 | /// 8 | /// Responsible for updating the contents of the Drive View. 9 | /// 10 | public class BrowserDrive : Browser { 11 | public BrowserDrive(Transform contentView, GameObject prefab, MainController controller) : base(contentView, prefab, controller) { } 12 | /// 13 | /// Reloads the drive view contents. 14 | /// 15 | public override void Reload() { 16 | try { 17 | List drives = SystemCalls.returnDrives(); 18 | Clear(); 19 | inst(drives, (b, go) => { 20 | go.GetComponent().Load(b); 21 | go.GetComponent().AddDownListener(UIClickListener.Type.LeftClick, () => { 22 | controller.getUI.onDriveClicked(go.GetComponent()); 23 | }); 24 | }); 25 | recalculateContentSize(drives.Count); 26 | } catch (Exception e) { 27 | controller.getUI.DisplayError(e); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Assets/Scripts/GComponent.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using UnityEngine.EventSystems; 4 | using System; 5 | using GFB; 6 | public class GComponent : MonoBehaviour { 7 | 8 | GBase holder; 9 | Type type; 10 | public Type Type { get { return type; } } 11 | UINavigator ui; 12 | public GBase Holder { get { return holder; } } 13 | 14 | 15 | public void Load(GBase b) { 16 | this.holder = b; 17 | type = b.GetType(); 18 | ReloadUI(); 19 | } 20 | 21 | public void ReloadUI(bool reloadText = true, bool reloadTexture = true) { 22 | if (reloadText) { 23 | if (type == typeof(GDrive)) { 24 | GetComponentInChildren().text = Holder.Path; 25 | } else { 26 | GetComponentInChildren().text = Holder.Name; 27 | } 28 | } 29 | 30 | if (reloadTexture) { 31 | if (type == typeof(GFile)) { 32 | GetComponentInChildren().texture = GFileBrowser.Resources.fileTexture; 33 | } else if (type == typeof(GFolder)) { 34 | GetComponentInChildren().texture = GFileBrowser.Resources.folderTexture; 35 | } else if (type == typeof(GDrive)) { 36 | GetComponentInChildren().texture = GFileBrowser.Resources.driveTexture; 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/file.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c0b056478be5b24982fd4f9a633ec7e 3 | timeCreated: 1467925079 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -2 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 1 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | textureType: 8 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /Assets/Scripts/UIClickListener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.EventSystems; 5 | using UnityEngine.UI; 6 | using GFB; 7 | 8 | public class UIClickListener : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { 9 | 10 | // public List> OnClickListeners 11 | // = new List>(); 12 | 13 | public List> OnDownListeners 14 | = new List>(); 15 | 16 | public List> OnUpListeners 17 | = new List>(); 18 | 19 | public void AddDownListener(Type t, Action action) { 20 | OnDownListeners.Add(new KeyValuePair(t, action)); 21 | } 22 | 23 | public void AddUpListener(Type t, Action action) { 24 | OnUpListeners.Add(new KeyValuePair(t, action)); 25 | } 26 | 27 | public void OnPointerDown(PointerEventData eventData) { 28 | OnDownListeners.ForEach(item => { 29 | if (item.Key.EqualsToUIType(eventData.button)) { item.Value(); } 30 | }); 31 | } 32 | 33 | public void OnPointerUp(PointerEventData eventData) { 34 | OnUpListeners.ForEach(item => { 35 | if (item.Key.EqualsToUIType(eventData.button)) { item.Value(); } 36 | }); 37 | } 38 | 39 | public enum Type { 40 | LeftClick, 41 | RightClick 42 | } 43 | } -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/drive.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6ac6086bf9967340a0d8f7dccefb391 3 | timeCreated: 1468251400 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 1 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | textureType: 8 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /Assets/Resources/FileBrowser/folder.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0ad9425fb7b49e499e5bd68c1e7ab31 3 | timeCreated: 1467925079 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 1 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | textureType: 8 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GFileBrowser 2 | The free open-source FileBrowser for Unity is now available for download. 3 | It uses the integrated UI System (from 5.1) and is fully customizable due to the use of prefabs. 4 | 5 | # Installation 6 | Clone the repository and take a look at the example project. 7 | The most important part of the filebrowser is Resources/FileBrowser (Contains the prefabs and the textures) and the Scripts folder, so you might as well copy them to your current project and use them accordingly :) 8 | 9 | # Usage 10 | 1. Add ```using GFB;``` at the top of your script. 11 | 2. Create a MonoBehaviour script and call ```GFileBrowser.Init(gameobject)``` where the gameobject should be your Canvas (or some child of your Canvas). 12 | 3. Create a callback function like this : 13 | ``` 14 | void onFileSelected(GBase file) { 15 | // Do stuff here with file.Name and file.Path 16 | } 17 | ``` 18 | 4. Assign the callback function to the GFileBrowser with ```GFileBrowser.onFileSelected = onFileSelected;``` 19 | 5. Show the dialog with ```GFileBrowser.ShowDialog(root)``` where root is a string that indicates the first path that the user will see when the dialog shows up. 20 | A good default value could be "C:\\". 21 | 22 | GFileBrowser contains also some extra functions that might be useful to you such as 23 | * ```AddToIgnore(string Name)``` Adds to the ignore list the name of the file-folder that you passed in the parameter so that it doesn't show up in the browser. 24 | * ```Navigate(string Path)``` Navigates the browser to the parameter Path 25 | * ```HideDialog()``` Hides the dialog (filebrowser) from the user at anytime. 26 | * ```FileOrder``` enum that specifies the order in which the folders-files should appear in the browser. 27 | Possible values are : FirstFolders, FirstFiles. The default is FirstFolders 28 | -------------------------------------------------------------------------------- /Assets/Scripts/Utilities.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections.Generic; 3 | using System; 4 | using UnityEngine.EventSystems; 5 | using UnityEngine; 6 | 7 | namespace GFB { 8 | public static class Utilities { 9 | public static readonly float panelHeight = 35.9f; 10 | public static readonly float spacingY = 2.03f; 11 | 12 | /// 13 | /// Used to calculate the height of the scrollview depending on the prefab measurements. 14 | /// 15 | public static float calculateHeight(int count) { 16 | return (panelHeight + spacingY) * count; 17 | } 18 | 19 | /// 20 | /// Given a filepath it will return the name of the file. 21 | /// 22 | public static string splitNamePath(string path) { 23 | int pos = path.LastIndexOf("/") + 1; 24 | return path.Substring(pos, path.Length - pos); 25 | } 26 | 27 | /// 28 | /// Orders alphabetically a list of strings 29 | /// 30 | public static List orderAlphabetically(this List ls) { 31 | return ls.OrderBy(str => str).ToList(); 32 | } 33 | 34 | /// 35 | /// Replaces all backslashes with frontslashes. 36 | /// 37 | public static string fixSlashes(this string str) { 38 | return str.Replace("\\", "/"); 39 | } 40 | 41 | /// 42 | /// Check if the UIClickListener type is the same as a PointerEventData inputbutton 43 | /// 44 | public static bool EqualsToUIType(this UIClickListener.Type t, PointerEventData.InputButton ib) { 45 | if (ib == PointerEventData.InputButton.Left && t == UIClickListener.Type.LeftClick) { return true; } 46 | if (ib == PointerEventData.InputButton.Right && t == UIClickListener.Type.RightClick) { return true; } 47 | return false; 48 | } 49 | 50 | public static Vector2 CalculateCanvasMousePos(GameObject canvas) { 51 | Vector2 res; 52 | RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.GetComponent(), Input.mousePosition, Camera.main, out res); 53 | return res; 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Assets/Scripts/Browser.cs: -------------------------------------------------------------------------------- 1 | 2 | using UnityEngine; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace GFB { 8 | /// 9 | /// The abstract class Browser that updates contents on views. 10 | /// 11 | public abstract class Browser { 12 | GameObject prefab; 13 | RectTransform rectTransform; 14 | protected MainController controller; 15 | protected Transform contentView; 16 | 17 | public Browser(Transform contentView, GameObject prefab, MainController controller) { 18 | this.contentView = contentView; 19 | rectTransform = this.contentView.GetComponent(); 20 | this.controller = controller; 21 | } 22 | 23 | /// 24 | /// Reloads the contents. 25 | /// 26 | public abstract void Reload(); 27 | 28 | /// 29 | /// Destroys all the objects inside the content view. 30 | /// You can optionally pass a function that will give you in each iteration of the deletion, 31 | /// the item that is going to be deleted. 32 | /// 33 | public void Clear(Action fun = null) { 34 | for (int i = 0; i < contentView.childCount; i++) { 35 | Transform item = contentView.GetChild(i); 36 | if (fun != null) { fun(item); } 37 | UnityEngine.GameObject.Destroy(item.gameObject); 38 | } 39 | } 40 | 41 | /// 42 | /// Calculates the new content size and updates the rect transform for the correct height. 43 | /// 44 | protected void recalculateContentSize(int count) { 45 | rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Utilities.calculateHeight(count)); 46 | } 47 | 48 | /// 49 | /// Instantiates GBase objects inside the content view. 50 | /// You can optionally pass a function that will give you the GBase and the GameObject that is created (after each iteration). 51 | /// 52 | protected void inst(List ls, Action fun = null) { 53 | var newls = ls.OrderBy(item => item.Name).ToList(); 54 | newls.ForEach(item => { 55 | GameObject f = GameObject.Instantiate(GFileBrowser.Resources.basePrefab, contentView, false); 56 | if (fun != null) { fun(item, f); } 57 | }); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Assets/Scripts/SystemCalls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | namespace GFB { 6 | public static class SystemCalls { 7 | /// 8 | /// Returns a List of GBase(type of File) in the parameter path 9 | /// 10 | public static List returnFiles(string path) { 11 | List res = new List(); 12 | Array.ForEach(Directory.GetFiles(path), (string str) => { res.Add(new GFile(str.fixSlashes())); }); 13 | return filter(res); 14 | } 15 | 16 | /// 17 | /// Returns a List of GBase(type of Folder) in the parameter path 18 | /// 19 | public static List returnFolders(string path) { 20 | List res = new List(); 21 | Array.ForEach(Directory.GetDirectories(path), (string str) => { res.Add(new GFolder(str.fixSlashes())); }); 22 | return filter(res); 23 | } 24 | 25 | /// 26 | /// Returns a List of GBase(type of Drive) 27 | /// 28 | public static List returnDrives() { 29 | List res = new List(); 30 | Array.ForEach(Directory.GetLogicalDrives(), (string str) => { res.Add(new GDrive(str)); }); 31 | return filter(res); 32 | } 33 | 34 | /// 35 | /// Filters out from a GBase List, the ignored files-folders from the static class GFileBrowser 36 | /// 37 | private static List filter(List list) { 38 | List newList = new List(); 39 | 40 | list.ForEach(item => { newList.Add(item); }); 41 | 42 | list.ForEach(item => { 43 | if (GFileBrowser.IgnoreList.Contains(item.Name)) { 44 | newList.Remove(item); 45 | } 46 | }); 47 | 48 | return newList; 49 | } 50 | 51 | /// 52 | /// Will delete the file-folder you provide. 53 | /// 54 | public static void DeleteGBase(GBase b) { 55 | if(b.GetType() == typeof(GFolder)){ 56 | Directory.Delete(b.Path); 57 | } else if(b.GetType() == typeof(GFile)){ 58 | File.Delete(b.Path); 59 | } 60 | } 61 | 62 | /// 63 | /// Will create a folder at a specific path and will return the GFolder that is created. 64 | /// 65 | public static GBase CreateFolder(string Path){ 66 | Directory.CreateDirectory(Path); 67 | return new GFolder(Path); 68 | } 69 | 70 | } 71 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Assets/Scripts/MainController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace GFB { 6 | public class MainController { 7 | BrowserFile brf; 8 | BrowserDrive brd; 9 | UINavigator ui; 10 | 11 | public GameObject fb; 12 | GameObject fileScrollView, driveScrollView; 13 | 14 | public BrowserFile BRF { get { return BRF; } } 15 | 16 | public BrowserDrive BRD { get { return BRD; } } 17 | 18 | public UINavigator getUI { get { return ui; } } 19 | 20 | /// 21 | /// The main controller holds the following classes : 22 | /// - UINavigator, responsible for the ui 23 | /// - Browser, responsible for filling the scroll-view contents 24 | /// 25 | /// and some GameObjects (FileBrowser, FileScrollView, DriveScrollView) 26 | /// ------------------------------------------------------------ 27 | /// Constructor takes a GameObject parent, which is used to instantiate the file browser (Preferrably the Canvas). 28 | /// 29 | public MainController(GameObject parent) { 30 | fb = GameObject.Instantiate(GFileBrowser.Resources.fileBrowserPrefab, parent.transform, false); 31 | fileScrollView = fb.transform.Find("FileScrollView").Find("Viewport").Find("Content").gameObject; 32 | driveScrollView = fb.transform.Find("DriveScrollView").Find("Viewport").Find("Content").gameObject; 33 | 34 | brf = new BrowserFile(fileScrollView.transform, GFileBrowser.Resources.basePrefab, this); 35 | brd = new BrowserDrive(driveScrollView.transform, GFileBrowser.Resources.basePrefab, this); 36 | ui = new UINavigator(fb, brf, brd); 37 | 38 | fb.transform.Find("DoneButton").GetComponent().AddDownListener(UIClickListener.Type.LeftClick, ui.onDone); 39 | fb.transform.Find("BackButton").GetComponent().AddDownListener(UIClickListener.Type.LeftClick, ui.onBack); 40 | fb.transform.Find("RedirectButton").GetComponent().AddDownListener(UIClickListener.Type.LeftClick, ui.onRedirect); 41 | if (GFileBrowser.IsMoveable) { 42 | fb.AddComponent().setCanvas(parent); 43 | fb.GetComponent().AddDownListener(UIClickListener.Type.LeftClick, fb.GetComponent().StartDragging); 44 | fb.GetComponent().AddUpListener(UIClickListener.Type.LeftClick, fb.GetComponent().StopDragging); 45 | } 46 | fb.SetActive(false); // ShowDialog has not been called only init, so we need to hide the UI from the user. 47 | } 48 | 49 | public void Show(string rootToShow) { 50 | fb.SetActive(true); 51 | brf.Reload(rootToShow, true); 52 | brd.Reload(); 53 | } 54 | 55 | public void Hide() { 56 | fb.SetActive(false); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Assets/Scripts/BrowserFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.EventSystems; 5 | 6 | namespace GFB { 7 | public class BrowserFile : Browser { 8 | public BrowserFile(Transform contentView, GameObject prefab, MainController controller) : base(contentView, prefab, controller) { } 9 | 10 | public GBase CurrentSelectedFile; 11 | 12 | List stack = new List(); 13 | 14 | /// 15 | /// Keeps a list of the components that are currently alive. 16 | /// 17 | public List components = new List(); 18 | 19 | public override void Reload() { 20 | throw new InvalidOperationException(); 21 | } 22 | 23 | /// 24 | /// Reloads the file content view. 25 | /// You can optionally pass if you want to add the current navigated path to the stack. 26 | /// 27 | public void Reload(string path, bool addToStack) { 28 | try { 29 | List files = SystemCalls.returnFiles(path); 30 | List folders = SystemCalls.returnFolders(path); 31 | if (addToStack && !(stack.Exists((String str) => { return str.Equals(path); }))) { 32 | stack.Add(path); 33 | } 34 | controller.getUI.UpdatePathField(path); 35 | CurrentSelectedFile = null; 36 | Clear((item) => { components.Remove(item.GetComponent()); }); 37 | switch (GFileBrowser.FileOrder) { 38 | case GFileBrowser.Order.FirstFiles: 39 | inst(files, addToComponents); 40 | inst(folders, addToComponents); 41 | break; 42 | case GFileBrowser.Order.FirstFolders: 43 | inst(folders, addToComponents); 44 | inst(files, addToComponents); 45 | break; 46 | } 47 | recalculateContentSize(files.Count + folders.Count); 48 | } catch (Exception e) { 49 | controller.getUI.DisplayError(e); 50 | } 51 | } 52 | 53 | /// 54 | /// Goes back in the stack (redirects to the previous folder). 55 | /// 56 | public void GoBack() { 57 | if (stack.Count < 2) { 58 | return; 59 | } 60 | Reload(stack[stack.Count - 2], false); 61 | stack.RemoveAt(stack.Count - 1); 62 | } 63 | 64 | 65 | void addToComponents(GBase b, GameObject go) { 66 | GComponent com = go.GetComponent(); 67 | components.Add(com); 68 | com.Load(b); 69 | if (com.Type == typeof(GFile)) { 70 | go.GetComponent().AddDownListener(UIClickListener.Type.LeftClick, () => { 71 | controller.getUI.onFileLeftClicked(com); 72 | }); 73 | } else if (com.Type == typeof(GFolder)) { 74 | go.GetComponent().AddDownListener(UIClickListener.Type.LeftClick, () => { 75 | controller.getUI.onFolderLeftClicked(com); 76 | }); 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Assets/Scripts/GFileBrowser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | namespace GFB { 5 | 6 | public static class GFileBrowser { 7 | 8 | static MainController Controller; 9 | 10 | /// 11 | /// Determines whether the file-browser window can be moved from the user or not 12 | /// 13 | static bool isMoveable = true; 14 | public static bool IsMoveable { get { return isMoveable; } set { isMoveable = value; } } 15 | 16 | /// 17 | /// is called when a file is selected and the user hits 'Done'. Returns the file selected 18 | /// 19 | public static Action onFileSelected; 20 | static Order order = Order.FirstFolders; 21 | 22 | /// 23 | /// Specifies the order in which the folders-files should appear in the browser. 24 | /// 25 | public static Order FileOrder { get { return order; } set { order = value; } } 26 | 27 | static List ignoreList = new List() 28 | { "hiberfil.sys", "System Volume Information", "Recovery", "ProgramData", "bootmgr", "BOOTNXT", 29 | "BOOTSECT.BAK", "Boot", "pagefile.sys", "setup.log", "swapfile.sys", "$RECYCLE.BIN", "Documents and Settings" }; 30 | public static List IgnoreList { get { return ignoreList; } } 31 | 32 | /// 33 | /// First function to call in order to init the GFileBrowser. 34 | /// 35 | public static void Init(GameObject parent) { 36 | Resources.Load(); 37 | Controller = new MainController(parent); 38 | } 39 | 40 | /// 41 | /// Adds to ignore list, so these folders-files don't display in the browser 42 | /// 43 | public static void AddToIgnore(string Name) { 44 | ignoreList.Add(Name); 45 | } 46 | 47 | /// 48 | /// Navigates the browser to a path 49 | /// 50 | public static void Navigate(string Path) { 51 | Controller.BRF.Reload(Path, true); 52 | } 53 | 54 | /// 55 | /// Shows the dialog to the user 56 | /// 57 | public static void ShowDialog(string Path) { 58 | Controller.Show(Path); 59 | } 60 | 61 | /// 62 | /// Hides the dialog from the user 63 | /// 64 | public static void HideDialog() { 65 | Controller.Hide(); 66 | } 67 | 68 | public enum Order { 69 | FirstFolders, 70 | FirstFiles 71 | } 72 | 73 | /// 74 | /// Class responsible for holding the resources(textures, prefabs) of the file browser. 75 | /// 76 | public static class Resources { 77 | public static GameObject fileBrowserPrefab; 78 | public static GameObject basePrefab; 79 | public static Texture2D fileTexture, folderTexture, driveTexture; 80 | public static void Load() { 81 | basePrefab = UnityEngine.Resources.Load("FileBrowser/BasePanel") as GameObject; 82 | fileBrowserPrefab = UnityEngine.Resources.Load("FileBrowser/FileBrowser") as GameObject; 83 | fileTexture = UnityEngine.Resources.Load("FileBrowser/file") as Texture2D; 84 | folderTexture = UnityEngine.Resources.Load("FileBrowser/folder") as Texture2D; 85 | driveTexture = UnityEngine.Resources.Load("FileBrowser/drive") as Texture2D; 86 | } 87 | 88 | } 89 | } 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Assets/Scripts/UINavigator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System; 6 | using System.IO; 7 | using UnityEngine.EventSystems; 8 | 9 | namespace GFB { 10 | public class UINavigator { 11 | 12 | //----UI Components----// 13 | InputField pathField; 14 | Text errorDisplayText; 15 | 16 | //----Classes----// 17 | BrowserFile brf; 18 | BrowserDrive brd; 19 | 20 | //----Colors----/ 21 | Color32 selectedColor = new Color32(0, 0, 255, 100); 22 | Color32 normalColor = new Color32(255, 255, 255, 100); 23 | 24 | public UINavigator(GameObject fb, BrowserFile browserFile, BrowserDrive browserDrive) { 25 | this.brf = browserFile; 26 | this.brd = browserDrive; 27 | pathField = fb.transform.Find("PathField").GetComponent(); 28 | errorDisplayText = fb.transform.Find("ErrorDisplayText").GetComponent(); 29 | } 30 | 31 | //----UI Responses----// 32 | 33 | void setSelected(GComponent gComponent, bool selected) { 34 | if (selected) { 35 | gComponent.gameObject.GetComponent().color = selectedColor; 36 | } else { 37 | gComponent.gameObject.GetComponent().color = normalColor; 38 | } 39 | } 40 | 41 | public void UpdatePathField(string path) { 42 | pathField.text = path; 43 | } 44 | 45 | public void DisplayError(Exception e) { 46 | string tmp = "Unknown error : " + e.ToString(); 47 | if (e is DirectoryNotFoundException) { 48 | tmp = "Path not found"; 49 | } else if (e is UnauthorizedAccessException) { 50 | tmp = "You don't have permission to access this folder"; 51 | } else if (e is ArgumentException) { 52 | tmp = "Path contains invalid characters"; 53 | } else if (e is ArgumentNullException) { 54 | tmp = "Path is invalid (maybe empty?)"; 55 | } else if (e is PathTooLongException) { 56 | tmp = "Path has exceed the system-defined maximum length"; 57 | } 58 | errorDisplayText.text = tmp; 59 | } 60 | 61 | //----UI Calls----// 62 | 63 | public void onBack() { 64 | brf.GoBack(); 65 | } 66 | 67 | public void onDone() { 68 | GFileBrowser.onFileSelected(brf.CurrentSelectedFile); 69 | GFileBrowser.HideDialog(); 70 | } 71 | 72 | public void onRedirect() { 73 | brf.Reload(pathField.text, true); 74 | } 75 | 76 | public void onDriveClicked(GComponent g) { 77 | brf.Reload(g.Holder.Path, true); 78 | } 79 | 80 | public void onFolderLeftClicked(GComponent g) { 81 | brf.Reload(g.Holder.Path, true); 82 | } 83 | 84 | public void onFolderRightClicked(GComponent g) { 85 | 86 | } 87 | 88 | public void onFileLeftClicked(GComponent g) { 89 | if (g.Holder.Equals(brf.CurrentSelectedFile)) { 90 | setSelected(g, false); 91 | brf.CurrentSelectedFile = null; 92 | } else { 93 | brf.components.ForEach(c => { 94 | if (!c.Equals(g)) { 95 | setSelected(c, false); 96 | } else { 97 | setSelected(c, true); 98 | brf.CurrentSelectedFile = (GFile)c.Holder; 99 | } 100 | }); 101 | 102 | } 103 | } 104 | 105 | public void onFileRightClicked(GComponent g) { 106 | 107 | } 108 | } 109 | } 110 | 111 | --------------------------------------------------------------------------------