194 lines
4.7 KiB
C#
Raw Normal View History

2025-05-14 18:28:46 +08:00
using System;
2024-12-14 18:27:59 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
2024-12-30 19:15:34 +08:00
using static OperationController;
2025-05-14 18:28:46 +08:00
using TMPro;
2025-05-12 17:26:46 +08:00
using System.IO;
2024-12-14 18:27:59 +08:00
namespace QFramework.Example
{
public class UITipWindowData : UIPanelData
{
public class ItemData
{
public string txt;
public Action OnClick;
}
2025-05-12 17:26:46 +08:00
public string ExportVideoPath;
2024-12-14 18:27:59 +08:00
public string txt;
2025-01-08 16:02:57 +08:00
public string audio;
2024-12-14 18:27:59 +08:00
public List<ItemData> btns = new List<ItemData>();
}
public partial class UITipWindow : UIPanel
{
2025-01-08 16:02:57 +08:00
ResLoader loader;
2024-12-14 18:27:59 +08:00
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UITipWindowData ?? new UITipWindowData();
// please add init code here
2025-01-09 09:43:15 +08:00
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
2024-12-30 19:15:34 +08:00
}
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
2024-12-14 18:27:59 +08:00
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UITipWindowData ?? new UITipWindowData();
2025-01-09 13:35:04 +08:00
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
2025-03-25 10:46:22 +08:00
if (mData.txt.Contains("{Score}"))
{
mData.txt = mData.txt.Replace("{Score}", ScoreController.Instance.GetCurScore().ToString());
}
2024-12-14 18:27:59 +08:00
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;
2025-01-08 16:02:57 +08:00
obj.name = item.txt;
2024-12-14 18:27:59 +08:00
obj.GetComponent<Button>().onClick.AddListener(() =>
{
item.OnClick?.Invoke();
Hide();
});
}
}
2025-01-08 16:02:57 +08:00
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();
}
2025-05-12 17:26:46 +08:00
2025-05-14 18:28:46 +08:00
transform.SetAsLastSibling();
ExportVideo();
2024-12-14 18:27:59 +08:00
}
2025-05-14 18:28:46 +08:00
2024-12-14 18:27:59 +08:00
protected override void OnShow()
{
}
protected override void OnHide()
{
2025-01-08 16:02:57 +08:00
AudioKit.StopVoice();
2024-12-14 18:27:59 +08:00
}
protected override void OnClose()
{
2025-01-08 16:02:57 +08:00
loader.Recycle2Cache();
2025-05-12 17:26:46 +08:00
2025-05-14 18:28:46 +08:00
}
private void ExportVideo()
{
Debug.Log("????????"+mData.ExportVideoPath+"????????");
if (!string.IsNullOrEmpty(mData.ExportVideoPath))
2025-05-12 17:26:46 +08:00
{
string OutPath = "";
string filePath = ChinarFileController.SaveProject(OutPath);
string sourcePath = Global.videoPath + mData.ExportVideoPath;
#if UNITY_WEBGL && !UNITY_EDITOR
2025-05-14 18:29:55 +08:00
WebGLDownLoadFile.Instance.DownloadVideo(url,sourcePath);
2025-05-12 17:26:46 +08:00
#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}");
}
2025-05-14 18:28:46 +08:00
#endif
2025-05-12 17:26:46 +08:00
}
else
{
2025-05-14 18:28:46 +08:00
Debug.Log(mData.ExportVideoPath+"????");
Debug.Log("<22><><EFBFBD><EFBFBD>????");
2025-05-12 17:26:46 +08:00
}
2025-05-14 18:28:46 +08:00
}
2025-05-12 17:26:46 +08:00
2024-12-14 18:27:59 +08:00
}
2025-05-14 18:28:46 +08:00
2024-12-14 18:27:59 +08:00
}
2025-05-14 18:28:46 +08:00