// Adapted from WriteToPng method public static void CustomWriteToPng(RenderTexture renderTex) { Texture2D texture2D = new Texture2D(renderTex.width, renderTex.height, TextureFormat.ARGB32, false); texture2D.ReadPixels(new Rect(0f, 0f, renderTex.width, renderTex.height), 0, 0); texture2D.Apply(); byte[] bytes = texture2D.EncodeToPNG(); Object.Destroy(texture2D); if (!Directory.Exists(Util.RootFolder())) { Directory.CreateDirectory(Util.RootFolder()); } string text = Path.Combine(Util.RootFolder(), "HD_Screenshots"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } string name = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.BaseName); DebugUtil.LogArgs(new object[] { "Saving screenshot to", text }); savedPath = text; string format = "0000.##"; text = text + Path.DirectorySeparatorChar + name + "_cycle_" + GameClock.Instance.GetCycle().ToString(format); File.WriteAllBytes(text + ".png", bytes); }
/// <summary> /// Saves a preview image to disk in the background. /// </summary> /// <param name="data">The uncompressed preview image data.</param> private void DoSave(BackgroundTimelapseData data) { var screenData = data.TextureData; string previewPath = data.SaveGamePath; bool preview = data.Preview; byte[] rawPNG; // Encode PNG (this is the woofy part on high resolution) #if DEBUG PUtil.LogDebug("Encoding preview image"); #endif try { rawPNG = screenData.EncodeToPNG(); } finally { data.Dispose(); } try { string retiredPath = Path.Combine(Util.RootFolder(), Util. GetRetiredColoniesFolderName()); if (!Directory.Exists(retiredPath)) { // This call is recursive Directory.CreateDirectory(retiredPath); } string saveName = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance. BaseName), path; if (preview) { // Colony preview path = Path.ChangeExtension(previewPath, ".png"); } else { string saveFolder = Path.Combine(retiredPath, saveName); if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } // Suffix file name with the current cycle saveName += "_cycle" + GameClock.Instance.GetCycle().ToString("0000.##"); // debugScreenShot is always false path = Path.Combine(saveFolder, saveName); } PUtil.LogDebug("Saving screenshot to " + path); File.WriteAllBytes(path, rawPNG); rawPNG = null; #if DEBUG PUtil.LogDebug("Background screenshot save complete"); #endif } catch (IOException e) { PUtil.LogWarning("Unable to save colony timelapse screenshot:"); PUtil.LogExcWarn(e); } catch (UnauthorizedAccessException e) { PUtil.LogWarning("Unable to save colony timelapse screenshot:"); PUtil.LogExcWarn(e); } }
/// <summary> /// Saves a preview image to disk in the background. /// </summary> /// <param name="data">The uncompressed preview image data.</param> private void DoSave(BackgroundTimelapseData data) { var screenData = data.RawData; string previewPath = data.SaveGamePath; bool preview = data.Preview; try { string retiredPath = Path.Combine(Util.RootFolder(), Util. GetRetiredColoniesFolderName()); if (!Directory.Exists(retiredPath)) { // This call is recursive Directory.CreateDirectory(retiredPath); } string saveName = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance. BaseName), path; if (preview) { // Colony preview path = Path.ChangeExtension(previewPath, ".png"); } else { string saveFolder = Path.Combine(retiredPath, saveName), worldName = data.WorldName; if (!string.IsNullOrWhiteSpace(worldName)) { saveFolder = Path.Combine(saveFolder, data.WorldID.ToString("D5")); saveFolder = Path.Combine(saveFolder, worldName); saveName = worldName; } if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } // Suffix file name with the current cycle saveName += "_cycle_" + GameClock.Instance.GetCycle().ToString("0000.##") + ".png"; // debugScreenShot is always false path = Path.Combine(saveFolder, saveName); } PUtil.LogDebug("Saving screenshot to " + path); File.WriteAllBytes(path, data.RawData); #if DEBUG PUtil.LogDebug("Background screenshot save complete"); #endif } catch (IOException e) { PUtil.LogWarning("Unable to save colony timelapse screenshot:"); PUtil.LogExcWarn(e); } catch (UnauthorizedAccessException e) { PUtil.LogWarning("Unable to save colony timelapse screenshot:"); PUtil.LogExcWarn(e); } }
public RetiredColonyData GetColonyDataByBaseName(string name) { name = RetireColonyUtility.StripInvalidCharacters(name); for (int i = 0; i < retiredColonyData.Length; i++) { if (RetireColonyUtility.StripInvalidCharacters(retiredColonyData[i].colonyName) == name) { return(retiredColonyData[i]); } } return(null); }
private void LoadExplorer() { if (!((UnityEngine.Object)SaveGame.Instance != (UnityEngine.Object)null)) { ToggleExplorer(true); this.retiredColonyData = RetireColonyUtility.LoadRetiredColonies(false); RetiredColonyData[] array = this.retiredColonyData; foreach (RetiredColonyData retiredColonyData in array) { RetiredColonyData data = retiredColonyData; GameObject gameObject = Util.KInstantiateUI(colonyButtonPrefab, explorerGrid, true); HierarchyReferences component = gameObject.GetComponent <HierarchyReferences>(); string text = RetireColonyUtility.StripInvalidCharacters(data.colonyName); Sprite sprite = RetireColonyUtility.LoadRetiredColonyPreview(text); Image reference = component.GetReference <Image>("ColonyImage"); RectTransform reference2 = component.GetReference <RectTransform>("PreviewUnavailableText"); if ((UnityEngine.Object)sprite != (UnityEngine.Object)null) { reference.enabled = true; reference.sprite = sprite; reference2.gameObject.SetActive(false); } else { reference.enabled = false; reference2.gameObject.SetActive(true); } component.GetReference <LocText>("ColonyNameLabel").SetText(retiredColonyData.colonyName); component.GetReference <LocText>("CycleCountLabel").SetText(string.Format(UI.RETIRED_COLONY_INFO_SCREEN.CYCLE_COUNT, retiredColonyData.cycleCount.ToString())); component.GetReference <LocText>("DateLabel").SetText(retiredColonyData.date); gameObject.GetComponent <KButton>().onClick += delegate { LoadColony(data); }; string key = retiredColonyData.colonyName; int num = 0; while (explorerColonyWidgets.ContainsKey(key)) { num++; key = retiredColonyData.colonyName + "_" + num; } explorerColonyWidgets.Add(key, gameObject); } } }