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

200 lines
5.6 KiB
C#
Raw Normal View History

using Code.Scripts.Gameplay.Game;
2024-06-19 13:17:09 +08:00
using Cysharp.Threading.Tasks;
using Gameplay;
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;
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>
public static async UniTask<UIWindow> Open()
{
2024-08-13 14:29:50 +08:00
await CommonUtils.CaptureScreenshot(); // 截取当前屏幕截图
2024-06-19 13:17:09 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_ChoosePerson);
}
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-06-19 15:44:06 +08:00
/// <summary>
/// 形象模型名1
/// </summary>
private const string MODEL_NAME_1 = "N00004";
/// <summary>
/// 形象模型名2
/// </summary>
private const string MODEL_NAME_2 = "N00005";
/// <summary>
/// 模型缩放
/// </summary>
private readonly Vector3 MODEL_SCALE = new(260f, 260f, 260f);
/// <summary>
/// 模型位置
/// </summary>
private readonly Vector3 MODEL_POS = new(0f, -185f, -200f);
/// <summary>
/// 模型旋转
/// </summary>
private readonly Quaternion MODEL_ROT = Quaternion.Euler(0f, 180f, 0f);
/// <summary>
/// 选择的模型id
/// </summary>
private int selectModelId;
public override async void PreLoad(object data = null)
{
await AssetManager.Instance.PostPreload<GameObject>(PathEx.GetNpcDisplayModelPath(MODEL_NAME_1));
await AssetManager.Instance.PostPreload<GameObject>(PathEx.GetNpcDisplayModelPath(MODEL_NAME_2));
}
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-06-19 13:17:09 +08:00
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-06-19 15:44:06 +08:00
selectModelId = 0;
OnModel(0);
goSelect1.gameObject.IsScaleShow(false);
goSelect2.gameObject.IsScaleShow(false);
BindButton(buttonModel1, () =>
{
OnModel(1);
goSelect1.gameObject.IsScaleShow(true);
goSelect2.gameObject.IsScaleShow(false);
});
BindButton(buttonModel2, () =>
{
OnModel(2);
goSelect1.gameObject.IsScaleShow(false);
goSelect2.gameObject.IsScaleShow(true);
});
BindButton(buttonConfirm, OnConfirm);
2024-06-19 13:17:09 +08:00
}
2024-06-19 15:44:06 +08:00
protected override async void OnShowWindow(object data = null)
2024-06-19 13:17:09 +08:00
{
base.OnShowWindow(data);
2024-06-19 15:44:06 +08:00
await AssetManager.Instance.WaitAllPreloads();
2024-06-19 13:17:09 +08:00
2024-06-19 15:44:06 +08:00
GameObject goModelTemp = AssetManager.Instance.GetPreLoadResult<GameObject>(PathEx.GetNpcDisplayModelPath(MODEL_NAME_1));
if (null != goModelTemp)
{
GameObject goModel = Object.Instantiate(goModelTemp, buttonModel1.transform, true);
goModel.transform.localPosition = MODEL_POS;
goModel.transform.localScale = MODEL_SCALE;
goModel.transform.localRotation = MODEL_ROT;
goModel.SetLayerEx(5);
}
goModelTemp = AssetManager.Instance.GetPreLoadResult<GameObject>(PathEx.GetNpcDisplayModelPath(MODEL_NAME_2));
if (null != goModelTemp)
{
GameObject goModel = Object.Instantiate(goModelTemp, buttonModel2.transform, true);
goModel.transform.localPosition = MODEL_POS;
goModel.transform.localScale = MODEL_SCALE;
goModel.transform.localRotation = MODEL_ROT;
goModel.SetLayerEx(5);
}
2024-06-19 13:17:09 +08:00
}
protected override void OnHideWindow()
{
base.OnHideWindow();
}
public override void OnRelease()
{
2024-06-19 15:44:06 +08:00
AssetManager.Instance.Unload(PathEx.GetNpcDisplayModelPath(MODEL_NAME_1));
AssetManager.Instance.Unload(PathEx.GetNpcDisplayModelPath(MODEL_NAME_2));
2024-06-19 13:17:09 +08:00
base.OnRelease();
}
#region 回调方法
/// <summary>
/// 关闭
/// </summary>
private void OnClose()
{
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;
}
/// <summary>
/// 确定选择
/// </summary>
private void OnConfirm()
{
NetHelper.SetPlayeHead((uint)selectModelId);
_ContinueStory();
}
private async void _ContinueStory()
{
if (GameStateManager.Instance.GetCurState() is GameStateStory gameStateStory)
{
// 这里需要重新创建主角模型
await StoryManager.instance.AutoReCreatePlayerModel(gameStateStory.storyConfig);
gameStateStory.IsReady = true;
}
OnClose();
2024-06-19 15:44:06 +08:00
}
2024-06-19 13:17:09 +08:00
#endregion
}