Skip to content

Commit 5eb46e7

Browse files
committed
Add Settings to Camera
1 parent 1034d2a commit 5eb46e7

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

CameraScreenShot/.idea/.idea.CameraScreenShot/.idea/indexLayout.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CameraScreenShot/00000000.png

-30.2 KB
Binary file not shown.

CameraScreenShot/Assets/Recorder/RenderTexture/RenderTexture.renderTexture

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ RenderTexture:
1313
m_ForcedFallbackFormat: 4
1414
m_DownscaleFallback: 0
1515
serializedVersion: 3
16-
m_Width: 2180
17-
m_Height: 1080
16+
m_Width: 760
17+
m_Height: 561
1818
m_AntiAliasing: 1
1919
m_MipCount: -1
2020
m_DepthFormat: 2

CameraScreenShot/Assets/Recorder/Scripts/VideoRecorder.cs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
using UnityEngine;
22
using System.IO;
33

4+
public enum QualityCam
5+
{
6+
PNG,JPG
7+
}
48
[RequireComponent(typeof(Camera))]
5-
public class VideoRecorder : MonoBehaviour {
6-
7-
8-
public int frameRate = 30;
9+
public class VideoRecorder : MonoBehaviour
10+
{
11+
public QualityCam QualityOfCam;
912
public RenderTexture VideoTexture;
1013
Camera ScrnCam;
1114
float Width=Screen.width;
1215
float Height=Screen.height;
1316
private string dataPath;
17+
public bool UseScreenSize=true;
18+
1419
#region VideoCapt
20+
public int frameRate = 30;
1521
bool isCapturing = false;
1622
string path;
1723
int folderIndex = 0;
1824
int imgIndex = 0;
1925
float localDeltaTime,prevTime,fixedDeltaTimeCache;
20-
2126
#endregion
2227

2328
private void Awake()
@@ -27,10 +32,19 @@ private void Awake()
2732
ScrnCam = GetComponent<Camera>();
2833
if (VideoTexture == null)
2934
{
30-
Debug.Log("Создайте текстуру для рендера!");
35+
Debug.Log("Создайте текстуру для рендера! \n Create a texture for the render!");
3136
}
32-
Width = VideoTexture.width;
33-
Height = VideoTexture.height;
37+
if (!UseScreenSize)
38+
{
39+
Width = VideoTexture.width;
40+
Height = VideoTexture.height;
41+
}
42+
else
43+
{
44+
VideoTexture.width = (int) Width;
45+
VideoTexture.height = (int) Height;
46+
}
47+
3448
ScrnCam.gameObject.SetActive(false);
3549
//если нет директории сохранения файла
3650
bool exists = System.IO.Directory.Exists(dataPath);
@@ -63,12 +77,23 @@ void LateUpdate () {
6377

6478
if (ScrnCam.gameObject.activeInHierarchy){
6579
localDeltaTime = Time.realtimeSinceStartup - prevTime;
66-
prevTime = Time.realtimeSinceStartup;
80+
prevTime = Time.realtimeSinceStartup;
81+
Texture2D Shot = ToTexture2D(VideoTexture);
6782
//перевод текстуры в картинку
68-
Texture2D Shot =ToTexture2D(VideoTexture);
69-
byte[] bytes = Shot.EncodeToPNG();
70-
string filename = path+imgIndex.ToString("D8")+".png";
71-
File.WriteAllBytes(filename, bytes);
83+
if ( QualityOfCam == QualityCam.PNG)
84+
{
85+
byte[] bytes = Shot.EncodeToPNG();
86+
string filename = path+imgIndex.ToString("D8")+".png";
87+
File.WriteAllBytes(filename, bytes);
88+
}
89+
else
90+
{
91+
byte[] bytes = Shot.EncodeToJPG();
92+
string filename = path+imgIndex.ToString("D8")+".jpg";
93+
File.WriteAllBytes(filename, bytes);
94+
}
95+
//декодируем в png, для наивышего качества
96+
7297
imgIndex+=1;
7398
Time.timeScale = 1.0f/localDeltaTime/frameRate;
7499
//Time.fixedDeltaTime = fixedDeltaTimeCache / Time.timeScale;

0 commit comments

Comments
 (0)