示例#1
0
        /// <summary>
        /// 将UGUI显示的窗口截图,然后缩放到分享的图片的大小,然后分享出去
        /// </summary>
        /// <returns></returns>
        Texture2D CutType1()
        {
            RectInt shareRect = new RectInt(0, 0, (int)cutMark.sizeDelta.x, (int)cutMark.sizeDelta.y);

            Debug.Log(canvas.scaleFactor);
            //获得需要截取的范围
            //Debug.Log(cutMark.position);
            Rect uiRect = new Rect(cutMark.position.x * canvas.scaleFactor, cutMark.position.y * canvas.scaleFactor, cutMark.sizeDelta.x * canvas.scaleFactor, cutMark.sizeDelta.y * canvas.scaleFactor);
            //Rect uiRect = new Rect(0, 0, 100, 100);
            Texture2D uiShot = ScreenCaptureUtil.Capture(uiRect);

            //uiShot.Resize(shareRect.width, shareRect.height);
            //uiShot.Apply();
            Color[]   colors = uiShot.GetPixels();
            Texture2D t      = new Texture2D((int)uiRect.width, (int)uiRect.height);

            t.SetPixels(0, 0, uiShot.width, uiShot.height, colors);

            return(uiShot);
        }
示例#2
0
        private void OnGUI()
        {
            if (_isCaptureScreen)
            {
                //先截取屏幕到指定矩形大小
                var       r  = new Rect(0, 0, 580, 326);
                Texture2D ss = ScreenCaptureUtil.Capture(Camera.main, r);
                screenCut.GetComponent <Image>().sprite = Sprite.Create(ss, r, Vector2.zero);
                _screenShot      = ss;
                _isCaptureScreen = false;
            }

            if (_shareMode > 0)
            {
                Texture2D shareImg = CutType2();
                byte[]    bytes    = shareImg.EncodeToJPG();
                //MultiPlatformUtil.ShareImg(bytes, _shareMode == 1 ? true : false);
                //截取分享的图片
                _shareMode = 0;
            }
        }
示例#3
0
        public void Update()
        {
            if ((EventSystem.current != null && EventSystem.current.currentSelectedGameObject != null))
            {
                return;
            }

            if (Input.GetKeyDown(Config.Key["CAMERA_MENU_KEY"]))
            {
                if (!(CameraManager.GetMachine() != null || Array.Exists(Array.Find(UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(), i => (i.name == "SceneManager")).GetComponents <Component>(), i => i.ToString().Contains("Host"))))
                {
                    return;
                }
                // Cursor [None / Locked] switch
                new AutoPilot().FreeCursor(this.Gui.enabled = !this.Gui.enabled);
            }

            this.Camera.Update();

            if (this.Gui.enabled)
            {
                return;
            }

            this.Light.ListenSwitch();

            if (Input.GetKeyDown(Config.Key["CAMERA_SWITCH_KEY"]))
            {
                if (this.Camera.Enabled() == false)
                {
                    this.Camera.CreateCamera();
                }
                else
                {
                    this.Camera.DestroyCamera();
                }
            }

            if (Input.GetKeyDown(Config.Key["CAMERA_SMOOTH_KEY"]))
            {
                this.Camera.SmoothMove = !this.Camera.SmoothMove;
            }

            if (Input.GetKeyDown(Config.Key["LIGHT_ADD_KEY"]))
            {
                this.Light.Create(CameraManager.GetMachine());
            }

            if (Input.GetKeyDown(Config.Key["HD_SCREENSHOT_KEY"]))
            {
                if (!SanyoLib.DirUtil.Exists(Config.ScreenshotPath))
                {
                    SanyoLib.DirUtil.Create(Config.ScreenshotPath);
                }
                string filePath = string.Format("{0}/{1}.png", Config.ScreenshotPath, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
                if (Config.ScreenshotRenderMode)
                {
                    ScreenCaptureUtil.Capture(filePath, Config.ScreenshotWidth, Config.ScreenshotHeight, this.Camera.Camera, true);
                }
                else
                {
                    Application.CaptureScreenshot(filePath, Config.ScreenshotResolution);
                }
            }
        }