增加音频功能

This commit is contained in:
shenjianxing 2024-12-17 09:49:59 +08:00
parent 46fb891186
commit 1e322942c5
6 changed files with 32 additions and 4 deletions

View File

@ -131,7 +131,7 @@ public class ActionHelper
case "TextTip": case "TextTip":
{ {
var strAction = (XMLTool.StringListAction)act; var strAction = (XMLTool.StringListAction)act;
return TextTipAction.Allocate(act.Value, strAction.args[0]); return TextTipAction.Allocate(act.Value, strAction.args[0], strAction.args[1]);
} }
case "UIShow": case "UIShow":
{ {

View File

@ -17,7 +17,8 @@ public class TextTipAction : IAction
new SimpleObjectPool<TextTipAction>(() => new TextTipAction(), null, 10); new SimpleObjectPool<TextTipAction>(() => new TextTipAction(), null, 10);
string text = string.Empty; string text = string.Empty;
string btns = string.Empty; string btns = string.Empty;
public static TextTipAction Allocate(string text, string btns, System.Action onDelayFinish = null) string audio = string.Empty;
public static TextTipAction Allocate(string text,string audio , string btns, System.Action onDelayFinish = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.ActionID = ActionKit.ID_GENERATOR++;
@ -25,6 +26,7 @@ public class TextTipAction : IAction
retNode.Reset(); retNode.Reset();
retNode.text = text; retNode.text = text;
retNode.btns = btns; retNode.btns = btns;
retNode.audio = audio;
return retNode; return retNode;
} }
@ -52,6 +54,7 @@ public class TextTipAction : IAction
UITextTipData data = new UITextTipData(); UITextTipData data = new UITextTipData();
data.text = text; data.text = text;
data.btns = btns.Split(',').ToList(); data.btns = btns.Split(',').ToList();
data.audio = audio;
UIKit.OpenPanelAsync<UITextTip>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish()); UIKit.OpenPanelAsync<UITextTip>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
} }

View File

@ -68,6 +68,7 @@ namespace QFramework.Example
protected override void OnClose() protected override void OnClose()
{ {
SetItem(0); SetItem(0);
loader.Recycle2Cache();
} }
} }
} }

View File

@ -9,11 +9,12 @@ namespace QFramework.Example
public class UITextTipData : UIPanelData public class UITextTipData : UIPanelData
{ {
public string text; public string text;
public string audio;
public List<string> btns; public List<string> btns;
} }
public partial class UITextTip : UIPanel public partial class UITextTip : UIPanel
{ {
ResLoader loader;
protected override void OnInit(IUIData uiData = null) protected override void OnInit(IUIData uiData = null)
{ {
@ -36,6 +37,19 @@ namespace QFramework.Example
Hide(); 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();
}
} }
protected override void OnShow() protected override void OnShow()
@ -48,6 +62,7 @@ namespace QFramework.Example
protected override void OnClose() protected override void OnClose()
{ {
loader.Recycle2Cache();
} }
} }
} }

View File

@ -551,6 +551,15 @@ namespace XMLTool
case "TextTip": case "TextTip":
{ {
var act = new StringListAction(); var act = new StringListAction();
XAttribute audio = action.Attribute("audio");
if (audio != null)
{
act.args.Add(audio.Value);
}
else
{
act.args.Add("");
}
XAttribute btns = action.Attribute("btns"); XAttribute btns = action.Attribute("btns");
if (btns != null) if (btns != null)
{ {

View File

@ -733,7 +733,7 @@
</Reset> </Reset>
<Start> <Start>
<Action type="Sequence"> <Action type="Sequence">
<Action type="TextTip" value="这里是文字描述" btns="确定,取消"/> <Action type="TextTip" value="这里是文字描述" audio="q001.mp3" btns="确定,取消"/>
<Action type="Move" value="Main Camera" to="-3.206,3.24,-1.425" time="0"></Action> <Action type="Move" value="Main Camera" to="-3.206,3.24,-1.425" time="0"></Action>
<Action type="Rotate" value="Main Camera" to="27.9597,270,2.899792E-06" time="0"></Action> <Action type="Rotate" value="Main Camera" to="27.9597,270,2.899792E-06" time="0"></Action>
<Action type="Btns" value="下一步"></Action> <Action type="Btns" value="下一步"></Action>