// Corutine add message private IEnumerator add_delayed_event(EntryCorutine data) { KDebug.Log("pre add_delayed_event", KDebug.Type.CORUTINE); float waitTime = 3; //this._situationRunning = true; yield return new WaitForSeconds(waitTime); KDebug.Log("post add_delayed_event", KDebug.Type.CORUTINE); report.add_situation_event(data.situation, data.ves, data.message, data.vessel_situation); }
// This corutine add event imideatelly and add photo later private IEnumerator add_event_and_delayed_photo(EntryCorutine data) { KDebug.Log("pre add_event_and_delayed_photo", KDebug.Type.CORUTINE); Mission M = report.add_event_get_mission(data.situation, data.ves, data.message); if (M == null) yield break; int iE = M.get_last_entry_index(); // we should return index that we just added float waitTime = 1; // default wait time if(data.situation == Entry.Situations.EXPLODE) waitTime = 0.1f; // Faster watitime for explosion (capture cool photo) yield return new WaitForSeconds(waitTime); // Now we wait KDebug.Log("post add_event_and_delayed_photo", KDebug.Type.CORUTINE); // We are serching for right filepath! // The name of the screenshot should be constructed! String dirName = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder; var dirInfo = new System.IO.DirectoryInfo(dirName); // TODO: when the game is created // if (!Directory.Exists(dirName + "/Kistory/Photo/")) //{ //Directory.CreateDirectory(filePath + "/Kistory/Photo/"); //} //String fileName = dirInfo.FullName + "/Kistory/Photo/" + str_eventTime() + data.situation.ToString(); String fileName = dirInfo.FullName + "/" + str_eventTime() + data.situation.ToString(); // Let's make sure that we don't have the file with this name int cntr = 0; FileInfo info = new FileInfo(fileName + cntr.ToString() + ".png"); while (info != null & info.Exists != false) { cntr++; info = new FileInfo(fileName + cntr.ToString() + ".png"); } fileName = fileName + cntr.ToString() + ".png"; KDebug.Log("filename " + fileName, KDebug.Type.CORUTINE); KDebug.Log("Capturing screeshot for " + iE.ToString() + " in " + data.situation.ToString() + " " + fileName, KDebug.Type.CORUTINE); Application.CaptureScreenshot(fileName); // SCREEN SHOT while (!File.Exists(fileName)) { yield return null; // apparently it should make the screeshot first and then continue } KDebug.Log("Trasfering screeshot for " + iE.ToString() + " in " + data.situation.ToString() + " " + fileName, KDebug.Type.CORUTINE); M.add_screenshot(fileName, iE); StartCoroutine("delayed_message", "Screenshot captured!"); // add message that we added the screenshot with 1s delay }