194 lines
4.7 KiB
C#
194 lines
4.7 KiB
C#
using System;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using QFramework;
|
||
using System.Collections.Generic;
|
||
using static OperationController;
|
||
using TMPro;
|
||
using System.IO;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UITipWindowData : UIPanelData
|
||
{
|
||
public class ItemData
|
||
{
|
||
public string txt;
|
||
public Action OnClick;
|
||
}
|
||
public string ExportVideoPath;
|
||
public string txt;
|
||
public string audio;
|
||
public List<ItemData> btns = new List<ItemData>();
|
||
}
|
||
public partial class UITipWindow : UIPanel
|
||
{
|
||
ResLoader loader;
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UITipWindowData ?? new UITipWindowData();
|
||
// please add init code here
|
||
|
||
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||
}
|
||
|
||
private void OnStepChanged(StepStatusOnChange change)
|
||
{
|
||
Hide();
|
||
}
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UITipWindowData ?? new UITipWindowData();
|
||
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
|
||
if (mData.txt.Contains("{Score}"))
|
||
{
|
||
mData.txt = mData.txt.Replace("{Score}", ScoreController.Instance.GetCurScore().ToString());
|
||
}
|
||
Label.text = mData.txt;
|
||
BtnContent.RemoveAllChildren();
|
||
if (mData != null)
|
||
{
|
||
foreach (var item in mData.btns)
|
||
{
|
||
GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent);
|
||
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item.txt;
|
||
obj.name = item.txt;
|
||
obj.GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
item.OnClick?.Invoke();
|
||
Hide();
|
||
});
|
||
}
|
||
|
||
}
|
||
if (string.IsNullOrEmpty(mData.audio) == false)
|
||
{
|
||
string path = Global.audioPath + mData.audio;
|
||
loader = ResLoader.Allocate();
|
||
loader.Add2Load(path.ToLocalAudioResName(), (success, res) =>
|
||
{
|
||
if (success)
|
||
{
|
||
AudioKit.PlayVoice(res.Asset.As<AudioClip>(), false);
|
||
}
|
||
});
|
||
loader.LoadAsync();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
transform.SetAsLastSibling();
|
||
|
||
ExportVideo();
|
||
}
|
||
|
||
|
||
protected override void OnShow()
|
||
{
|
||
}
|
||
|
||
protected override void OnHide()
|
||
{
|
||
AudioKit.StopVoice();
|
||
}
|
||
|
||
protected override void OnClose()
|
||
{
|
||
loader.Recycle2Cache();
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
private void ExportVideo()
|
||
{
|
||
Debug.Log("????????"+mData.ExportVideoPath+"????????");
|
||
if (!string.IsNullOrEmpty(mData.ExportVideoPath))
|
||
{
|
||
|
||
string OutPath = "";
|
||
string filePath = ChinarFileController.SaveProject(OutPath);
|
||
string sourcePath = Global.videoPath + mData.ExportVideoPath;
|
||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||
|
||
|
||
|
||
WebGLDownLoadFile.Instance.DownloadVideo(url,sourcePath);
|
||
|
||
|
||
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
|
||
|
||
try
|
||
{
|
||
// ȷ<><C8B7>Ŀ<EFBFBD><C4BF>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
|
||
string directory = Path.GetDirectoryName(sourcePath);
|
||
if (!Directory.Exists(directory))
|
||
{
|
||
Directory.CreateDirectory(directory);
|
||
}
|
||
|
||
// <20><><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||
File.Copy(sourcePath, filePath, true);
|
||
Debug.Log("<22>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ƴɹ<C6B3><C9B9><EFBFBD>");
|
||
}
|
||
catch (IOException e)
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IO<49>쳣
|
||
Debug.LogError($"<22>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>: {e.Message}");
|
||
|
||
// <20><>ѡ<EFBFBD><D1A1><EFBFBD>ṩ<EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||
if (e.Message.Contains("Sharing violation"))
|
||
{
|
||
Debug.LogError("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD>ԡ<EFBFBD>");
|
||
}
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣
|
||
|
||
Debug.LogError($"<22><><EFBFBD><EFBFBD>δ֪<CEB4><D6AA><EFBFBD><EFBFBD>: {e.Message}");
|
||
}
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
|
||
Debug.Log(mData.ExportVideoPath+"????");
|
||
Debug.Log("<22><><EFBFBD><EFBFBD>????");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|