83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using DG.Tweening;
|
||
using System;
|
||
using System.Collections;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UI_CustomSessionPanel : 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:客户,iconIndex=1:负责人
|
||
/// </summary>
|
||
public void Init(string triggerID, string clientTalk, string _clientName, int iconIndex, Action<string> _callBack)
|
||
{
|
||
this.triggerID = triggerID;
|
||
callBack = _callBack;
|
||
GetControl<TextMeshProUGUI>("ClientText_DialogBox").DOKill();
|
||
GetControl<TextMeshProUGUI>("ClientText_DialogBox").text = "";
|
||
GetControl<TextMeshProUGUI>("ClientName").text = _clientName;
|
||
headIcon.sprite = icon[iconIndex];
|
||
//UItext = GetControl<TextMeshProUGUI>("ClientText_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 "ClientContinueBtn":
|
||
GameManager.UIMgr.HidePanel<UI_CustomSessionPanel>();
|
||
callBack?.Invoke(triggerID);
|
||
break;
|
||
}
|
||
}
|
||
void StartTypewriterEffect(string msg)
|
||
{
|
||
// 使用DoTween的DOText方法实现打字机效果
|
||
GetControl<TextMeshProUGUI>("ClientText_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;
|
||
}
|
||
}
|
||
}
|