async UniTaskVoid TakeScreenshot(WebJSON.Screenshot msg) { if (msg != null) { TransparencyCaptureBehaviour tcb = Camera.main.GetComponent <TransparencyCaptureBehaviour>(); if (tcb != null) { try { if (msg.Type == WebJSON.Screenshot.ScreenshotType.FullLevel) { System.DateTime dateTime = System.DateTime.Now; byte[] screenshotBytes = await tcb.CaptureFulllevel(msg.IsTransparent ?? true); SaveFile(screenshotBytes, screenshotBytes.Length, $"Screenshot_{dateTime.ToString("yyyy_MM_dd HH_mm_ss")}.png"); } else { Resolution res = TransparencyCaptureBehaviour.GetCurrentResolution(); int height = msg.Height ?? Mathf.RoundToInt(res.height * (msg.SizeFactor ?? 1)); int width = msg.Width ?? Mathf.RoundToInt(res.width * (msg.SizeFactor ?? 1)); if (width > 0 && height > 0) { System.DateTime dateTime = System.DateTime.Now; byte[] screenshotBytes = await tcb.Capture(width, height, msg.IsTransparent ?? true); SaveFile(screenshotBytes, screenshotBytes.Length, $"Screenshot_{dateTime.ToString("yyyy_MM_dd HH_mm_ss")}.png"); } } } catch (Exception) { Debug.Log("Screenshot failed"); } } } }
public override async void OnInspectorGUI() { DrawDefaultInspector(); TransparencyCaptureBehaviour pb = (TransparencyCaptureBehaviour)target; if (GUILayout.Button("Take screenshot")) { Resolution res = TransparencyCaptureBehaviour.GetCurrentResolution(); System.DateTime dateTime = System.DateTime.Now; byte[] screenshotBytes = await pb.CaptureFulllevel(true); //byte[] screenshotBytes = await pb.Capture(res.width* 4, res.height * 4, true); Util.ByteArrayToFile("Screenshots/" + dateTime.ToString("yyyy_MM_dd HH_mm_ss") + ".png", screenshotBytes); } }
public async UniTask <byte[]> CreateLevelScreenshot() { var onFinished = new List <Action>(); // Force update event controller controllerEvents.ForceUpdate(); // Hide unused links and show gendoors foreach (var e in Objects) { // Update the event to make sure it has rendered e.ForceUpdate(); if (e.ObjData is Unity_Object_R1 r1Obj) { Enum[] exceptions = { R1_EventType.TYPE_GENERATING_DOOR, R1_EventType.TYPE_DESTROYING_DOOR, R1_EventType.MS_scintillement, R1_EventType.MS_super_gendoor, R1_EventType.MS_super_kildoor, R1_EventType.MS_compteur, R1_EventType.TYPE_RAY_POS, R1_EventType.TYPE_INDICATOR, }; if (exceptions.Contains(r1Obj.EventData.Type)) { var wasActive = e.gameObject.activeSelf; e.gameObject.SetActive(true); onFinished.Add(() => e.gameObject.SetActive(wasActive)); } } else if (e.ObjData is Unity_Object_GBA gbaObj) { if (gbaObj.Actor.ActorID == 0) { var wasActive = e.gameObject.activeSelf; e.gameObject.SetActive(true); onFinished.Add(() => e.gameObject.SetActive(wasActive)); } } // Hide events with no graphics if (e.defaultRenderer.gameObject.activeSelf && !Settings.Screenshot_ShowDefaultObj) { var wasActive = e.gameObject.activeSelf; e.gameObject.SetActive(false); onFinished.Add(() => e.gameObject.SetActive(wasActive)); } // TODO: Change this option // Helper method bool showLinksForObj(Unity_ObjBehaviour ee) { if (ee.ObjData is Unity_Object_R1 r1Object) { return(r1Object.EventData.Type == R1_EventType.TYPE_GENERATING_DOOR || r1Object.EventData.Type == R1_EventType.TYPE_DESTROYING_DOOR || r1Object.EventData.Type == R1_EventType.MS_scintillement || r1Object.EventData.Type == R1_EventType.MS_super_gendoor || r1Object.EventData.Type == R1_EventType.MS_super_kildoor || r1Object.EventData.Type == R1_EventType.MS_compteur); } return(ee.ObjData.EditorLinkGroup != 0); } if (e.ObjData.EditorLinkGroup == 0) { var wasActive = e.lineRend.enabled; e.lineRend.enabled = false; e.linkCube.gameObject.SetActive(false); onFinished.Add(() => { e.lineRend.enabled = wasActive; e.linkCube.gameObject.SetActive(wasActive); }); } else { // Hide link if not linked to gendoor bool gendoorFound = showLinksForObj(e); var allofSame = new List <Unity_ObjBehaviour> { e }; foreach (Unity_ObjBehaviour f in Objects.Where(f => f.ObjData.EditorLinkGroup == e.ObjData.EditorLinkGroup)) { allofSame.Add(f); if (showLinksForObj(f)) { gendoorFound = true; } } if (!gendoorFound) { foreach (var a in allofSame) { var wasActive = a.lineRend.enabled; a.lineRend.enabled = false; a.linkCube.gameObject.SetActive(false); onFinished.Add(() => { a.lineRend.enabled = wasActive; a.linkCube.gameObject.SetActive(wasActive); }); } } } } TransparencyCaptureBehaviour tcb = Camera.main.GetComponent <TransparencyCaptureBehaviour>(); byte[] result = await tcb.CaptureFulllevel(false, ScreenshotRect); foreach (var a in onFinished) { a?.Invoke(); } return(result); }