From 86f588515ce945c54f577a30d96f7b6b0a568405 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Wed, 8 Jan 2025 16:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Etipwindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionHelper.cs | 5 ++ Assets/Scripts/Actions/TipWindowAction.cs | 69 +++++++++++++++++++ .../Scripts/Actions/TipWindowAction.cs.meta | 11 +++ Assets/Scripts/UI/UITipWindow.cs | 19 ++++- Assets/Scripts/Xml/XmlParser.cs | 1 + 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/Actions/TipWindowAction.cs create mode 100644 Assets/Scripts/Actions/TipWindowAction.cs.meta diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index a13fb53d..d5a6a328 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -133,6 +133,11 @@ public class ActionHelper var strAction = (XMLTool.DictionaryAction)act; return ShowAction.Allocate(act.Value, strAction.args); } + case "TipWindow": + { + var strAction = (XMLTool.StringListAction)act; + return TipWindowAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); + } case "TextTip": { var strAction = (XMLTool.StringListAction)act; diff --git a/Assets/Scripts/Actions/TipWindowAction.cs b/Assets/Scripts/Actions/TipWindowAction.cs new file mode 100644 index 00000000..e7a5540c --- /dev/null +++ b/Assets/Scripts/Actions/TipWindowAction.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using QFramework; +using System; +using QFramework.Example; +using System.Linq; +public class TipWindowAction : IAction +{ + public ulong ActionID { get; set; } + public bool Deinited { get; set; } + public bool Paused { get; set; } + public ActionStatus Status { get; set; } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new TipWindowAction(), null, 10); + string text = string.Empty; + string btns = string.Empty; + string audio = string.Empty; + public static TipWindowAction Allocate(string text, string audio, string btns, System.Action onDelayFinish = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.text = text; + retNode.btns = btns; + retNode.audio = audio; + return retNode; + } + + + + public void Deinit() + { + if (!Deinited) + { + Deinited = true; + mPool.Recycle(this); + } + } + + public void OnExecute(float dt) + { + } + + public void OnFinish() + { + } + + public void OnStart() + { + UITipWindowData data = new UITipWindowData(); + data.txt = text; + var btnText = btns.Split(',').ToList(); + foreach (var item in btnText) + { + data.btns.Add(new UITipWindowData.ItemData() { txt = item }); + } + data.audio = audio; + UIKit.OpenPanelAsync(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish()); + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + } +} diff --git a/Assets/Scripts/Actions/TipWindowAction.cs.meta b/Assets/Scripts/Actions/TipWindowAction.cs.meta new file mode 100644 index 00000000..c465da72 --- /dev/null +++ b/Assets/Scripts/Actions/TipWindowAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 10573b9b3c343214bb0b5990d11f02f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UITipWindow.cs b/Assets/Scripts/UI/UITipWindow.cs index e4208481..6dde5a40 100644 --- a/Assets/Scripts/UI/UITipWindow.cs +++ b/Assets/Scripts/UI/UITipWindow.cs @@ -16,10 +16,12 @@ namespace QFramework.Example public Action OnClick; } public string txt; + public string audio; public List btns = new List(); } public partial class UITipWindow : UIPanel { + ResLoader loader; protected override void OnInit(IUIData uiData = null) { mData = uiData as UITipWindowData ?? new UITipWindowData(); @@ -44,6 +46,7 @@ namespace QFramework.Example { GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent); obj.transform.Find("Label").GetComponent().text = item.txt; + obj.name = item.txt; obj.GetComponent