选择题新增解析功能

This commit is contained in:
shenjianxing 2025-05-26 11:32:54 +08:00
parent 1a10ee747d
commit 0a6fcca29a
6 changed files with 209 additions and 11 deletions

View File

@ -122,6 +122,157 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1421359348001069859
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8258785922237481627}
- component: {fileID: 5541531973927547524}
- component: {fileID: 5421419062846475919}
- component: {fileID: 2812006979516291810}
m_Layer: 5
m_Name: Des
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8258785922237481627
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421359348001069859}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2509629627698566919}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5541531973927547524
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421359348001069859}
m_CullTransparentMesh: 1
--- !u!114 &5421419062846475919
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421359348001069859}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 1
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: e7da174c677019b49aa681250aa4ded8, type: 2}
m_sharedMaterial: {fileID: -7878122246201655599, guid: e7da174c677019b49aa681250aa4ded8, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 14
m_fontSizeBase: 14
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!114 &2812006979516291810
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421359348001069859}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0d51f3a7c41ab0346b49ae50d456bece, type: 3}
m_Name:
m_EditorClassIdentifier:
MarkType: 0
CustomComponentName:
CustomComment:
mComponentName: TMPro.TextMeshProUGUI
--- !u!1 &1564041369283421511
GameObject:
m_ObjectHideFlags: 0
@ -403,6 +554,7 @@ RectTransform:
m_Children:
- {fileID: 6739641498610695016}
- {fileID: 8818801742622154618}
- {fileID: 8258785922237481627}
- {fileID: 561093864464523440}
m_Father: {fileID: 5056252797064041554}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -691,6 +843,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Title: {fileID: 5287111216189064539}
OptionContent: {fileID: 3206335665978531065}
Des: {fileID: 5421419062846475919}
BtnContent: {fileID: 561093864464523440}
BtnPrefab: {fileID: 3495757393179336855}
OptionPrefab: {fileID: 4836612527177548046}

View File

@ -26,6 +26,8 @@ public class TextQuestionAction : IAction
string absolutely = string.Empty;
string finishedEvent = string.Empty;
string optionType = null;
string des;
string cellSize;
public static TextQuestionAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
@ -44,6 +46,8 @@ public class TextQuestionAction : IAction
retNode.absolutely = datas.ContainsKey("absolutely") ? datas["absolutely"] : string.Empty;
retNode.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : string.Empty;
retNode.optionType = datas.ContainsKey("optionType") ? datas["optionType"] : "0";
retNode.des = datas.ContainsKey("des") ? datas["des"] : string.Empty;
retNode.cellSize = datas.ContainsKey("cellSize") ? datas["cellSize"] : string.Empty;
return retNode;
}
@ -87,6 +91,8 @@ public class TextQuestionAction : IAction
bool.TryParse(absolutely, out data.absolutely);
}
int.TryParse(optionType, out data.OptionType);
data.des = des;
data.cellSize = cellSize;
UIKit.OpenPanelAsync<UITextQuestion>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
}

View File

