Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: public static void SetPunDemoBuildSettings()
{
// find path of pun guide
string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
if (tempPaths == null || tempPaths.Length != 1)
{
return;
}
// find scenes of guide
string guidePath = tempPaths[0];
tempPaths = Directory.GetFiles(guidePath, "*.unity", SearchOption.AllDirectories);
if (tempPaths == null || tempPaths.Length == 0)
{
return;
}
// add found guide scenes to build settings
List sceneAr = new List();
for (int i = 0; i < tempPaths.Length; i++)
{
//Debug.Log(tempPaths[i]);
string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
path = path.Replace('\\', '/');
//Debug.Log(path);
if (path.Contains("PUNGuide_M2H"))
{
continue;
}
if (path.Contains("Hub"))
{
sceneAr.Insert(0, new EditorBuildSettingsScene(path, true));
continue;
}
sceneAr.Add(new EditorBuildSettingsScene(path, true));
}
EditorBuildSettings.scenes = sceneAr.ToArray();
EditorApplication.OpenScene(sceneAr[0].path);
}
{
// find path of pun guide
string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
if (tempPaths == null || tempPaths.Length != 1)
{
return;
}
// find scenes of guide
string guidePath = tempPaths[0];
tempPaths = Directory.GetFiles(guidePath, "*.unity", SearchOption.AllDirectories);
if (tempPaths == null || tempPaths.Length == 0)
{
return;
}
// add found guide scenes to build settings
List
for (int i = 0; i < tempPaths.Length; i++)
{
//Debug.Log(tempPaths[i]);
string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
path = path.Replace('\\', '/');
//Debug.Log(path);
if (path.Contains("PUNGuide_M2H"))
{
continue;
}
if (path.Contains("Hub"))
{
sceneAr.Insert(0, new EditorBuildSettingsScene(path, true));
continue;
}
sceneAr.Add(new EditorBuildSettingsScene(path, true));
}
EditorBuildSettings.scenes = sceneAr.ToArray();
EditorApplication.OpenScene(sceneAr[0].path);
}