NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_ChoosePersonController.cs

200 lines
5.5 KiB
C#
Raw Normal View History

using Code.Scripts.Gameplay.Game;
2024-06-19 13:17:09 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2024-06-19 13:17:09 +08:00
using Gameplay;
2025-03-27 15:46:09 +08:00
using Gameplay.HeroSelect;
2024-06-19 13:17:09 +08:00
using Gameplay.Net;
using Gameplay.Story;
2024-06-19 15:44:06 +08:00
using Gameplay.Utils;
2024-06-19 13:17:09 +08:00
using PhxhSDK;
2025-04-02 14:37:16 +08:00
using System;
2024-06-19 13:17:09 +08:00
using UnityEngine;
using UnityEngine.UI;
2024-06-19 15:44:06 +08:00
using Object = UnityEngine.Object;
2024-06-19 13:17:09 +08:00
/// <summary>
/// 选人UI
/// </summary>
public class UI_ChoosePersonController : UIWindow
{
/// <summary>
/// 打开选人界面
/// </summary>
/// <returns></returns>
2025-04-02 14:37:16 +08:00
public static async UniTask<UIWindow> Open(Action callback)
2024-06-19 13:17:09 +08:00
{
2024-09-18 16:03:02 +08:00
CommonUtils.CaptureScreenshot(); // 截取当前屏幕截图
2024-06-19 13:17:09 +08:00
2025-04-02 14:37:16 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_ChoosePerson, callback);
2024-06-19 13:17:09 +08:00
}
2024-06-19 15:44:06 +08:00
#region UI
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
/// <summary>
/// 形象1按钮
/// </summary>
private Button buttonModel1;
/// <summary>
/// 形象2按钮
/// </summary>
private Button buttonModel2;
/// <summary>
/// 确定按钮
/// </summary>
private Button buttonConfirm;
/// <summary>
/// 选中状态1
/// </summary>
private GameObject goSelect1;
/// <summary>
/// 选中状态2
/// </summary>
private GameObject goSelect2;
#endregion
2024-06-19 13:17:09 +08:00
2024-09-09 18:48:36 +08:00
private const string ANIM_STATE = "IsSelect";
2024-06-19 15:44:06 +08:00
/// <summary>
2024-09-09 18:48:36 +08:00
/// 模型1
2024-06-19 15:44:06 +08:00
/// </summary>
2024-09-09 18:48:36 +08:00
private GameObject goModel1;
2024-06-19 15:44:06 +08:00
/// <summary>
2024-09-09 18:48:36 +08:00
/// 模型2
2024-06-19 15:44:06 +08:00
/// </summary>
2024-09-09 18:48:36 +08:00
private GameObject goModel2;
private Animator animator1;
private Animator animator2;
2024-06-19 15:44:06 +08:00
/// <summary>
/// 选择的模型id
/// </summary>
private int selectModelId;
2025-04-02 14:37:16 +08:00
private Action callbackAction;
2024-06-19 15:44:06 +08:00
public override void OnInit()
{
2024-06-19 13:17:09 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
2024-06-19 15:44:06 +08:00
buttonModel1 = GetComponent<Button>("Image_BG/ButtonModel1");
buttonModel2 = GetComponent<Button>("Image_BG/ButtonModel2");
buttonConfirm = GetComponent<Button>("Image_BG/Button_Confirm");
goSelect1 = FindObj("Image_BG/ButtonModel1/ImageSelect");
goSelect2 = FindObj("Image_BG/ButtonModel2/ImageSelect");
2024-09-09 18:48:36 +08:00
goModel1 = FindObj("Image_BG/ButtonModel1/P_S_N00004");
goModel2 = FindObj("Image_BG/ButtonModel2/P_S_N00005");
animator1 = GetComponent<Animator>("Image_BG/ButtonModel1/P_S_N00004/N00004");
animator2 = GetComponent<Animator>("Image_BG/ButtonModel2/P_S_N00005/N00005");
2024-06-19 13:17:09 +08:00
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-06-19 15:44:06 +08:00
selectModelId = 0;
2024-09-09 18:48:36 +08:00
goModel1.SetLayerEx(5);
goModel2.SetLayerEx(5);
animator1.SetBool(ANIM_STATE, false);
animator2.SetBool(ANIM_STATE, false);
2024-06-19 15:44:06 +08:00
OnModel(0);
goSelect1.gameObject.IsScaleShow(false);
goSelect2.gameObject.IsScaleShow(false);
BindButton(buttonModel1, () =>
{
2025-03-27 15:46:09 +08:00
OnModel(HeroSelectManager.HERO_ID_1);
2024-06-19 15:44:06 +08:00
});
BindButton(buttonModel2, () =>
{
2025-03-27 15:46:09 +08:00
OnModel(HeroSelectManager.HERO_ID_2);
2024-06-19 15:44:06 +08:00
});
BindButton(buttonConfirm, OnConfirm);
2024-06-19 13:17:09 +08:00
EventManager.Instance.Register<string>(EventManager.EventName.UIOpen, OnUIOpen);
EventManager.Instance.Register<string>(EventManager.EventName.UIClose, OnUIClose);
2025-04-02 14:37:16 +08:00
EventManager.Instance.Register(EventManager.EventName.SetPlayerMode, OnClose);
}
protected override void OnShowWindow(object data)
{
base.OnShowWindow(data);
if (data is Action callback)
callbackAction = callback;
2024-06-19 13:17:09 +08:00
}
public override void OnRelease()
2024-06-19 13:17:09 +08:00
{
2025-04-02 14:37:16 +08:00
EventManager.Instance.Unregister(EventManager.EventName.SetPlayerMode, OnClose);
EventManager.Instance.Unregister<string>(EventManager.EventName.UIClose, OnUIClose);
EventManager.Instance.Unregister<string>(EventManager.EventName.UIOpen, OnUIOpen);
2024-06-19 13:17:09 +08:00
base.OnRelease();
2024-06-19 13:17:09 +08:00
}
#region 回调方法
2024-06-19 13:17:09 +08:00
/// <summary>
/// 关闭
/// </summary>
private void OnClose()
{
2025-04-02 14:37:16 +08:00
callbackAction?.Invoke();
2024-06-19 13:17:09 +08:00
CloseWindow();
}
2024-06-19 15:44:06 +08:00
/// <summary>
/// 选择模型
/// </summary>
/// <param name="i"></param>
private void OnModel(int id)
{
selectModelId = id;
buttonConfirm.interactable = 0 != selectModelId;
2025-03-27 15:46:09 +08:00
if (HeroSelectManager.HERO_ID_1 == id)
{
animator1.SetBool(ANIM_STATE, true);
animator2.SetBool(ANIM_STATE, false);
goSelect1.gameObject.IsScaleShow(true);
goSelect2.gameObject.IsScaleShow(false);
}
2025-03-27 15:46:09 +08:00
else if(HeroSelectManager.HERO_ID_2 == id)
{
animator1.SetBool(ANIM_STATE, false);
animator2.SetBool(ANIM_STATE, true);
goSelect1.gameObject.IsScaleShow(false);
goSelect2.gameObject.IsScaleShow(true);
}
2024-06-19 15:44:06 +08:00
}
/// <summary>
/// 确定选择
/// </summary>
private void OnConfirm()
{
2025-03-27 16:05:17 +08:00
NetHelper.SetPlayeAvatar(selectModelId);
}
private void OnUIOpen(string uiName)
{
if (UINameConst.UI_ChoosePerson == uiName)
return;
if (UINameConst.UI_Guide == uiName)
return;
buttonModel1.gameObject.SetActive(false);
buttonModel2.gameObject.SetActive(false);
}
private void OnUIClose(string uiName)
{
if (UINameConst.UI_ChoosePerson == uiName)
return;
if (UINameConst.UI_Guide == uiName)
return;
buttonModel1.gameObject.SetActive(true);
buttonModel2.gameObject.SetActive(true);
OnModel(selectModelId);
}
2024-06-19 13:17:09 +08:00
#endregion
}