using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Text.RegularExpressions;
using System.IO;
public class TKVideoAndTextureRecordManager : MonoBehaviour
{
public static TKVideoAndTextureRecordManager TKVideoAndTextureRecordManagerInstance;
public RawImage cameraTexture;
public WebCamTexture webCameraTexture;
//public Button SaveButton;
public int captureid = 0;
long[] listLocalVideos;
long currenyListLocalVideosPathID;
public int CurrentItemID;
private void Awake()
{
}
IEnumerator Start()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[] devices = WebCamTexture.devices;
string devicename = devices[0].name;
webCameraTexture = new WebCamTexture(devicename, Screen.width, Screen.height);
cameraTexture.texture =webCameraTexture;
webCameraTexture.Play();
}
//OnBindEvent();
//SaveButton.enabled = false;
//Debug.LogError("666");
}
启用此本脚本就启用摄像头
private void OnEnable()
{
//if (TKDeviceInformationManagerRef != null)
//{
// captureid = TKDeviceInformationManagerRef.CurrentTextureID;
//}
if (Application.HasUserAuthorization(UserAuthorization.WebCam) && webCameraTexture != null)
{
webCameraTexture.Play();
}
}
//禁用此脚本时停止摄像头
private void OnDisable()
{
if (Application.HasUserAuthorization(UserAuthorization.WebCam) && webCameraTexture != null)
{
webCameraTexture.Stop();
}
}
void Update()
{
//ScreenChange();
}
int width;
///
/// 横竖屏切换
///
void ScreenChange()
{
if (width == Screen.width)
return;
width = Screen.width;
if (width > Screen.height)
{
cameraTexture.transform.localEulerAngles = Vector3.zero;
}
else
{
cameraTexture.transform.localEulerAngles = new Vector3(0, 0, -90);
}
}
///
/// 切换手机前后摄像头
///
///
void changeCam(bool isOn)
{
StartCoroutine(CallCamera(isOn));
}
IEnumerator CallCamera(bool isOn)
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
if (webCameraTexture != null)
webCameraTexture.Stop();
WebCamDevice[] cameraDevices = WebCamTexture.devices;
string deviceName = "";
for (int i = 0; i < cameraDevices.Length; i++)
{
//如果是前置摄像机??
if (WebCamTexture.devices[i].isFrontFacing && isOn)
{
deviceName = WebCamTexture.devices[i]