using UnityEngine; using System.Collections; using UnityEngine.UI; public class FileBrowser : MonoBehaviour { string message = ""; float alpha = 1.0f; char pathChar = '/'; public float posY = 560; public float posX = 560; public float posY2 = 739; public float posX2 = 18; public float xSize = 159; public float ySize = 20; public Button check; private bool importCheck, importCheckPass, spawnCheckPass ; private bool importSettingCheck, importSettingCheckPass, exportSettingCheckPass; public GameObject mapBehaviorObj; public GameObject spawnBehaviorObj; public Controller control; void Start () { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { pathChar = '\\'; } importCheck = false; importSettingCheck = false; } void Update(){ if (Input.GetKeyDown ("v") || Input.GetKeyDown("w")) { importCheck = !importCheck; if (importCheck){ importCheckPass = true; spawnCheckPass = true; }else if (!importCheck){ importCheckPass = false; spawnCheckPass = false; } } if (Input.GetKeyDown ("c") || Input.GetKeyDown("w")) { importSettingCheck = !importSettingCheck; if (importSettingCheck){ importSettingCheckPass = true; exportSettingCheckPass = true; }else if (!importSettingCheck){ importSettingCheckPass = false; exportSettingCheckPass = false; } } } void OnGUI () { if (!importCheckPass) { if (GUI.Button (new Rect(850, 562, 90, 30), "Import Map")) { if (UniFileBrowser.use.allowMultiSelect) { UniFileBrowser.use.OpenFileWindow (OpenFiles); } else { UniFileBrowser.use.OpenFileWindow (OpenFile); } } } if (!spawnCheckPass) { if (GUI.Button (new Rect(850, 662, 90, 31), "Spawn Map")) { if (UniFileBrowser.use.allowMultiSelect) { UniFileBrowser.use.OpenFileWindow (OpenSpawnFiles); } else { UniFileBrowser.use.OpenFileWindow (OpenSpawnFile); } } } if (!importSettingCheckPass) { if (GUI.Button (new Rect(posX2, posY2, xSize, ySize), "Import Settings")) { if (UniFileBrowser.use.allowMultiSelect) { UniFileBrowser.use.OpenFileWindow (OpenFiles); } else { UniFileBrowser.use.OpenFileWindow (OpenSettingFile); } } } if (!exportSettingCheckPass) { if (GUI.Button (new Rect(posX, posY, xSize, ySize), "Export Settings")) { UniFileBrowser.use.SaveFileWindow (SaveFile); } } var col = GUI.color; col.a = alpha; GUI.color = col; GUI.Label (new Rect(100, 275, 500, 1000), message); col.a = 1.0f; GUI.color = col; } void OpenFile (string behaviorpathToFile) { var behaviorfileIndex = behaviorpathToFile; //message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); mapBehaviorObj.GetComponent<MapBehavior> ().updatePath = behaviorfileIndex; mapBehaviorObj.GetComponent<MapBehavior> ().runIt = true; Fade(); } void OpenSpawnFile (string spawnpathToFile) { var spawnfileIndex = spawnpathToFile; //message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); spawnBehaviorObj.GetComponent<SpawnBehavior> ().newPath = spawnfileIndex; spawnBehaviorObj.GetComponent<SpawnBehavior> ().runIt = true; Fade(); } void OpenSettingFile (string pathToFile) { var fileIndex = pathToFile; //message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); control.GetComponent<SettingsImport> ().path = fileIndex; control.GetComponent<SettingsImport> ().runIt = true; Fade(); } void OpenSpawnFiles (string[] pathsToFiles) { message = "You selected these files:\n"; for (var i = 0; i < pathsToFiles.Length; i++) { var fileIndex = pathsToFiles[i].LastIndexOf (pathChar); message += pathsToFiles[i].Substring (fileIndex+1, pathsToFiles[i].Length-fileIndex-1) + "\n"; } Fade(); } void OpenFiles (string[] pathsToFiles) { message = "You selected these files:\n"; for (var i = 0; i < pathsToFiles.Length; i++) { var fileIndex = pathsToFiles[i].LastIndexOf (pathChar); message += pathsToFiles[i].Substring (fileIndex+1, pathsToFiles[i].Length-fileIndex-1) + "\n"; } Fade(); } void SaveFile (string pathToFile) { var fileIndex = pathToFile; //message = "You're saving file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); control.GetComponent<SettingsExport> ().pathSpecified = fileIndex; control.GetComponent<SettingsExport> ().runIt = true; Fade(); } void OpenFolder (string pathToFolder) { message = "You selected folder: " + pathToFolder; Fade(); } void Fade () { StopCoroutine ("FadeAlpha"); // Interrupt FadeAlpha if it's already running, so only one instance at a time can run StartCoroutine ("FadeAlpha"); } IEnumerator FadeAlpha () { alpha = 1.0f; yield return new WaitForSeconds (5.0f); for (alpha = 1.0f; alpha > 0.0f; alpha -= Time.deltaTime/4) { yield return null; } message = ""; } } Update