83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_PlayerSessionPanel : BasePanel
|
|
{
|
|
private string triggerID;
|
|
public Action<string> callBack;
|
|
private float typingSpeed = 0.05f;
|
|
public Sprite[] icon;
|
|
public Image headIcon;
|
|
|
|
public RectTransform MidPanel;
|
|
public RectTransform ContentPanel;
|
|
public ContentSizeFitter ContentSize;
|
|
private float minHeight = 43.0f;
|
|
/// <summary>
|
|
/// 初始化,state 0 激活另一个操作
|
|
/// iconIndex =0,playIcon,iconIndex =1,负责人Icon
|
|
/// </summary>
|
|
public void Init(string triggerID, string clientTalk, Action<string> _callBack,int iconIndex)
|
|
{
|
|
this.triggerID = triggerID;
|
|
callBack = _callBack;
|
|
headIcon.sprite = icon[iconIndex];
|
|
GetControl<TextMeshProUGUI>("PlayerText_DialogBox").DOKill();
|
|
GetControl<TextMeshProUGUI>("PlayerText_DialogBox").text = "";
|
|
//UItext = GetControl<TextMeshProUGUI>("PlayerText_DialogBox");
|
|
StartTypewriterEffect(clientTalk);
|
|
}
|
|
public override void ShowMe()
|
|
{
|
|
base.ShowMe();
|
|
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.PlayerCanMove, false);
|
|
}
|
|
|
|
public override void HideMe()
|
|
{
|
|
base.HideMe();
|
|
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.PlayerCanMove, true);
|
|
}
|
|
//}
|
|
/// <summary>
|
|
/// 按钮点击
|
|
/// </summary>
|
|
/// <param name="btnName"></param>
|
|
protected override void OnClick(string btnName)
|
|
{
|
|
switch (btnName)
|
|
{
|
|
case "PlayerContinueBtn":
|
|
GameManager.UIMgr.HidePanel<UI_PlayerSessionPanel>();
|
|
callBack?.Invoke(triggerID);
|
|
break;
|
|
}
|
|
}
|
|
void StartTypewriterEffect(string msg)
|
|
{
|
|
// 使用DoTween的DOText方法实现打字机效果
|
|
GetControl<TextMeshProUGUI>("PlayerText_DialogBox").DOText(msg, msg.Length * typingSpeed)
|
|
.SetEase(Ease.Linear);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
RectTransform pt_Dialog = MidPanel.GetComponentInChildren<TMP_Text>().GetComponent<RectTransform>();
|
|
if (Mathf.Abs(pt_Dialog.sizeDelta.y - minHeight) > 0.01f)
|
|
{
|
|
if (pt_Dialog.sizeDelta.y > minHeight)
|
|
MidPanel.sizeDelta = new Vector2(MidPanel.sizeDelta.x, pt_Dialog.sizeDelta.y);
|
|
else
|
|
MidPanel.sizeDelta = new Vector2(MidPanel.sizeDelta.x, minHeight);
|
|
ContentSize.enabled = false;
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(ContentPanel);
|
|
ContentSize.enabled = true;
|
|
}
|
|
}
|
|
}
|