新增tipwindow
This commit is contained in:
parent
cdc5a49106
commit
86f588515c
@ -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;
|
||||
|
||||
69
Assets/Scripts/Actions/TipWindowAction.cs
Normal file
69
Assets/Scripts/Actions/TipWindowAction.cs
Normal file
@ -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<TipWindowAction> mPool =
|
||||
new SimpleObjectPool<TipWindowAction>(() => 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<UITipWindow>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Actions/TipWindowAction.cs.meta
Normal file
11
Assets/Scripts/Actions/TipWindowAction.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10573b9b3c343214bb0b5990d11f02f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -16,10 +16,12 @@ namespace QFramework.Example
|
||||
public Action OnClick;
|
||||
}
|
||||
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();
|
||||
@ -44,6 +46,7 @@ namespace QFramework.Example
|
||||
{
|
||||
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();
|
||||
@ -52,7 +55,19 @@ namespace QFramework.Example
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
@ -61,10 +76,12 @@ namespace QFramework.Example
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
AudioKit.StopVoice();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
loader.Recycle2Cache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -693,6 +693,7 @@ namespace XMLTool
|
||||
newAction = act;
|
||||
}
|
||||
break;
|
||||
case "TipWindow":
|
||||
case "TextTip":
|
||||
{
|
||||
var act = new StringListAction();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user