- Home /
Android Game boy emulator: How to set directory in C# Script
i found a open source game boy emulator and decide port to android but im new in unity and in c# and I'm doubt this part of this code
// Get what path to use depending on platform
static public string getPath() {
if (path == "") {
// Check platforms, change this to different platfoms as needed
// I've set SAV games and ROMs to be in the same folder.
switch (Application.platform) {
case (RuntimePlatform.Android):
path = "/accounts/1000/shared/misc/roms/gb/";
break;
default:
path = System.Environment.CurrentDirectory + "//storage//sdcard0//Download//";
break;
}
}
how to set path to android and directory to downloads folder for example, as directory diversify as do look for another directory if not find it,It would be a variable, show me examples for this. (Sorry my english)
complete code
using UnityEngine;
using System.Collections;
using System.IO;
public class LoaderScript : MonoBehaviour {
static public string path = "";
static public string[] roms;
static public int romIndex;
static public GUIText guiText;
static public FileInfo[] fileInfo;
// Prevent long strings and show only the end of the text string
static public string mStr(string inString) {
int maxLen = 28;
if (inString.Length > maxLen) {
inString = "..." + inString.Substring(inString.Length - maxLen);
}
return inString;
}
// Find all the roms in the folder and display it based on romIndex
static public void findRoms() {
updateText ("Loading...");
if (romIndex == null)
romIndex = 0;
string extension = "*.gb";
DirectoryInfo dirInfo = new DirectoryInfo(getPath());
fileInfo = dirInfo.GetFiles(extension);
string tString = "";
int mIndex = romIndex + 10;
tString = "<I>" + mStr("Path: " + getPath() + "\n\n") + "</I>";
if (fileInfo.Length > mIndex) {
for (int i = romIndex; i < mIndex; i++) {
if (i == romIndex)
tString = tString + "> ";
else
tString = tString + " ";
tString = tString + fileInfo[i].Name +"\n";
}
tString = tString + "... more";
}
else
{
for (int i = romIndex; i < fileInfo.Length; i++) {
if (i == romIndex)
tString = tString + "> ";
tString = tString + fileInfo[i].Name +"\n";
}
tString = tString + "... end";
}
tString = tString + "\n\nQ Keys WSAD [Arrows], OP [Buttons]\nSpace & Enter, T Screenshot";
updateText (tString);
}
// Update our text box
static public void updateText(string text) {
if (guiText == null)
guiText = GameObject.Find("Text").GetComponent<GUIText>();
guiText.text = text;
}
// Get what path to use depending on platform
static public string getPath() {
if (path == "") {
// Check platforms, change this to different platfoms as needed
// I've set SAV games and ROMs to be in the same folder.
switch (Application.platform) {
case (RuntimePlatform.BlackBerryPlayer):
path = "/accounts/1000/shared/misc/roms/gb/";
break;
default:
path = System.Environment.CurrentDirectory + "\\Assets\\ROM\\";
break;
}
}
Debug.Log("ROM path set to: " + path);
return path;
}
// Not used
static public void createFolder(string path) {
Debug.Log ("Creating path: " + path);
File.Create (path);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Character Movement Problem 0 Answers
Why does my pause & quit menus appear when I load next level? 0 Answers