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;
|
2025-04-28 10:17:57 +08:00
|
|
|
|
GameObject moveObj;
|
|
|
|
|
|
GameObject enterRight;
|
|
|
|
|
|
GameObject leftDragObj;
|
|
|
|
|
|
Dictionary<GameObject, UIImageSelectMapData.OptionItem> itemDatas = new Dictionary<GameObject, UIImageSelectMapData.OptionItem>();
|
2025-04-27 11:41:11 +08:00
|
|
|
|
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();
|
2025-04-28 10:17:57 +08:00
|
|
|
|
itemDatas.Clear();
|
2025-04-27 11:41:11 +08:00
|
|
|
|
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 10:17:57 +08:00
|
|
|
|
leftObj.OnBeginDragEvent(LeftOnBeginDrag);
|
|
|
|
|
|
leftObj.OnDragEvent(LeftOnDrag);
|
|
|
|
|
|
leftObj.OnEndDragEvent(LeftOnEndDrag);
|
2025-04-28 09:12:21 +08:00
|
|
|
|
|
2025-04-27 11:41:11 +08:00
|
|
|
|
var rightObj = GameObject.Instantiate(RightItem, RightContent);
|
2025-04-28 10:17:57 +08:00
|
|
|
|
rightObj.name = item.pic;
|
|
|
|
|
|
rightObj.rectTransform.anchoredPosition = item.pos;
|
2025-04-27 11:41:11 +08:00
|
|
|
|
rightObj.rectTransform.sizeDelta = item.size;
|
2025-04-28 10:17:57 +08:00
|
|
|
|
rightObj.OnPointerEnterEvent(RightOnEnter);
|
|
|
|
|
|
rightObj.OnPointerExitEvent(RightOnExit);
|
|
|
|
|
|
|
|
|
|
|
|
itemDatas.Add(leftObj.gameObject, item);
|
2025-04-27 11:41:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 10:17:57 +08:00
|
|
|
|
private void RightOnExit(PointerEventData data)
|
2025-04-28 09:12:21 +08:00
|
|
|
|
{
|
2025-04-28 10:17:57 +08:00
|
|
|
|
enterRight = null;
|
2025-04-28 09:12:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-28 10:17:57 +08:00
|
|
|
|
private void RightOnEnter(PointerEventData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
enterRight = data.pointerEnter.gameObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LeftOnBeginDrag(PointerEventData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
leftDragObj = data.pointerDrag;
|
|
|
|
|
|
moveObj = GameObject.Instantiate(LeftItem.gameObject, gameObject.transform);
|
|
|
|
|
|
moveObj.GetComponent<Image>().raycastTarget = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LeftOnEndDrag(PointerEventData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (enterRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (enterRight.name == itemDatas[leftDragObj].pic)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("<22><>ȷ");
|
|
|
|
|
|
enterRight.GetComponent<Image>().color = Color.green;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("<22><><EFBFBD><EFBFBD>");
|
|
|
|
|
|
enterRight.GetComponent<Image>().color = Color.red;
|
|
|
|
|
|
}
|
|
|
|
|
|
moveObj.transform.parent = enterRight.transform;
|
|
|
|
|
|
moveObj.transform.localPosition = Vector3.zero;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject.Destroy(moveObj);
|
|
|
|
|
|
moveObj = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
leftDragObj = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LeftOnDrag(PointerEventData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
//data.pointerDrag.transform.position = Input.mousePosition;
|
|
|
|
|
|
if (moveObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
moveObj.transform.position = Input.mousePosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-27 11:41:11 +08:00
|
|
|
|
protected override void OnShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|