提交内容修改
This commit is contained in:
parent
9e425a0886
commit
69005fe089
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ae12c898f4042949bc5cc317c63d77d
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName: uiimageselectmap_prefab
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -286,11 +286,13 @@ public class ActionHelper
|
||||
var dictAction = (XMLTool.DictionaryAction)act;
|
||||
return QFramework.ShowScoreAction.Allocate(dictAction.args);
|
||||
}
|
||||
case "ImageSelectMap":
|
||||
{
|
||||
var dictAction = (XMLTool.ImageSelectMapAction)act;
|
||||
return QFramework.ImageSelectMapAction.Allocate(dictAction.args, dictAction.rows);
|
||||
}
|
||||
|
||||
//ɾµô¾ÉµÄÍÏ×§UI
|
||||
//case "ImageSelectMap":
|
||||
// {
|
||||
// var dictAction = (XMLTool.ImageSelectMapAction)act;
|
||||
// return QFramework.ImageSelectMapAction.Allocate(dictAction.args, dictAction.rows);
|
||||
// }
|
||||
case "UIGuideTip":
|
||||
{
|
||||
|
||||
@ -320,6 +322,13 @@ public class ActionHelper
|
||||
return QFramework.BtnAnimAction.Allocate(dictAction.args);
|
||||
|
||||
}
|
||||
case "DragJiHe":
|
||||
{
|
||||
var dictAction = (XMLTool.DictionaryAction)act;
|
||||
return QFramework.ActionDragJiHe.Allocate(dictAction.args);
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
||||
break;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae19a7483e41c6f48b777175f4bc6362
|
||||
guid: c3f2a6c0a9e5b4848adf01855842e857
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
98
Assets/Scripts/Actions/CustomAction/ActionDragJiHe.cs
Normal file
98
Assets/Scripts/Actions/CustomAction/ActionDragJiHe.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using QFramework.Example;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
namespace QFramework
|
||||
{
|
||||
|
||||
|
||||
public class ActionDragJiHe : IAction
|
||||
{
|
||||
public System.Action OnFinished
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ulong ActionID
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public ActionStatus Status
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public bool Deinited
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public bool Paused
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
private ActionDragJiHe()
|
||||
{
|
||||
}
|
||||
private static readonly SimpleObjectPool<ActionDragJiHe> mPool =
|
||||
new SimpleObjectPool<ActionDragJiHe>(() => new(), null, 10);
|
||||
Dictionary<string, string> datas;
|
||||
|
||||
public static ActionDragJiHe Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
|
||||
{
|
||||
var retNode = mPool.Allocate();
|
||||
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||||
retNode.Deinited = false;
|
||||
retNode.Reset();
|
||||
retNode.datas = datas;
|
||||
return retNode;
|
||||
}
|
||||
public void Deinit()
|
||||
{
|
||||
if (!Deinited)
|
||||
{
|
||||
Deinited = true;
|
||||
mPool.Recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
// Debug.Log("Action OnFinish???");
|
||||
}
|
||||
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
UIImageSelectMap_JiHeData data = new UIImageSelectMap_JiHeData();
|
||||
|
||||
|
||||
|
||||
//拖拽对象,
|
||||
data.DragItemName = datas.ContainsKey("DragItemName") ? datas["DragItemName"] : string.Empty;
|
||||
//正确的框的名称
|
||||
data.TargetObj = datas.ContainsKey("TargetObj") ? datas["TargetObj"] : string.Empty;
|
||||
//图片路径
|
||||
data.ItemPath = datas.ContainsKey("ItemPath") ? datas["ItemPath"] : string.Empty;
|
||||
|
||||
|
||||
|
||||
|
||||
UIKit.OpenPanelAsync<UIImageSelectMap_JiHe>(uiData: data, canvasLevel: UILevel.Common).ToAction().StartGlobal(() =>
|
||||
{
|
||||
this.Finish();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30b3cad2e23c39b43befa7ffb3bae172
|
||||
guid: e3913843049b5bb499a6c808a812ee0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@ -1,127 +0,0 @@
|
||||
using QFramework.Example;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XMLTool;
|
||||
|
||||
namespace QFramework
|
||||
{
|
||||
internal class ImageSelectMapAction : IAction
|
||||
{
|
||||
public string txt;
|
||||
|
||||
|
||||
public System.Action OnFinished { get; set; }
|
||||
|
||||
|
||||
private ImageSelectMapAction()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly SimpleObjectPool<ImageSelectMapAction> mPool =
|
||||
new SimpleObjectPool<ImageSelectMapAction>(() => new ImageSelectMapAction(), null, 10);
|
||||
Dictionary<string, string> datas;
|
||||
List<XMLTool.ImageSelectMapAction.Row> rows;
|
||||
public static ImageSelectMapAction Allocate(Dictionary<string, string> datas, List<XMLTool.ImageSelectMapAction.Row> rows, System.Action OnFinished = null)
|
||||
{
|
||||
var retNode = mPool.Allocate();
|
||||
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||||
retNode.Deinited = false;
|
||||
retNode.datas = datas;
|
||||
retNode.rows = rows;
|
||||
retNode.Reset();
|
||||
retNode.OnFinished = OnFinished;
|
||||
return retNode;
|
||||
}
|
||||
|
||||
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
|
||||
UIImageSelectMapData data = new UIImageSelectMapData();
|
||||
data.totalScore = 0;
|
||||
if (datas.ContainsKey("totalScore"))
|
||||
{
|
||||
float.TryParse(datas["totalScore"], out data.totalScore);
|
||||
}
|
||||
data.rightScore = 0;
|
||||
if (datas.ContainsKey("rightScore"))
|
||||
{
|
||||
float.TryParse(datas["rightScore"], out data.rightScore);
|
||||
}
|
||||
data.wrongScore = 0;
|
||||
if (datas.ContainsKey("wrongScore"))
|
||||
{
|
||||
float.TryParse(datas["wrongScore"], out data.wrongScore);
|
||||
}
|
||||
data.scoreName = datas.ContainsKey("scoreName") ? datas["scoreName"] : "";
|
||||
data.rightLabel = datas.ContainsKey("rightLabel") ? datas["rightLabel"] : "";
|
||||
data.wrongLabel = datas.ContainsKey("wrongLabel") ? datas["wrongLabel"] : "";
|
||||
data.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : "";
|
||||
if (datas.ContainsKey("random"))
|
||||
{
|
||||
bool.TryParse(datas["random"], out data.random);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.random = false;
|
||||
}
|
||||
|
||||
foreach (var rowItem in rows)
|
||||
{
|
||||
var row = new UIImageSelectMapData.Row();
|
||||
row.name = rowItem.name;
|
||||
data.rows.Add(row);
|
||||
foreach (var item in rowItem.items)
|
||||
{
|
||||
row.items.Add(new UIImageSelectMapData.OptionItem()
|
||||
{
|
||||
pic = item.pic,
|
||||
name = item.name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
UIKit.OpenPanelAsync<UIImageSelectMap>(uiData: data).ToAction().StartGlobal(() =>
|
||||
{
|
||||
|
||||
this.Finish();
|
||||
OnFinished?.Invoke();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!Deinited)
|
||||
{
|
||||
OnFinished = null;
|
||||
Deinited = true;
|
||||
mPool.Recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Deinited { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93d6ed89dd2e1974f8712dde5a2c6c31
|
||||
timeCreated: 1647655796
|
||||
8
Assets/Scripts/UI/UIBtnAnim.meta
Normal file
8
Assets/Scripts/UI/UIBtnAnim.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2261eaeda20c16469fd7c74006445c8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/UI/UIImageSelectMap.Designer.cs
generated
61
Assets/Scripts/UI/UIImageSelectMap.Designer.cs
generated
@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using QFramework;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
// Generate Id:ee191ed8-359d-4628-aa2b-d1711157540d
|
||||
public partial class UIImageSelectMap
|
||||
{
|
||||
public const string Name = "UIImageSelectMap";
|
||||
|
||||
[SerializeField]
|
||||
public RectTransform LeftContent;
|
||||
[SerializeField]
|
||||
public RectTransform RightContent;
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Image LeftItem;
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Image RightItem;
|
||||
[SerializeField]
|
||||
public RectTransform RightRowItem;
|
||||
|
||||
|
||||
|
||||
|
||||
private UIImageSelectMapData mPrivateData = null;
|
||||
|
||||
protected override void ClearUIComponents()
|
||||
{
|
||||
LeftContent = null;
|
||||
RightContent = null;
|
||||
LeftItem = null;
|
||||
RightItem = null;
|
||||
RightRowItem = null;
|
||||
|
||||
mData = null;
|
||||
}
|
||||
|
||||
public UIImageSelectMapData Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
}
|
||||
|
||||
UIImageSelectMapData mData
|
||||
{
|
||||
get
|
||||
{
|
||||
return mPrivateData ?? (mPrivateData = new UIImageSelectMapData());
|
||||
}
|
||||
set
|
||||
{
|
||||
mUIData = value;
|
||||
mPrivateData = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,286 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using QFramework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.EventSystems;
|
||||
using System;
|
||||
using TMPro;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
public class UIImageSelectMapData : UIPanelData
|
||||
{
|
||||
public class OptionItem
|
||||
{
|
||||
public string pic;
|
||||
public string name;
|
||||
}
|
||||
public class Row
|
||||
{
|
||||
public string name;
|
||||
public List<OptionItem> items = new List<OptionItem>();
|
||||
}
|
||||
public string scoreName;
|
||||
public float totalScore;
|
||||
public float rightScore;
|
||||
public float wrongScore;
|
||||
public string rightLabel;
|
||||
public string wrongLabel;
|
||||
public string finishedEvent;
|
||||
public bool random = false;
|
||||
public List<Row> rows = new List<Row>();
|
||||
|
||||
}
|
||||
public partial class UIImageSelectMap : UIPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// 右侧数据结构
|
||||
/// </summary>
|
||||
class RightDataItem
|
||||
{
|
||||
public GameObject rightObj;
|
||||
public bool isRight = false;
|
||||
}
|
||||
ResLoader loader;
|
||||
GameObject moveObj;
|
||||
GameObject enterRight;
|
||||
GameObject leftDragObj;
|
||||
Dictionary<GameObject, UIImageSelectMapData.OptionItem> itemDatas = new Dictionary<GameObject, UIImageSelectMapData.OptionItem>();
|
||||
Dictionary<GameObject, RightDataItem> leftAndRightMap = new Dictionary<GameObject, RightDataItem>();
|
||||
|
||||
// 新增:存储分类行对象和数据的映射
|
||||
Dictionary<GameObject, UIImageSelectMapData.Row> rowMap = new Dictionary<GameObject, UIImageSelectMapData.Row>();
|
||||
|
||||
protected override void OnInit(IUIData uiData = null)
|
||||
{
|
||||
mData = uiData as UIImageSelectMapData ?? new UIImageSelectMapData();
|
||||
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuitHandler);
|
||||
// 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();
|
||||
itemDatas.Clear();
|
||||
leftAndRightMap.Clear();
|
||||
rowMap.Clear(); // 清空行映射
|
||||
|
||||
foreach (var row in mData.rows)
|
||||
{
|
||||
GameObject rowObj = GameObject.Instantiate(RightRowItem.gameObject, RightContent);
|
||||
var typeText = rowObj.transform.Find("Type").GetComponent<TextMeshProUGUI>();
|
||||
typeText.text = row.name.Replace("\\n", "\n");
|
||||
rowObj.name = row.name.Replace("\\n", "\n");
|
||||
Transform itemContent = rowObj.transform.Find("Items");
|
||||
|
||||
// 存储行对象和数据的映射
|
||||
rowMap.Add(rowObj, row);
|
||||
|
||||
foreach (var item in row.items)
|
||||
{
|
||||
var rightObj = GameObject.Instantiate(RightItem, itemContent);
|
||||
var nameText = rightObj.transform.Find("Name").GetComponent<TextMeshProUGUI>();
|
||||
nameText.text = item.name;
|
||||
nameText.color = Color.white;
|
||||
rightObj.name = item.name;
|
||||
rightObj.transform.Find("PicBg/Pic").GetComponent<Image>().color = new Color(1, 1, 1, 0);
|
||||
rightObj.OnPointerEnterEvent(RightOnEnter);
|
||||
rightObj.OnPointerExitEvent(RightOnExit);
|
||||
rightObj.OnPointerClickEvent(RightOnClick);
|
||||
|
||||
var leftObj = GameObject.Instantiate(LeftItem, LeftContent);
|
||||
leftObj.name = row.name + "|" + item.name;
|
||||
var path = Global.deviceIconsPath + item.pic;
|
||||
loader.Add2Load(path.ToNetImageResName(), (success, res) =>
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
leftObj.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D);
|
||||
}
|
||||
});
|
||||
|
||||
leftObj.OnBeginDragEvent(LeftOnBeginDrag);
|
||||
leftObj.OnDragEvent(LeftOnDrag);
|
||||
leftObj.OnEndDragEvent(LeftOnEndDrag);
|
||||
itemDatas.Add(leftObj.gameObject, item);
|
||||
}
|
||||
}
|
||||
|
||||
if (mData.random)
|
||||
{
|
||||
Utility.ShuffleChildObjects(LeftContent);
|
||||
}
|
||||
|
||||
loader.LoadAsync();
|
||||
}
|
||||
|
||||
private void OnModuleQuitHandler(OnModuleQuit quit)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void RightOnClick(PointerEventData data)
|
||||
{
|
||||
Transform trans = data.pointerClick.transform;
|
||||
if (leftAndRightMap.ContainsKey(trans.gameObject))
|
||||
{
|
||||
leftAndRightMap[trans.gameObject].rightObj.SetActive(true);
|
||||
trans.GetComponent<Image>().color = Color.white;
|
||||
trans.Find("PicBg/Pic").GetComponent<Image>().color = new Color(1, 1, 1, 0);
|
||||
|
||||
enterRight.transform.Find("Name").GetComponent<TextMeshProUGUI>().color = Color.white;
|
||||
leftAndRightMap.Remove(trans.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void RightOnExit(PointerEventData data)
|
||||
{
|
||||
enterRight = null;
|
||||
}
|
||||
|
||||
private void RightOnEnter(PointerEventData data)
|
||||
{
|
||||
enterRight = data.pointerEnter.gameObject;
|
||||
}
|
||||
|
||||
private void LeftOnBeginDrag(PointerEventData data)
|
||||
{
|
||||
leftDragObj = data.pointerDrag;
|
||||
moveObj = GameObject.Instantiate(leftDragObj, gameObject.transform);
|
||||
moveObj.name = moveObj.name.Replace("(Clone)", "");
|
||||
moveObj.GetComponent<RectTransform>().sizeDelta = LeftContent.GetComponent<GridLayoutGroup>().cellSize;
|
||||
moveObj.GetComponent<Image>().raycastTarget = false;
|
||||
}
|
||||
|
||||
private void LeftOnEndDrag(PointerEventData data)
|
||||
{
|
||||
if (enterRight == null || leftAndRightMap.ContainsKey(enterRight))
|
||||
return;
|
||||
|
||||
//TextMeshProUGUI nameText = enterRight.transform.Find("Name").GetComponent<TextMeshProUGUI>();
|
||||
|
||||
//Image Frame = enterRight.transform.Find("Frame").GetComponent<Image>();
|
||||
bool isRight = false;
|
||||
|
||||
// 获取正确的分类数据
|
||||
UIImageSelectMapData.Row categoryRow = GetCategoryRow(enterRight);
|
||||
if (categoryRow == null)
|
||||
{
|
||||
Debug.LogError("无法找到对应的分类数据");
|
||||
return;
|
||||
}
|
||||
|
||||
var draggedItem = itemDatas[leftDragObj];
|
||||
bool foundMatch = CheckItemInCategory(draggedItem, categoryRow);
|
||||
|
||||
// 更新UI反馈
|
||||
if (foundMatch)
|
||||
{
|
||||
//Frame.color = Color.green;
|
||||
//nameText.color = Color.green;
|
||||
isRight = true;
|
||||
Debug.Log($"正确匹配: {draggedItem.name} 到分类 {categoryRow.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Frame.color = Color.red;
|
||||
//nameText.color = Color.red;
|
||||
Debug.Log($"错误匹配: {draggedItem.name} 到分类 {categoryRow.name}");
|
||||
}
|
||||
|
||||
// 更新图片显示
|
||||
//Image img = enterRight.transform.Find("PicBg/Pic").GetComponent<Image>();
|
||||
//img.sprite = moveObj.GetComponent<Image>().sprite;
|
||||
//img.color = Color.white;
|
||||
|
||||
// 记录匹配结果
|
||||
leftAndRightMap.Add(enterRight, new RightDataItem { rightObj = leftDragObj, isRight = isRight });
|
||||
leftDragObj.SetActive(false);
|
||||
|
||||
// 检查当前分类是否完成
|
||||
if (isRight && CheckCategoryCompletion(categoryRow))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(mData.finishedEvent))
|
||||
{
|
||||
StringEventSystem.Global.Send(mData.finishedEvent);
|
||||
Debug.Log($"分类 {categoryRow.name} 已完成,触发完成事件");
|
||||
}
|
||||
}
|
||||
|
||||
// 清理拖拽对象
|
||||
GameObject.Destroy(moveObj);
|
||||
moveObj = null;
|
||||
leftDragObj = null;
|
||||
}
|
||||
|
||||
// 获取分类行数据
|
||||
private UIImageSelectMapData.Row GetCategoryRow(GameObject targetObj)
|
||||
{
|
||||
Transform parentTransform = targetObj.transform.parent;
|
||||
|
||||
// 查找行对象
|
||||
while (parentTransform != null && parentTransform != RightContent.transform)
|
||||
{
|
||||
if (rowMap.ContainsKey(parentTransform.gameObject))
|
||||
{
|
||||
return rowMap[parentTransform.gameObject];
|
||||
}
|
||||
parentTransform = parentTransform.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查项目是否在分类中
|
||||
private bool CheckItemInCategory(UIImageSelectMapData.OptionItem item, UIImageSelectMapData.Row categoryRow)
|
||||
{
|
||||
return categoryRow.items.Exists(i => i.pic == item.pic || i.name == item.name);
|
||||
}
|
||||
|
||||
// 检查分类是否完成匹配
|
||||
private bool CheckCategoryCompletion(UIImageSelectMapData.Row categoryRow)
|
||||
{
|
||||
if (categoryRow == null)
|
||||
return false;
|
||||
|
||||
// 查找该分类需要匹配的项目数
|
||||
int required = categoryRow.items.Count;
|
||||
|
||||
// 查找该分类已正确匹配的项目数
|
||||
int actual = 0;
|
||||
if (leftAndRightMap.Any(p => p.Value.isRight && GetCategoryRow(p.Key) == categoryRow))
|
||||
{
|
||||
actual = leftAndRightMap.Count(p => p.Value.isRight && GetCategoryRow(p.Key) == categoryRow);
|
||||
}
|
||||
|
||||
// 判断是否完成
|
||||
return actual >= required;
|
||||
}
|
||||
|
||||
private void LeftOnDrag(PointerEventData data)
|
||||
{
|
||||
if (moveObj)
|
||||
{
|
||||
moveObj.transform.position = Input.mousePosition;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnModuleQuitHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/UI/UIImageSelectMap_JiHe.meta
Normal file
8
Assets/Scripts/UI/UIImageSelectMap_JiHe.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d35f08ef181200419ba4a9061e9c25c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/Scripts/UI/UIImageSelectMap_JiHe/UIImageDrag_JiHe.cs
Normal file
74
Assets/Scripts/UI/UIImageSelectMap_JiHe/UIImageDrag_JiHe.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using F3Device.Screen;
|
||||
using QFramework;
|
||||
using QFramework.Example;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class UIImageDrag_JiHe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
RectTransform rect;
|
||||
Canvas canvas; // 用于坐标转换
|
||||
|
||||
List<RaycastResult> raycastResults;
|
||||
GameObject target;
|
||||
public Vector3 originPos;
|
||||
bool isOverTarget = false; // 是否在目标物体上结束拖拽
|
||||
|
||||
void Awake()
|
||||
{
|
||||
rect = GetComponent<RectTransform>();
|
||||
canvas = GetComponentInParent<Canvas>(); // 获取父级Canvas
|
||||
|
||||
|
||||
originPos = rect.transform.localPosition;
|
||||
|
||||
raycastResults = new List<RaycastResult>();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
rect.transform.position = Input.mousePosition;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
var uiPanel = UIKit.GetPanel<UIImageSelectMap_JiHe>();
|
||||
if (uiPanel == null) return;
|
||||
|
||||
// 获取目标对象名称
|
||||
string targetObjName = uiPanel.Data.TargetObj;
|
||||
|
||||
// 判断当前拖拽的物体是否与目标物体匹配
|
||||
if (isOverTarget && target != null && target.name == targetObjName)
|
||||
{
|
||||
Debug.Log("成功放置到目标物体: " + targetObjName);
|
||||
|
||||
// 可以在这里执行成功放置的逻辑
|
||||
// 例如:将当前物体位置固定到目标位置
|
||||
transform.position = target.transform.position;
|
||||
|
||||
// 通知UI面板操作成功
|
||||
// uiPanel.OnDragSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("未放置到正确目标,返回原位");
|
||||
Debug.Log(originPos+"??????");
|
||||
// 未放置到正确目标,返回原始位置
|
||||
rect.anchoredPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
// 重置状态
|
||||
isOverTarget = false;
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fa5d149f86eeb54d89208e36562e2d8
|
||||
guid: 55cd654f93809b34da0cf6fefd602a8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@ -5,35 +5,41 @@ using QFramework;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
// Generate Id:e105577a-1a00-4455-bd9b-8514a767a42f
|
||||
// Generate Id:3ac2388d-8123-48e8-878d-47de0e19e577
|
||||
public partial class UIImageSelectMap_JiHe
|
||||
{
|
||||
public const string Name = "UIImageSelectMap_JiHe";
|
||||
|
||||
|
||||
[SerializeField]
|
||||
public RectTransform LeftContent;
|
||||
public GameObject Kuang1;
|
||||
|
||||
[SerializeField]
|
||||
public RectTransform RightContent;
|
||||
public GameObject Kuang2;
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Image LeftItem;
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Image RightItem;
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Image Frame;
|
||||
[SerializeField]
|
||||
public RectTransform RightRowItem;
|
||||
public GameObject LeftItem;
|
||||
[SerializeField]
|
||||
public GameObject LeftContent;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[SerializeField]
|
||||
public UnityEngine.UI.Button CloseBtn;
|
||||
|
||||
private UIImageSelectMap_JiHeData mPrivateData = null;
|
||||
|
||||
protected override void ClearUIComponents()
|
||||
{
|
||||
LeftContent = null;
|
||||
RightContent = null;
|
||||
|
||||
Kuang1 = null;
|
||||
|
||||
Kuang2 = null;
|
||||
LeftItem = null;
|
||||
RightItem = null;
|
||||
Frame = null;
|
||||
//Name = null;
|
||||
RightRowItem = null;
|
||||
CloseBtn = null;
|
||||
|
||||
mData = null;
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using QFramework;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
public class UIImageSelectMap_JiHeData : UIPanelData
|
||||
{
|
||||
public string DragItemName;
|
||||
public string TargetObj;
|
||||
public string ItemPath;
|
||||
}
|
||||
|
||||
public partial class UIImageSelectMap_JiHe : UIPanel
|
||||
{
|
||||
|
||||
|
||||
protected override void OnInit(IUIData uiData = null)
|
||||
{
|
||||
mData = uiData as UIImageSelectMap_JiHeData ?? new UIImageSelectMap_JiHeData();
|
||||
loader = ResLoader.Allocate();
|
||||
}
|
||||
|
||||
ResLoader loader;
|
||||
|
||||
protected override void OnOpen(IUIData uiData = null)
|
||||
{
|
||||
string s = mData.DragItemName;
|
||||
|
||||
// 生成单个物体
|
||||
GameObject obj = GameObject.Instantiate(LeftItem, LeftContent.transform);
|
||||
obj.name = s;
|
||||
|
||||
string path = Global.deviceIconsPath + mData.ItemPath;
|
||||
Debug.Log(path + "????");
|
||||
loader.Add2Load(path.ToNetImageResName(), (success, res) =>
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
obj.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D);
|
||||
obj.GetComponentInChildren<Text>().text = s;
|
||||
}
|
||||
});
|
||||
|
||||
uIImageDrag_JiHe = obj.GetComponent<UIImageDrag_JiHe>();
|
||||
|
||||
// 添加拖拽事件
|
||||
//obj.OnBeginDragEvent(LeftOnBeginDrag);
|
||||
//obj.OnDragEvent(LeftOnDrag);
|
||||
//obj.OnEndDragEvent(LeftOnEndDrag);
|
||||
|
||||
loader.LoadAsync();
|
||||
}
|
||||
|
||||
public UIImageDrag_JiHe uIImageDrag_JiHe;
|
||||
|
||||
|
||||
// 重置拖拽状态
|
||||
|
||||
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
|
||||
if (loader != null)
|
||||
{
|
||||
loader.Recycle2Cache();
|
||||
loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/UI/UISliderAnim.meta
Normal file
8
Assets/Scripts/UI/UISliderAnim.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efdee06f670b8314d9bae65d7d33c32a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,38 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using QFramework;
|
||||
|
||||
namespace QFramework.Example
|
||||
{
|
||||
public class UIImageSelectMap_JiHeData : UIPanelData
|
||||
{
|
||||
}
|
||||
public partial class UIImageSelectMap_JiHe : UIPanel
|
||||
{
|
||||
protected override void OnInit(IUIData uiData = null)
|
||||
{
|
||||
mData = uiData as UIImageSelectMap_JiHeData ?? new UIImageSelectMap_JiHeData();
|
||||
// please add init code here
|
||||
}
|
||||
|
||||
protected override void OnOpen(IUIData uiData = null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2039,6 +2039,34 @@ namespace XMLTool
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case "DragJiHe":
|
||||
{
|
||||
|
||||
var act = new DictionaryAction();
|
||||
XAttribute DragItemName = action.Attribute("DragItemName");
|
||||
if (DragItemName != null)
|
||||
{
|
||||
act.args.Add("DragItemName", DragItemName.Value);
|
||||
}
|
||||
XAttribute TargetObj = action.Attribute("TargetObj");
|
||||
if (TargetObj != null)
|
||||
{
|
||||
act.args.Add("TargetObj", TargetObj.Value);
|
||||
}
|
||||
|
||||
XAttribute ItemPath = action.Attribute("ItemPath");
|
||||
if (ItemPath != null)
|
||||
{
|
||||
act.args.Add("ItemPath", ItemPath.Value);
|
||||
}
|
||||
newAction = act;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
newAction = new Action();
|
||||
break;
|
||||
|
||||
@ -69,6 +69,7 @@
|
||||
|
||||
<Condition type="UIClick" value="UIRoot/PopUI/UITextTip/Mask/Content/BtnContent/确定"></Condition>
|
||||
|
||||
<Action type="Greatbtns" name="动态三维建模|分类对比学习" pos="-889,317.1|-756,317.1" size="125,70|125,70" />
|
||||
|
||||
<Action type="UIBackPack" devices="棱柱,棱锥,球体,圆柱,圆锥"
|
||||
random="false"
|
||||
@ -420,26 +421,10 @@
|
||||
<Action type="UIShow" value="UIBtnAnim" isShow="false"></Action>
|
||||
<Action type="UIShow" value="UIBackPack" isShow="false"></Action>
|
||||
|
||||
<Action type="DragJiHe" DragItemName="棱柱" TargetObj="" ItemPath="JiHeTi/LengZhu.png"></Action>
|
||||
|
||||
|
||||
<!--<Action type="ImageSelectMap"
|
||||
random="true"
|
||||
scoreName=""
|
||||
totalScore=""
|
||||
rightScore=""
|
||||
wrongScore=""
|
||||
rightLabel=""
|
||||
wrongLabel=""
|
||||
finishedEvent="全部完成">
|
||||
|
||||
<Row name="绿色">
|
||||
<Item name="帝王绿" pic="JiHeTi/LengZhu.png"></Item>
|
||||
<Item name="阳绿" pic="JiHeTi/LengZhui.png"></Item>
|
||||
<Item name="碧玉" pic="JiHeTi/QiuTi.png"></Item>
|
||||
<Item name="青玉" pic="JiHeTi/YuanZhu.png"></Item>
|
||||
<Item name="青玉" pic="JiHeTi/YuanZhui.png"></Item>
|
||||
</Row>
|
||||
|
||||
</Action>-->
|
||||
|
||||
</Action>
|
||||
</Enter>
|
||||
|
||||
@ -44,8 +44,8 @@ PlayerSettings:
|
||||
m_HolographicTrackingLossScreen: {fileID: 0}
|
||||
defaultScreenWidth: 1920
|
||||
defaultScreenHeight: 1080
|
||||
defaultScreenWidthWeb: 1280
|
||||
defaultScreenHeightWeb: 720
|
||||
defaultScreenWidthWeb: 1920
|
||||
defaultScreenHeightWeb: 1080
|
||||
m_StereoRenderingPath: 0
|
||||
m_ActiveColorSpace: 0
|
||||
unsupportedMSAAFallback: 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user