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

78 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_TipsForPracticePanel : BasePanel
{
public GameObject pptImagePrefab;
public Transform content;
public ScrollRect scrollRect;
protected override void Awake()
{
base.Awake();
//pptConfig = JsonManager.LoadData<PPTConfig>("pptConfig");
}
public override void ShowMe()
{
base.ShowMe();
}
public override void HideMe()
{
base.HideMe();
}
protected override void OnClick(string btnName)
{
Debug.Log(btnName);
switch (btnName)
{
case "retrun_Btn":
Bootstrap.Instance.uiManager.ShowPanel<UI_SelectModePanel>(this, E_UI_Layer.System, (panel) =>
{
Debug.Log(".1");
Bootstrap.Instance.uiManager.HidePanel<UI_TipsForPracticePanel>();
StartCoroutine(RefreshScrollView());
});
//Bootstrap.Instance.uiManager.HidePanel<UI_TipsForPracticePanel>();
break;
default:
List<Texture2D> textures = LoadPPTTest.LoadPPTItems(btnName);
if (textures != null)
{
DisplayPPT(textures);
}
StartCoroutine(RefreshScrollView());
break;
}
}
private void DisplayPPT(List<Texture2D> textures)
{
foreach (Transform child in content)
{
Destroy(child.gameObject);
}
Debug.LogError("texturesCount:"+textures.Count);
foreach (var texture in textures)
{
RawImage rawImage = pptImagePrefab.GetComponent<RawImage>();
RawImage image = Instantiate(rawImage, content);
image.texture = texture;
image.rectTransform.sizeDelta = new Vector2(texture.width, texture.height);
}
}
/// <summary>
/// Ë¢ÐÂÓÒ²àµÄ»¬¶¯Ìõ
/// </summary>
/// <returns></returns>
IEnumerator RefreshScrollView()
{
yield return null; // µÈ´ýÒ»Ö¡
LayoutRebuilder.ForceRebuildLayoutImmediate(content as RectTransform);
scrollRect.verticalNormalizedPosition = 1; // »Øµ½¶¥²¿
}
}