修改KnowIedgeBug,添加刷新组件前清除一次子项,音频工具添加暂停音频后转到完成状态。添加点击播放,再次点击停止逻辑。

This commit is contained in:
李浩 2025-06-03 13:45:06 +08:00
parent af45dc2d17
commit c3ca663b21
3 changed files with 46 additions and 6 deletions

View File

@ -119,6 +119,8 @@ namespace QFramework
AudioKit.StopAllSound(); AudioKit.StopAllSound();
break; break;
} }
this.Finish();
} }
} }

View File

@ -14,7 +14,8 @@ namespace QFramework.Example
public partial class UIKnowledge : UIPanel public partial class UIKnowledge : UIPanel
{ {
ResLoader loader; ResLoader loader;
Transform content;
Transform subContent;
Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>(); Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();
IAction curAction; IAction curAction;
@ -32,6 +33,8 @@ namespace QFramework.Example
UIKit.OpenPanelAsync<UIModuleSelect>().ToAction().StartGlobal(); UIKit.OpenPanelAsync<UIModuleSelect>().ToAction().StartGlobal();
}); });
} }
protected override void OnOpen(IUIData uiData = null) protected override void OnOpen(IUIData uiData = null)
@ -39,6 +42,7 @@ namespace QFramework.Example
if (Global.Instance.curModule.knowledge != null && Global.Instance.curModule.knowledge.items != null) if (Global.Instance.curModule.knowledge != null && Global.Instance.curModule.knowledge.items != null)
{ {
LeftContent.RemoveAllChildren(); LeftContent.RemoveAllChildren();
GlobalComs.RemoveAllChildren();
string bg = Global.Instance.curModule.knowledge.bgImage; string bg = Global.Instance.curModule.knowledge.bgImage;
LoadBgImage(bg, () => LoadBgImage(bg, () =>
{ {
@ -55,8 +59,10 @@ namespace QFramework.Example
public void ItemFactory(XMLTool.Knowledge.Item itemData, Transform parent = null) public void ItemFactory(XMLTool.Knowledge.Item itemData, Transform parent = null)
{ {
Transform content = parent == null ? LeftContent : parent; Transform content = parent == null ? LeftContent : parent;
GameObject leftObj = GameObject.Instantiate(LeftItem.gameObject, content); GameObject leftObj = GameObject.Instantiate(LeftItem.gameObject, content);
Transform subContent = leftObj.transform.Find("SubContent"); Transform subContent = leftObj.transform.Find("SubContent");
Toggle toggle = leftObj.transform.Find("Toggle").GetComponent<Toggle>(); Toggle toggle = leftObj.transform.Find("Toggle").GetComponent<Toggle>();
TextMeshProUGUI label = toggle.transform.Find("Name").GetComponent<TextMeshProUGUI>(); TextMeshProUGUI label = toggle.transform.Find("Name").GetComponent<TextMeshProUGUI>();
label.text = itemData.title; label.text = itemData.title;
@ -103,6 +109,7 @@ namespace QFramework.Example
/// </summary> /// </summary>
public void RefreshComponents(List<XMLTool.Knowledge.Item.Component> coms, Transform content) public void RefreshComponents(List<XMLTool.Knowledge.Item.Component> coms, Transform content)
{ {
int numIndex = 0;
if (coms != null && coms.Count > 0) if (coms != null && coms.Count > 0)
{ {
foreach (var ComData in coms) foreach (var ComData in coms)
@ -111,6 +118,7 @@ namespace QFramework.Example
{ {
case "Button": case "Button":
GameObject btn = GameObject.Instantiate(BtnPrefab.gameObject, content); GameObject btn = GameObject.Instantiate(BtnPrefab.gameObject, content);
btn.name ="Btn" +numIndex;
btn.GetComponent<RectTransform>().sizeDelta = Utility.GetVector2FromStrArray(ComData.size); btn.GetComponent<RectTransform>().sizeDelta = Utility.GetVector2FromStrArray(ComData.size);
btn.transform.localPosition = Utility.GetVector2FromStrArray(ComData.pos); btn.transform.localPosition = Utility.GetVector2FromStrArray(ComData.pos);
btn.GetComponent<Button>().onClick.AddListener(() => btn.GetComponent<Button>().onClick.AddListener(() =>
@ -126,6 +134,7 @@ namespace QFramework.Example
curAction = null; curAction = null;
}); });
}); });
numIndex++;
break; break;
} }
} }
@ -192,10 +201,12 @@ namespace QFramework.Example
protected override void OnHide() protected override void OnHide()
{ {
AudioKit.StopVoice();
} }
protected override void OnClose() protected override void OnClose()
{ {
AudioKit.StopVoice();
sprites.Clear(); sprites.Clear();
loader.ReleaseAllRes(); loader.ReleaseAllRes();
} }

View File

@ -8,13 +8,26 @@
<FSM name="状态机1"> <FSM name="状态机1">
<State name="初始状态"> <State name="初始状态">
<Enter> <Enter>
<Action type="Parallel"> <Action type="Sequence">
<Action type="UIShow" value="UIKnowledge" isShow="true"></Action> <Action type="UIShow" value="UIKnowledge" isShow="true"></Action>
<Action type="Delay" value="0.1"></Action>
<Action type="Show" value="UIRoot/Common/UIKnowledge/Mask/Bg/Right/Viewport/RightContent/GlobalComs/Btn25" isShow="false" isDevice="false"></Action>
</Action> </Action>
</Enter> </Enter>
<Exit>
<Action type="Sequence">
</Action>
</Exit>
</State> </State>
<!--<Transision from="初始状态" to="状态2"> <!--<Transision from="初始状态" to="状态2">
<Condition type="ObjClick" value="Cube (1)"></Condition> <Condition type="ObjClick" value="Cube (1)"></Condition>
@ -26,6 +39,8 @@
<Item title="项目简介" setPos="0,0"> <Item title="项目简介" setPos="0,0">
<Item title="实验名称" bgImage="" setPos="0,67.59607" > <Item title="实验名称" bgImage="" setPos="0,67.59607" >
<!--<Action type="Audio" audioType="Voice" value="二、shiyanlilunrenzhi/sound_1.mp3" loop="false" waitFinished="false" volumen="1" isPlay="true"></Action>--> <!--<Action type="Audio" audioType="Voice" value="二、shiyanlilunrenzhi/sound_1.mp3" loop="false" waitFinished="false" volumen="1" isPlay="true"></Action>-->
@ -471,11 +486,23 @@
<Action type="Sequence"> <Action type="Sequence">
<Action type="Log" value="播放背景音乐"></Action> <Action type="Log" value="播放背景音乐"></Action>
<Action type="Audio" audioType="Voice" value="BgMusic.mp3" loop="false" waitFinished="false" volumen="1" isPlay="true"></Action> <Action type="Audio" audioType="Voice" value="BgMusic.mp3" loop="false" waitFinished="false" volumen="1" isPlay="true"></Action>
<Action type="Audio" audioType="Voice" value="BgMusic.mp3" loop="false" waitFinished="false" volumen="1" isPlay="false"></Action> <Action type="Show" value="UIRoot/Common/UIKnowledge/Mask/Bg/Right/Viewport/RightContent/GlobalComs/Btn25" isShow="true" isDevice="false"></Action>
<Action type="Log" value="2222222222"></Action> <Action type="Log" value="2222222222"></Action>
</Action> </Action>
</Component> </Component>
<Component type="Button" size="535.0657,137.6156" pos="-23,-10333">
<Action type="Sequence">
<Action type="Log" value="暂停背景音乐"></Action>
<Action type="Show" value="UIRoot/Common/UIKnowledge/Mask/Bg/Right/Viewport/RightContent/GlobalComs/Btn25" isShow="false" isDevice="false"></Action>
<Action type="Show" value="UIRoot/Common/UIKnowledge/Mask/Bg/Right/Viewport/RightContent/GlobalComs/Btn24" isShow="true" isDevice="false"></Action>
<Action type="Audio" audioType="Voice" value="BgMusic.mp3" loop="false" waitFinished="false" volumen="1" isPlay="false"></Action>
<Action type="Log" value="0000000"></Action>
</Action>
</Component>
<!--<Component type="Button" size="535.0657,137.6156" pos="-23,-10333"> <!--<Component type="Button" size="535.0657,137.6156" pos="-23,-10333">
<Action type="Sequence"> <Action type="Sequence">
<Action type="Log" value="暂停背景音乐"></Action> <Action type="Log" value="暂停背景音乐"></Action>
@ -539,8 +566,8 @@
<Action type="Log" value="2222222222"></Action> <Action type="Log" value="2222222222"></Action>
</Action> </Action>
</Component> </Component>
</Knowledge> </Knowledge>