You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
5.1 KiB
177 lines
5.1 KiB
2 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using UnityEngine.UI;
|
||
|
using FFmpeg.Demo.REC;
|
||
|
using System;
|
||
|
using System.IO;
|
||
|
using System.Reflection;
|
||
|
using Newtonsoft;
|
||
|
|
||
|
public class RecPanel : MonoBehaviour
|
||
|
{
|
||
|
public Button StartButton;
|
||
|
public Button StopButton;
|
||
|
public Text RecordTimeText;
|
||
|
private int RecordTime;
|
||
|
public FFmpegREC recLogic;
|
||
|
public RecSavePanel RecSavePanel;
|
||
|
private Color OriginalColor;
|
||
|
void Awake()
|
||
|
{
|
||
|
OriginalColor = StartButton.GetComponent<Image>().color;
|
||
|
StartButton.onClick.AddListener(OnStart);
|
||
|
StopButton.onClick.AddListener(OnStop);
|
||
|
RecordTimeText.text = "00:00:00";
|
||
|
RecordTime = 0;
|
||
|
MessageDispatcher.AddListener("StartDrillValueChange",BeginSet);
|
||
|
gameObject.SetActive(false);
|
||
|
}
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
StartButton.onClick.RemoveListener(OnStart);
|
||
|
StopButton.onClick.RemoveListener(OnStop);
|
||
|
MessageDispatcher.RemoveListener("StartDrillValueChange", BeginSet);
|
||
|
}
|
||
|
|
||
|
private void BeginSet(IMessage obj)
|
||
|
{
|
||
|
bool isbegin = (bool)obj.Data;
|
||
|
if (isbegin)
|
||
|
{
|
||
|
// if ((CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id))
|
||
|
{
|
||
|
if (!gameObject.activeInHierarchy)
|
||
|
{
|
||
|
gameObject.SetActive(true);
|
||
|
recLogic.Init(Output, Finish);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//else
|
||
|
//{
|
||
|
// if (gameObject.activeInHierarchy)
|
||
|
// {
|
||
|
// if (recLogic.isREC)
|
||
|
// {
|
||
|
// recLogic.StopREC();
|
||
|
// }
|
||
|
// gameObject.SetActive(false);
|
||
|
// }
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
public void OnStart()
|
||
|
{
|
||
|
if (!GameSettings.othersSettings.IsStartDrill)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
StartButton.interactable = false;
|
||
|
StopButton.interactable = true;
|
||
|
StartButton.GetComponent<Image>().color = Color.red;
|
||
|
RecordTimeText.text = "00:00:00";
|
||
|
RecordTime = 0;
|
||
|
recLogic.StartREC();
|
||
|
StartCoroutine(Time());
|
||
|
}
|
||
|
private IEnumerator Time()
|
||
|
{
|
||
|
while (recLogic.isREC)
|
||
|
{
|
||
|
yield return new WaitForSeconds(1f);
|
||
|
RecordTime++;
|
||
|
string ht = "";
|
||
|
int h = (int)(RecordTime / 3600);
|
||
|
if (h < 10)
|
||
|
{
|
||
|
ht = "0" + h;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ht = h.ToString();
|
||
|
}
|
||
|
string mt = "";
|
||
|
int m = (int)(RecordTime - h * 3600) / 60;
|
||
|
if (m < 10)
|
||
|
{
|
||
|
mt = "0" + m;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mt = m.ToString();
|
||
|
}
|
||
|
int s = RecordTime - h * 3600 - m * 60;
|
||
|
string st = "";
|
||
|
if (s < 10)
|
||
|
{
|
||
|
st = "0" + s;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
st = s.ToString();
|
||
|
}
|
||
|
RecordTimeText.text = ht + ":" + mt+ ":" + st;
|
||
|
}
|
||
|
}
|
||
|
//------------------------------
|
||
|
|
||
|
public void OnStop()
|
||
|
{
|
||
|
StopButton.interactable = false;
|
||
|
StartButton.GetComponent<Image>().color = OriginalColor;
|
||
|
recLogic.StopREC();
|
||
|
StopCoroutine(Time());
|
||
|
}
|
||
|
|
||
|
void Output(string msg)
|
||
|
{
|
||
|
//string newOutput = output.text + msg;
|
||
|
//if (newOutput.Length > charsLimit)
|
||
|
// newOutput = newOutput.Remove(0, newOutput.Length - charsLimit);
|
||
|
//output.text = newOutput;
|
||
|
}
|
||
|
|
||
|
public void Finish(string outputVideo)
|
||
|
{
|
||
|
StartButton.interactable = true;
|
||
|
Debug.Log("Video saved to: " + outputVideo);
|
||
|
//string localURL = "file://" + outputVideo;
|
||
|
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
|
||
|
Handheld.PlayFullScreenMovie(
|
||
|
localURL,
|
||
|
Color.black,
|
||
|
FullScreenMovieControlMode.Full,
|
||
|
FullScreenMovieScalingMode.AspectFit);
|
||
|
#else
|
||
|
if (File.Exists(outputVideo))
|
||
|
{
|
||
|
string filePath = Path.GetDirectoryName(outputVideo);
|
||
|
string newFilePath = Path.Combine(filePath, RecSavePanel.GetSavePath()) + ".mp4";
|
||
|
|
||
|
File.Move(outputVideo, newFilePath);
|
||
|
VideoData data = new VideoData();
|
||
|
data.Url = newFilePath;
|
||
|
data.Mode = GameSettings.othersSettings.mode.ToString();
|
||
|
data.RoomId = CurrentUserInfo.room.Id.ToString();
|
||
|
data.RoomName = CurrentUserInfo.room.Name;
|
||
|
data.Creator = CurrentUserInfo.mySelf.RealName;
|
||
|
data.Name = RecSavePanel.GetInputName();
|
||
|
data.RecoedTime = RecordTimeText.text;
|
||
|
VideoFileCtrl.Instance.AddVideoDatasToJson(data,GameSettings.othersSettings.mode.ToString());
|
||
|
ScreenshotHandler.SetPath(Path.Combine(filePath, RecSavePanel.GetSavePath()) + ".png");
|
||
|
ScreenshotHandler.TakeScreenshot_static();
|
||
|
|
||
|
RecSavePanel.SetTip("录制成功!");
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
//------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
}
|