ND_SimulationAutomaticControl/Assets/Scripts/UI/UIPanel/UI_OpenTipPanel.cs

142 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
public class UI_OpenTipPanel : BasePanel
{
public Button NextBtn;//下一个按钮
public Button PrevBtn;//上一个按钮
public Button OKBtn; //知道了按钮
private CanvasGroup canvasGroup; //屏幕显示
private GameObject Player;
public List<Sprite> bookPages = new List<Sprite>(); //台账翻页
public Image LedgerImage; //提示图片
public int currentPage = 1; //当前页数
// Start is called before the first frame update
protected override void Awake()
{
base.Awake();
OnInit();
}
public void OnInit()
{
NextBtn = GetControl<Button>("下一步");
PrevBtn = GetControl<Button>("上一步");
OKBtn = GetControl<Button>("知道了");
canvasGroup = GetComponent<CanvasGroup>();
canvasGroup.alpha = 0f; // 默认隐藏
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
Player = GameObject.FindGameObjectWithTag("Player");
}
public override void ShowMe()
{
base.ShowMe();
UpDatePageDisplay();
FadeIn(0.5f);
Player = GameObject.FindGameObjectWithTag("Player");
}
public override void HideMe()
{
base.HideMe();
currentPage = 1;
UpDatePageDisplay();
FadeOut(0.5f);
}
protected override void OnClick(string btnPath)
{
base.OnClick(btnPath);
switch (btnPath)
{
case "CloseBtn":
FadeOut(0.5f);
Player.GetComponent<FirstPersonController>().enabled = true;
currentPage = 1;
LedgerImage.sprite = bookPages[0];
break;
case "上一步":
Debug.Log("下一步");
PrevPage();
break;
case "下一步":
Debug.Log("下一步");
NextPage();
break;
case "知道了":
Debug.Log("知道了");
break;
}
}
/// <summary>
/// 提问渐显
/// </summary>
public void FadeIn(float time)
{
canvasGroup.DOFade(1f, time);
canvasGroup.interactable = true;
canvasGroup.blocksRaycasts = true;
}
/// <summary>
/// 提问渐隐
/// </summary>
public void FadeOut(float time)
{
canvasGroup.DOFade(0f, time);
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
}
/// <summary>
/// 上一页
/// </summary>
public void PrevPage()
{
Debug.Log("上一页");
if (currentPage > 1)
{
currentPage--;
UpDatePageDisplay();
}
}
/// <summary>
/// 下一页
/// </summary>
public void NextPage()
{
Debug.Log("下一页");
if (currentPage < bookPages.Count)
{
currentPage++;
UpDatePageDisplay();
}
}
/// <summary>
/// 更新页数
/// </summary>
public void UpDatePageDisplay()
{
Debug.Log(bookPages.Count);
if (currentPage >= 1 && currentPage <= bookPages.Count)
{
LedgerImage.sprite = bookPages[currentPage - 1];
LedgerImage.gameObject.SetActive(true);
Debug.Log($"显示第 {currentPage} 页,共 {bookPages.Count} 页");
}
else
{
Debug.Log("当前文件夹内为空");
LedgerImage.gameObject.SetActive(false);
}
PrevBtn.gameObject.SetActive(currentPage > 1); // 上一页
NextBtn.gameObject.SetActive(currentPage < bookPages.Count); // 下一页
}
}