@ -5,7 +5,7 @@ using QFramework;
namespace QFramework.Example
{
// Generate Id:32288864-cf64-4f8d-82e1-661c04d7b98d
// Generate Id:d5266ca7-b00f-4538-9dbd-ab80bcacd960
public partial class UITextQuestion
{
public const string Name = "UITextQuestion";
@ -15,6 +15,8 @@ namespace QFramework.Example
[SerializeField]
public UnityEngine.UI.ToggleGroup OptionContent;
[SerializeField]
public TMPro.TextMeshProUGUI Des;
[SerializeField]
public RectTransform BtnContent;
[SerializeField]
public UnityEngine.UI.Button BtnPrefab;
@ -27,6 +29,7 @@ namespace QFramework.Example
{
Title = null;
OptionContent = null;
Des = null;
BtnContent = null;
BtnPrefab = null;
OptionPrefab = null;

View File

@ -4,8 +4,6 @@ using QFramework;
using System.Collections.Generic;
using TMPro;
using System;
using Microsoft.SqlServer.Server;
using XMLTool;
using static OperationController;
namespace QFramework.Example
@ -23,6 +21,8 @@ namespace QFramework.Example
public string scoreName = string.Empty;
public string format;
public string finishedEvent;
public string des;
public string cellSize;
/// <summary>
/// 0:×Ô¶¯ÅÐ¶Ï 1:µ¥Ñ¡ 2:¶àÑ¡
/// </summary>
@ -49,8 +49,13 @@ namespace QFramework.Example
{
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
mData = uiData as UITextQuestionData ?? new UITextQuestionData();
Des.text = string.Empty;
Title.text = mData.title;
OptionContent.transform.RemoveAllChildren();
if (string.IsNullOrEmpty(mData.cellSize) == false)
{
OptionContent.GetComponent<GridLayoutGroup>().cellSize = Utility.GetVector2FromStrArray(mData.cellSize);
}
for (int i = 0; i < mData.options.Count; i++)
{
var item = mData.options[i];
@ -85,6 +90,11 @@ namespace QFramework.Example
label.text = item;
obj.GetComponent<Button>().onClick.AddListener(() =>
{
if (string.IsNullOrEmpty(mData.des) == false && Des.text != string.Empty)
{
HideSelf();
return;
}
if (mData.showAnswer)
{
for (int i = 0; i < OptionContent.transform.childCount; i++)
@ -97,6 +107,7 @@ namespace QFramework.Example
}
}
// 分数名不为空
if (string.IsNullOrEmpty(mData.scoreName) == false)
{
if (mData.rightScore != 0)
@ -125,13 +136,23 @@ namespace QFramework.Example
}
}
// 解析不为空
if (string.IsNullOrEmpty(mData.des) == false)
{
if (Des.text == string.Empty)
{
Des.text = mData.des;
return;
}
}
else
{
if (mData.waitCloseTime != -1)
{
ActionKit.Delay(mData.waitCloseTime, () => HideSelf()).Start(this);
return;
}
}
HideSelf();
});
@ -181,6 +202,7 @@ namespace QFramework.Example
{
count = mData.answers.Count;
}
Des.text = mData.des;
callback?.Invoke(count);
}
}

View File

@ -807,6 +807,16 @@ namespace XMLTool
{
act.args.Add("optionType", optionType.Value);
}
XAttribute des = action.Attribute("des");
if (des != null)
{
act.args.Add("des", des.Value);
}
XAttribute cellSize = action.Attribute("cellSize");
if (cellSize != null)
{
act.args.Add("cellSize", cellSize.Value);
}
newAction = act;
}
break;

View File

@ -107,8 +107,12 @@
注意rightScore与wrongScore不能同时存在 同时存在则只生效rightScore
finishedEvent 用于监听选择题UI消失
optionType 0 根据答案数量自动判断单选还是多选 1 单选 2多选
des 答案解析 不为空的情况下 点击确定显示解析 在点确定 关闭窗口
cellSize : 选项的格子宽高 默认370,43 可以修改
-->
<Action type="TextQuestion" title="这里是标题" options="A.111|B.222|C.333|D.4444" answers="2" btns="确定" wait="1" showAnswer="true" scoreName="分数名" rightScore="5" wrongScore="-5" absolutely="false" format="{0:F1}" finishedEvent="事件名" optionType="0"></Action>
<Action type="TextQuestion" title="这里是标题" options="A.111|B.222|C.333|D.4444" answers="2" btns="确定" wait="1" showAnswer="true" scoreName="分数名" rightScore="5" wrongScore="-5" absolutely="false" format="{0:F1}" finishedEvent="事件名" optionType="0"
des="这里是答案解析"
cellSize="370,43"></Action>
<!--提示 time为显示的时间 -1则一直显示 icon是前面的绿色图标是否显示 audio是音频 位于data文件夹下的Audio-->
<Action type="Hint" value="这里是文字描述" time="5" icon="false" audio="音频.mp3"></Action>
<!--设置变量 value只能是数字可以是小数-->