public async UniTask <byte[]> Capture(int width, int height, bool isTransparent)
    {
        if (isTransparent)
        {
            Controller.obj.levelController.controllerTilemap.backgroundTint.gameObject.SetActive(false);
        }
        await UniTask.WaitForEndOfFrame();

        //After Unity4,you have to do this function after WaitForEndOfFrame in Coroutine
        //Or you will get the error:"ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame"
        //zzTransparencyCapture.captureScreenshot("capture.png");
        byte[] screenshotBytes = null;


        List <Camera> cameras = new List <Camera>();

        cameras.Add(Camera.main);
        if (LevelEditorData.Level?.IsometricData != null)
        {
            EditorCam ec = Controller.obj?.levelController?.editor?.cam;
            cameras.Add(ec.camera3D);
        }

        var lScreenshot = zzTransparencyCapture.CaptureScreenshot(width, height, isTransparent, camera: cameras.ToArray());

        try {
            screenshotBytes = lScreenshot.EncodeToPNG();
        } finally {
            Object.DestroyImmediate(lScreenshot);
        }
        if (isTransparent)
        {
            Controller.obj.levelController.controllerTilemap.backgroundTint.gameObject.SetActive(true);
        }
        Debug.Log("Screenshot saved.");
        return(screenshotBytes);
    }
    public async UniTask <byte[]> CaptureFulllevel(bool isTransparent, RectInt?rect = null)
    {
        if (isTransparent)
        {
            Controller.obj.levelController.controllerTilemap.backgroundTint.gameObject.SetActive(false);
        }
        //Camera[] cams = Camera.allCameras.OrderBy(c => c.depth).ToArray();
        int width            = LevelEditorData.MaxWidth;
        int height           = LevelEditorData.MaxHeight;
        int cellSize         = LevelEditorData.Level.CellSize;
        int screenshotWidth  = Mathf.CeilToInt(width / (float)cellSize);
        int screenshotHeight = Mathf.CeilToInt(height / (float)cellSize);
        var cellSizeInUnits  = cellSize / (float)LevelEditorData.Level.PixelsPerUnit;
        Dictionary <Camera, CameraSettings> camSettings = new Dictionary <Camera, CameraSettings>();
        EditorCam ec = Controller.obj?.levelController?.editor?.cam;

        ec.enabled = false;
        List <Camera> cameras = new List <Camera>();

        // Add main camera
        {
            Camera cam = Camera.main;
            camSettings[cam] = CameraSettings.Current(cam);

            cam.transform.position = new Vector3((LevelEditorData.MaxWidth) * cellSizeInUnits / 2f, -(LevelEditorData.MaxHeight) * cellSizeInUnits / 2f, cam.transform.position.z);
            cam.orthographicSize   = (LevelEditorData.MaxHeight * cellSizeInUnits / 2f);
            cam.rect = new Rect(0, 0, 1, 1);
            cameras.Add(cam);
        }
        if (LevelEditorData.Level?.IsometricData != null)
        {
            // Add isometric camera
            Camera cam = ec.camera3D;

            camSettings[cam] = CameraSettings.Current(cam);

            // Update 3D camera
            float      scl   = 1f;
            Quaternion rot3D = LevelEditorData.Level.IsometricData.ViewAngle;
            cam.transform.rotation = rot3D;
            Vector3 v = rot3D * Vector3.back;
            float   w = LevelEditorData.Level.IsometricData.TilesWidth * cellSizeInUnits;
            float   h = (LevelEditorData.Level.IsometricData.TilesHeight) * cellSizeInUnits;
            float   colYDisplacement = LevelEditorData.Level.IsometricData.CalculateYDisplacement();
            float   colXDisplacement = LevelEditorData.Level.IsometricData.CalculateXDisplacement();

            var pos = new Vector3((LevelEditorData.MaxWidth) * cellSizeInUnits / 2f, -(LevelEditorData.MaxHeight) * cellSizeInUnits / 2f, -10f);

            cam.transform.position = v * 300 + rot3D * ((pos -
                                                         new Vector3((w - colXDisplacement) / 2f, -(h - colYDisplacement) / 2f, 0f)) / scl); // Move back 300 units
            cam.orthographicSize = Camera.main.orthographicSize / scl;
            cam.rect             = new Rect(0, 0, 1, 1);
            cam.orthographic     = true;
            cam.gameObject.SetActive(true);
            cameras.Add(cam);

            await UniTask.WaitForEndOfFrame();

            // Update all object positions & rotations according to this new camera pos
            var objects = Controller.obj.levelController.Objects;
            foreach (var obj in objects)
            {
                obj.UpdatePosition3D();
            }
        }
        await UniTask.WaitForEndOfFrame();

        byte[] screenshotBytes = null;
        var    lScreenshot     = zzTransparencyCapture.CaptureScreenshot(width * cellSize, height * cellSize, isTransparent, camera: cameras.ToArray());

        foreach (var cam in cameras)
        {
            camSettings[cam].Apply(cam);
        }
        ec.enabled = true;
        try
        {
            if (rect != null)
            {
                lScreenshot = lScreenshot.Crop(rect.Value, true);
            }

            screenshotBytes = lScreenshot.EncodeToPNG();
        } finally {
            Object.DestroyImmediate(lScreenshot);
        }
        if (isTransparent)
        {
            Controller.obj.levelController.controllerTilemap.backgroundTint.gameObject.SetActive(true);
        }
        Debug.Log("Screenshot saved.");
        return(screenshotBytes);
    }