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.
139 lines
4.0 KiB
139 lines
4.0 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using FFmpeg.Demo.REC; |
|
|
|
public class RecSavePanel : MonoBehaviour |
|
{ |
|
//public string Name; |
|
public Button SureButton; |
|
public Button CancelButton; |
|
public Text WarnText; |
|
public InputField NameInput; |
|
public FFmpegREC FFmpegREC; |
|
public string BeginTime; |
|
[SerializeField] |
|
private string path; |
|
[SerializeField] |
|
private string ModeFilePath; |
|
[SerializeField] |
|
private string RoomFilePath; |
|
public Text TipText; |
|
/// <summary> |
|
/// 文件视频命名规则为:房间名_创建者_输入名_开始时间(秒) |
|
/// 存放路径为:streamingAssetsPath/RECFile/模式/房间id/ |
|
/// </summary> |
|
[SerializeField] |
|
private string FileName; |
|
|
|
private void OnDisable() |
|
{ |
|
NameInput.text = ""; |
|
SureButton.interactable = true; |
|
CancelButton.interactable = true; |
|
TipText.gameObject.SetActive(false); |
|
WarnText.gameObject.SetActive(false); |
|
} |
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
if (GameSettings.othersSettings.mode==Mode.DisasterManagement) |
|
{ |
|
gameObject.SetActive(false); |
|
return; |
|
} |
|
SureButton.onClick.AddListener(SureClick); |
|
CancelButton.onClick.AddListener(CancelClick); |
|
path = Application.streamingAssetsPath; |
|
path += "/RECFile"; |
|
ModeFilePath =Path.Combine(path , GameSettings.othersSettings.mode.ToString()); |
|
RoomFilePath =Path.Combine( ModeFilePath ,CurrentUserInfo.room.Id.ToString()); |
|
gameObject.SetActive(false); |
|
} |
|
private void OnDestroy() |
|
{ |
|
NameInput.text = ""; |
|
SureButton.interactable = true; |
|
SureButton.interactable = true; |
|
SureButton.onClick.RemoveListener(SureClick); |
|
CancelButton.onClick.RemoveListener(CancelClick); |
|
} |
|
|
|
void SureClick() |
|
{ |
|
WarnText.gameObject.SetActive(false); |
|
//if (!GameSettings.othersSettings.IsStartDrill) |
|
//{ |
|
// WarnText.gameObject.SetActive(true); |
|
// WarnText.text = "请先开始演练!"; |
|
//} |
|
if (string.IsNullOrEmpty(NameInput.text)) |
|
{ |
|
WarnText.gameObject.SetActive(true); |
|
WarnText.text = "文件名不可为空"; |
|
return; |
|
} |
|
|
|
if (!Directory.Exists(path)) |
|
{ |
|
Directory.CreateDirectory(path); |
|
} |
|
if (!Directory.Exists(ModeFilePath)) |
|
{ |
|
Directory.CreateDirectory(ModeFilePath); |
|
} |
|
if (!Directory.Exists(RoomFilePath)) |
|
{ |
|
Directory.CreateDirectory(RoomFilePath); |
|
} |
|
//防止多次点击 |
|
SureButton.interactable = false; |
|
CancelButton.interactable = false; |
|
TipText.gameObject.SetActive(true); |
|
TipText.text = "保存中..."; |
|
FFmpegREC.CreateVideo(); |
|
|
|
|
|
} |
|
public string GetInputName() |
|
{ |
|
return NameInput.text; |
|
} |
|
/// <summary> |
|
/// 获取保存路径 |
|
/// </summary> |
|
/// <returns></returns> |
|
public string GetSavePath() |
|
{ |
|
string[] time = BeginTime.Split(':'); |
|
int Second = int.Parse(time[0]) * 3600 + int.Parse(time[1]) * 60 + int.Parse(time[2]); |
|
FileName = CurrentUserInfo.room.Name + "_" +CurrentUserInfo.mySelf.RealName+"_"+ NameInput.text + "_" + Second.ToString(); |
|
return FileName; |
|
} |
|
public string GetRoomFilePath() |
|
{ |
|
if (!Directory.Exists(RoomFilePath)) |
|
{ |
|
Directory.CreateDirectory(RoomFilePath); |
|
} |
|
return RoomFilePath; |
|
} |
|
void CancelClick() |
|
{ |
|
gameObject.SetActive(false); |
|
} |
|
public void SetTip(string Tip) |
|
{ |
|
TipText.gameObject.SetActive(true); |
|
TipText.text = Tip; |
|
StartCoroutine(Close()); |
|
} |
|
IEnumerator Close() |
|
{ |
|
yield return new WaitForSeconds(1f); |
|
if (gameObject.activeInHierarchy) |
|
gameObject.SetActive(false); |
|
} |
|
}
|
|
|