89 lines
2.0 KiB
C#
Raw Normal View History

2024-12-14 18:27:59 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using System;
using QFramework.Example;
public class UIShowAction : 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<UIShowAction> mPool =
new SimpleObjectPool<UIShowAction>(() => new UIShowAction(), null, 10);
string uiName = string.Empty;
bool isShow = true;
public static UIShowAction Allocate(string uiName, string isShow = "true", System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.uiName = uiName;
bool.TryParse(isShow, out retNode.isShow);
return retNode;
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
mPool.Recycle(this);
}
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void OnStart()
{
2025-02-07 09:40:55 +08:00
Type type = null;
if (ActionHelper.typeDict.ContainsKey(uiName))
2024-12-14 18:27:59 +08:00
{
2025-02-07 09:40:55 +08:00
type = ActionHelper.typeDict[uiName];
}
else if (CustomUIMap.typeDict.ContainsKey(uiName))
{
type = CustomUIMap.typeDict[uiName];
}
if (type == null)
{
Debug.LogError($"{uiName} <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD>");
2024-12-14 18:27:59 +08:00
}
else
{
2025-02-07 09:40:55 +08:00
if (isShow)
2024-12-30 16:42:29 +08:00
{
2025-02-07 09:40:55 +08:00
UIKit.OpenPanelAsync(type, assetBundleName: uiName).ToAction().StartGlobal(() => this.Finish());
2024-12-30 16:42:29 +08:00
}
2025-02-07 09:40:55 +08:00
else
{
if (UIKit.GetPanel(type) != null)
{
UIKit.HidePanel(type);
}
2024-12-30 16:42:29 +08:00
2025-02-07 09:40:55 +08:00
this.Finish();
}
2024-12-14 18:27:59 +08:00
}
2025-02-07 09:40:55 +08:00
2024-12-14 18:27:59 +08:00
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
}