123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using SUIFW;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- public class jietu : MonoBehaviour
- {
- private Camera screenShotCamera;
- private Texture shots;
- public Transform imageParent;
- public RawImage jietuBG;
- private void Start()
- {
- if (UIMaskMgr.GetInstance()._UICamear)
- {
- screenShotCamera = UIMaskMgr.GetInstance()._UICamear;
- }
- }
- public void ClickJietu()
- {
- if (AgoraVideoAudioManager.Instance.isVideoStream&& screenShotCamera && RoomMainForms.Instance)
- {
-
- RoomMainForms.Instance.CkickOnJieTuBtn();
- PaintLine.canUse = false;
- Rect rect = new Rect(0, 0, Screen.width, Screen.height);
- shots = ScreenShot(screenShotCamera, rect);
-
-
- }
- }
-
-
-
-
- public Texture2D ScreenShot(Camera camera, Rect rect)
- {
- RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
- camera.targetTexture = rt;
- camera.Render();
- RenderTexture.active = rt;
- Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
- screenShot.ReadPixels(rect, 0, 0);
- screenShot.Apply();
- camera.targetTexture = null;
- RenderTexture.active = null;
- GameObject.Destroy(rt);
-
-
-
-
- #if UNITY_EDITOR
- UnityEditor.AssetDatabase.Refresh();
- #endif
- Invoke("CreateImage", 0.5f);
- return screenShot;
-
- }
- void CreateImage()
- {
- if (RoomMainForms.Instance)
- {
- RoomMainForms.Instance.ShowShotsAllBtn();
- }
- GameObject Im = new GameObject();
- Im.name = "jieping";
- Im.transform.SetParent(imageParent, false);
- RawImage rawImage = Im.AddComponent<RawImage>();
- if (shots != null && rawImage)
- {
- rawImage.texture = shots;
- rawImage.rectTransform.sizeDelta = new Vector2(shots.width, shots.height);
- rawImage.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
- rawImage.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
- }
- }
- }
|