From af9ddbffe91e7e13a369e3ca6ce6b0a57006b1a7 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 28 Apr 2025 10:17:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Art/UIPrefab/UIImageSelectMap.prefab | 18 +++--- Assets/Scripts/UI/UIImageSelectMap.cs | 68 +++++++++++++++++++-- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/Assets/Art/UIPrefab/UIImageSelectMap.prefab b/Assets/Art/UIPrefab/UIImageSelectMap.prefab index a5078f91..f21a5820 100644 --- a/Assets/Art/UIPrefab/UIImageSelectMap.prefab +++ b/Assets/Art/UIPrefab/UIImageSelectMap.prefab @@ -269,7 +269,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &8333043509333940129 RectTransform: m_ObjectHideFlags: 0 @@ -454,8 +454,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 336.29443, y: 0} - m_SizeDelta: {x: 672.5889, y: 0} + m_AnchoredPosition: {x: 336.29443, y: -54.999996} + m_SizeDelta: {x: 672.5889, y: -110} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &2989934290346154672 CanvasRenderer: @@ -726,7 +726,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0.00013167458} + m_AnchoredPosition: {x: 0, y: 0.0008044916} m_SizeDelta: {x: 0, y: 300} m_Pivot: {x: 0, y: 1} --- !u!114 &1181747651547168674 @@ -882,8 +882,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -364.56055, y: 0} - m_SizeDelta: {x: 730, y: 0} + m_AnchoredPosition: {x: -364.56055, y: -55} + m_SizeDelta: {x: 730, y: -110} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &8240270928057047746 CanvasRenderer: @@ -936,8 +936,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Content: {fileID: 6690386520824484871} - m_Horizontal: 1 - m_Vertical: 1 + m_Horizontal: 0 + m_Vertical: 0 m_MovementType: 1 m_Elasticity: 0.1 m_Inertia: 1 @@ -1240,7 +1240,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0.00013167458} + m_AnchoredPosition: {x: 0, y: 0.0008044916} m_SizeDelta: {x: 0, y: 300} m_Pivot: {x: 0, y: 1} --- !u!114 &3568317990091449983 diff --git a/Assets/Scripts/UI/UIImageSelectMap.cs b/Assets/Scripts/UI/UIImageSelectMap.cs index af1e8460..cb10266d 100644 --- a/Assets/Scripts/UI/UIImageSelectMap.cs +++ b/Assets/Scripts/UI/UIImageSelectMap.cs @@ -29,6 +29,10 @@ namespace QFramework.Example public partial class UIImageSelectMap : UIPanel { ResLoader loader; + GameObject moveObj; + GameObject enterRight; + GameObject leftDragObj; + Dictionary itemDatas = new Dictionary(); protected override void OnInit(IUIData uiData = null) { mData = uiData as UIImageSelectMapData ?? new UIImageSelectMapData(); @@ -42,6 +46,7 @@ namespace QFramework.Example LeftContent.RemoveAllChildren(); RightContent.RemoveAllChildren(); + itemDatas.Clear(); foreach (var item in mData.items) { var leftObj = GameObject.Instantiate(LeftItem, LeftContent); @@ -54,12 +59,18 @@ namespace QFramework.Example } }); - leftObj.OnDragEvent(leftOnDrag); - + leftObj.OnBeginDragEvent(LeftOnBeginDrag); + leftObj.OnDragEvent(LeftOnDrag); + leftObj.OnEndDragEvent(LeftOnEndDrag); var rightObj = GameObject.Instantiate(RightItem, RightContent); - rightObj.transform.localPosition = item.pos; + rightObj.name = item.pic; + rightObj.rectTransform.anchoredPosition = item.pos; rightObj.rectTransform.sizeDelta = item.size; + rightObj.OnPointerEnterEvent(RightOnEnter); + rightObj.OnPointerExitEvent(RightOnExit); + + itemDatas.Add(leftObj.gameObject, item); } @@ -80,11 +91,58 @@ namespace QFramework.Example } - private void leftOnDrag(PointerEventData data) + private void RightOnExit(PointerEventData data) { - data.selectedObject.transform.position = Input.mousePosition; + enterRight = null; } + 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().raycastTarget = false; + } + + private void LeftOnEndDrag(PointerEventData data) + { + if (enterRight) + { + if (enterRight.name == itemDatas[leftDragObj].pic) + { + Debug.LogError("ȷ"); + enterRight.GetComponent().color = Color.green; + } + else + { + Debug.LogError(""); + enterRight.GetComponent().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; + } + } + + protected override void OnShow() { } From e506167b3eedee0a121b82173161340ac67a7acb Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 28 Apr 2025 10:27:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=9D=9E=E6=95=B0=E5=80=BC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=8D=E5=AD=98=E5=82=A8=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/UI/UIInput.cs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/UI/UIInput.cs b/Assets/Scripts/UI/UIInput.cs index 26e19459..58e83e92 100644 --- a/Assets/Scripts/UI/UIInput.cs +++ b/Assets/Scripts/UI/UIInput.cs @@ -53,13 +53,17 @@ namespace QFramework.Example foreach (var item in mData.inputs) { GameObject input = GameObject.Instantiate(InputItem.gameObject, InputContent); + input.name = item.name; input.transform.Find("Name").GetComponent().text = item.name; var inputField = input.transform.Find("Input").GetComponent(); inputField.onEndEdit.AddListener(value => { - float v = 0; - float.TryParse(value, out v); - VarController.Instance.Set(item.var, v); + if (string.IsNullOrEmpty(item.var) == false) + { + float v = 0; + float.TryParse(value, out v); + VarController.Instance.Set(item.var, v); + } }); } @@ -125,12 +129,24 @@ namespace QFramework.Example foreach (var item in mData.inputs) { var list = item.answer.Split('|').ToList(); - if (list.Contains(VarController.Instance.Get(item.var).ToString())==false) + if (string.IsNullOrEmpty(item.var)) { - return false; + Transform trans = InputContent.transform.Find(item.name); + string inputStr = trans.Find("Input").GetComponent().text; + if (list.Contains(inputStr)) + { + return true; + } + } + else + { + if (list.Contains(VarController.Instance.Get(item.var).ToString())) + { + return true; + } } } - return true; + return false; } protected override void OnShow()