Exemple #1
0
 public void RefreshFolder()
 {
     if (dataFolder == null || dataFolder == "")
     {
         Debug.LogError("Folder path for scenarios not found");
         return;
     }
     for (int i = scenarioButtonHolder.childCount - 1; i >= 0; i--)
     {
         Destroy(scenarioButtonHolder.GetChild(i).gameObject);
     }
     try
     {
         Directory.CreateDirectory(dataFolder);
         Directory.GetLastAccessTime(dataFolder);
         Directory.GetDirectories(dataFolder);
     }
     catch (UnauthorizedAccessException)
     {
         PermissionRequester.RequestPermisssion((req) =>
         {
             if (req)
             {
                 RefreshFolder();
             }
             else
             {
                 DebugText.LogError("Cannot access scenario folder without permission");
             }
         });
         return;
     }
     catch (Exception e)
     {
         DebugText.LogException("Cannot access scenario folder", e);
         return;
     }
     string[] dirs = Directory.GetDirectories(dataFolder);
     foreach (string dir in dirs)
     {
         GameObject button = GameObject.Instantiate <GameObject>(scenarioButton, scenarioButtonHolder, false);
         button.GetComponent <Button>().onClick.AddListener(() => {
             scenarioManager.LoadScenario(Path.Combine(dataFolder, dir));
         });
         button.GetComponentInChildren <Text>().text = Path.GetFileName(dir);
     }
 }
 public void HandleMessage(string msg)
 {
     if (msg == "idle")
     {
         text.Show("Waiting for scenario selection");
         scenarioManager.gameObject.SetActive(false);
     }
     else if (msg == "disconnect")
     {
         Disconnect();
     }
     else
     {
         try
         {
             MessageData ndata = new MessageData(msg);
             if (!scenarioManager.gameObject.activeSelf || ndata.scenario != data.scenario)
             {
                 scenarioManager.LoadScenario(Path.Combine(fileExplorer.dataFolder, ndata.scenario), true);
             }
             if (data.scene != ndata.scene)
             {
                 scenarioManager.SwitchScene(ndata.scene == "" ? null : ndata.scene);
                 if (data.permutation != ndata.permutation)
                 {
                     scenarioManager.SetPermutationNumber(ndata.permutation);
                 }
             }
             if (string.IsNullOrEmpty(ndata.scene))
             {
                 text.Hide();
             }
             data = ndata;
         }
         catch (Exception e)
         {
             data = new MessageData(this);
             Debug.Log("Could not parse data " + e.ToString());
         }
     }
 }
Exemple #3
0
 public void LoadScenarioButton1()
 {
     scenarioManager.LoadScenario(Scenario1Button.GetComponentInChildren <Text>().text);
     ChangeScenarioName(Scenario1Button.GetComponentInChildren <Text>().text);
 }