2025-04-27 11:41:11 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using QFramework;
|
|
|
|
|
using System.Collections.Generic;
|
2025-04-28 09:12:21 +08:00
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using System;
|
2025-04-27 11:41:11 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-28 09:12:21 +08:00
|
|
|
leftObj.OnDragEvent(leftOnDrag);
|
|
|
|
|
|
|
|
|
|
|
2025-04-27 11:41:11 +08:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 09:12:21 +08:00
|
|
|
private void leftOnDrag(PointerEventData data)
|
|
|
|
|
{
|
|
|
|
|
data.selectedObject.transform.position = Input.mousePosition;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-27 11:41:11 +08:00
|
|
|
protected override void OnShow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|