VirtualFramework/Assets/Scripts/UI/UIImageSelectMap.cs

91 lines
2.6 KiB
C#
Raw Normal View History

2025-04-27 11:41:11 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
namespace QFramework.Example
{
public class UIImageSelectMapData : UIPanelData
{
public class OptionItem
{
public string pic;
public Vector2 pos;
public Vector2 size;
}
public string scoreName;
public float totalScore;
public float rightScore;
public float wrongScore;
public string rightLabel;
public string wrongLabel;
public string finishedEvent;
public string rightBg;
public List<OptionItem> items = new List<OptionItem>();
}
public partial class UIImageSelectMap : UIPanel
{
ResLoader loader;
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIImageSelectMapData ?? new UIImageSelectMapData();
// please add init code here
loader = ResLoader.Allocate();
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIImageSelectMapData ?? new UIImageSelectMapData();
LeftContent.RemoveAllChildren();
RightContent.RemoveAllChildren();
foreach (var item in mData.items)
{
var leftObj = GameObject.Instantiate(LeftItem, LeftContent);
var path = Global.imagePath + item.pic;
loader.Add2Load(path.ToNetImageResName(), (success, res) =>
{
if (success)
{
leftObj.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D);
}
});
var rightObj = GameObject.Instantiate(RightItem, RightContent);
rightObj.transform.localPosition = item.pos;
rightObj.rectTransform.sizeDelta = item.size;
}
var rightBgPath = Global.imagePath + mData.rightBg;
loader.Add2Load(rightBgPath.ToNetImageResName(), (success, res) =>
{
if (success)
{
RightContent.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D);
RightContent.GetComponent<Image>().SetNativeSize();
}
});
loader.LoadAsync();
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}