CultivationOfBrewing/Assets/Scripts/UI/UIPanel/UI_ContentPanel.cs

131 lines
3.3 KiB
C#

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class UI_ContentPanel : BasePanel
{
public static UI_ContentPanel instance;
public Image ContentPanel;
public Button enter;
public Button exit;
public TextMeshProUGUI ContentText;
public RawImage ContentrawImage;
public string ContentImage = "";//ͼƬ·¾¶
public string Tips ;
public int index = 0;
public Sprite[] sprites;
public Button Rig_Btn;//Çл»Í¼Æ¬ÓҲఴť
public Button Left_Btn;//Çл»Í¼Æ¬×ó²à°´Å¥
protected override void Awake()
{
instance = this;
sprites = Resources.LoadAll<Sprite>(ContentImage);
base.Awake();
}
public void init(TextMeshProUGUI textMeshProUGUI,Texture texture)
{
textMeshProUGUI.text = ContentText.text;
texture = ContentrawImage.texture;
}
public override void ShowMe(int time = 0)
{
base.ShowMe();
if (index==0)
{
Left_Btn.gameObject.SetActive(false);
Rig_Btn.gameObject.SetActive(true);
}
}
public override void HideMe( int time = 0)
{
Tips ="";
base.HideMe();
}
protected override void OnClick(string btnName)
{
Debug.Log(btnName);
switch (btnName)
{
case "exit":
if (ContentPanel.rectTransform.localPosition.x == 940)
{
ContentPanel.rectTransform.DOLocalMoveX(1330, 1f);
enter.gameObject.SetActive(true);
exit.gameObject.SetActive(false);
}
break;
case "enter":
if (ContentPanel.rectTransform.localPosition.x == 1330)
{
ContentPanel.rectTransform.DOLocalMoveX(940,1f);
enter.gameObject.SetActive(false);
exit.gameObject.SetActive(true);
}
break;
case "leftbutton":
leftbutton();
break;
case "rigbutton":
rigbutton();
break;
}
}
public void fizhi()
{
//for (int i = 0; i < Tips.Count; i++)
//{
// ContentText.text += Tips[i];
//}
ContentText.text = Tips;
}
/// <summary>
/// Çл»Í¼Æ¬ÓҲఴť
/// </summary>
public void rigbutton()
{
index++;
if (index>= sprites.Length)
{
index = 0;
Left_Btn.gameObject.SetActive(false);
Rig_Btn.gameObject.SetActive(true);
}
ImageReplacement(index);
}
/// <summary>
/// Çл»Í¼Æ¬×ó²à°´Å¥
/// </summary>
public void leftbutton()
{
index--;
if (index < 0)
{
index = sprites.Length-1;
Rig_Btn.gameObject.SetActive(false);
Left_Btn.gameObject.SetActive(true);
}
ImageReplacement(index);
}
/// <summary>
/// Ìæ»»Í¼Æ¬
/// </summary>
/// <param name="Imageindex"></param>
public void ImageReplacement(int Imageindex)
{
ContentrawImage.texture = sprites[Imageindex].texture;
}
}