工具类添加去掉空行方法,按钮点击,显示不同提示音频方法

This commit is contained in:
李浩 2025-05-27 11:56:08 +08:00
parent 7efc347595
commit 339c287691
9 changed files with 199 additions and 87 deletions

View File

@ -71,7 +71,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1177232684554755630
RectTransform:
m_ObjectHideFlags: 0

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 05b7496d94e7d684a8bf1c3320f42908
guid: df2e785befb47a243b3607ae7a6e5508
DefaultImporter:
externalObjects: {}
userData:

View File

@ -451,6 +451,44 @@ public class Utility
}
}
/// <summary>
/// 去除字符串中的空格和空行
/// </summary>
/// <param name="input">输入字符串</param>
/// <param name="removeAllSpaces">是否移除所有空格(包括字符串内部的空格)</param>
/// <returns>处理后的字符串</returns>
///
//// 处理提示文本,保留内部空格但移除空行
//string cleanTipText = Utility.RemoveSpacesAndEmptyLines(mData.tiptext);
//// 处理音频名称,移除所有空格
//string cleanTipAudio = Utility.RemoveSpacesAndEmptyLines(mData.tipaudio, true);
public static string RemoveSpacesAndEmptyLines(string input, bool removeAllSpaces = false)
{
if (string.IsNullOrEmpty(input))
return input;
// 分割字符串为行
string[] lines = input.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder result = new StringBuilder();
foreach (string line in lines)
{
string trimmedLine = line.Trim();
if (string.IsNullOrEmpty(trimmedLine))
continue; // 跳过空行
// 根据参数决定是否移除所有空格
if (removeAllSpaces)
{
trimmedLine = trimmedLine.Replace(" ", "");
}
result.AppendLine(trimmedLine);
}
return result.ToString().TrimEnd(); // 移除末尾的换行符
}
}

View File

@ -657,7 +657,7 @@ Transform:
m_GameObject: {fileID: 240304286}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.088, y: -0.011, z: 0.111}
m_LocalPosition: {x: -0.088, y: 0, z: 0.111}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -670,7 +670,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 240304286}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -740,7 +740,7 @@ Transform:
m_GameObject: {fileID: 248517710}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.192, y: 0.32, z: 0.111}
m_LocalPosition: {x: -0.2, y: 0.32, z: 0.111}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -753,7 +753,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 248517710}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -841,7 +841,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 261523058}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -1736,7 +1736,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -3568217860067444917, guid: 377e2d7235d2ffd4684c67b1127d172f, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: -3568217860067444917, guid: 377e2d7235d2ffd4684c67b1127d172f, type: 3}
propertyPath: m_StaticEditorFlags
@ -1828,7 +1828,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6047383785361520804, guid: 377e2d7235d2ffd4684c67b1127d172f, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6047383785361520804, guid: 377e2d7235d2ffd4684c67b1127d172f, type: 3}
propertyPath: m_StaticEditorFlags
@ -2933,7 +2933,7 @@ Transform:
m_GameObject: {fileID: 1020759834}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.009, y: 0.583, z: 0.2107}
m_LocalPosition: {x: 0.0007106997, y: 0.59896326, z: 0.20234376}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -2946,7 +2946,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1020759834}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -3174,7 +3174,7 @@ Transform:
m_GameObject: {fileID: 1032994694}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.009, y: 0.591, z: 0.109}
m_LocalPosition: {x: -0.0022, y: 0.5972, z: 0.109}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -3187,7 +3187,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1032994694}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -4323,7 +4323,7 @@ Transform:
m_GameObject: {fileID: 1434451487}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.106, y: 0.583, z: 0.111}
m_LocalPosition: {x: -0.106, y: 0.6034, z: 0.111}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -4336,7 +4336,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1434451487}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -5715,7 +5715,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1822372371}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@ -5911,7 +5911,7 @@ Transform:
m_GameObject: {fileID: 1910722536}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.007, y: 0.32, z: 0.205}
m_LocalPosition: {x: -0.0015, y: 0.32, z: 0.1981}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
@ -5924,7 +5924,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910722536}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1

View File

@ -63,7 +63,7 @@ namespace QFramework
public void OnFinish()
{
Debug.Log("Action OnFinish???");
// Debug.Log("Action OnFinish???");
}
public void OnStart()
@ -74,7 +74,8 @@ namespace QFramework
data.showName = datas.ContainsKey("showName") ? datas["showName"] : string.Empty;
data.offestPos= datas.ContainsKey("offSet") ? datas["offSet"] : string.Empty;
//添加个,点击按钮 ,显示不同的提示和语音的功能。
data.offestPos = datas.ContainsKey("tiptextAudio") ? datas["tiptextAudio"] : string.Empty;
data.tiptext = datas.ContainsKey("tiptext") ? datas["tiptext"] : string.Empty;
data.tipaudio = datas.ContainsKey("tipaudio") ? datas["tipaudio"] : string.Empty;
UIKit.OpenPanelAsync<UIGuideTip>(uiData: data, canvasLevel: UILevel.Common).ToAction().StartGlobal(() =>
{

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using static UnityEngine.GraphicsBuffer;
using UnityEngine.Assertions;
using static System.Net.Mime.MediaTypeNames;
namespace QFramework.Example
{
@ -20,7 +21,8 @@ namespace QFramework.Example
public string offestPos;
public string tiptextAudio;
public string tiptext;
public string tipaudio;
}
@ -76,7 +78,8 @@ namespace QFramework.Example
Debug.Log(mData);
List<String> Objs = mData.targets.Split(',')?.ToList();
List<String> ShowTexts = mData.showName.Split(',')?.ToList();
List<String> textTip =mData.tiptextAudio.Split(',')?.ToList();
List<String> Tip = mData.tiptext.Split(',')?.ToList();
List<String> audio = mData.tipaudio.Split(',')?.ToList();
if (String.IsNullOrEmpty(mData.offestPos) == false)
{
@ -85,7 +88,7 @@ namespace QFramework.Example
for (int i = 0; i < TipOffects.Count; i++)
{
Vector3 TipOffect = Utility.GetVector3FromStrArray(TipOffects[i]);
Debug.Log(TipOffect + "??????????");
// Debug.Log(TipOffect + "??????????");
TipOffectList.Add(TipOffect);
}
}
@ -103,11 +106,15 @@ namespace QFramework.Example
TipItemList.Add(tipItemObj);
tipItemObj.name = Objs[i];
GameObject target = GameObject.Find(Objs[i].ToString());
if (target==null)
if (target == null)
{
Debug.Log("出现异常,没有找到该物体");
}
tipItemObj.GetComponentInChildren<Text>().text = ShowTexts[i];
//Tip文字名称
tipItemObj.GetComponentInChildren<UnityEngine.UI.Text>().text = ShowTexts[i];
UpdatePos(
target,
GetComponentInParent<Canvas>(),
@ -119,6 +126,55 @@ namespace QFramework.Example
);
}
if (Tip.Count != 0 || audio.Count != 0)
{
// 计算两个列表的最小长度,确保安全索引范围
int minListCount = Math.Min(Tip.Count, audio.Count);
int buttonCount = TipItemList.Count;
for (int i = 0; i < buttonCount; i++)
{
var tipButton = TipItemList[i].transform.Find("tip").GetComponent<Button>();
tipButton.onClick.RemoveAllListeners();
// 创建当前索引的局部副本,解决闭包问题
int currentIndex = i;
tipButton.onClick.AddListener(() => {
// 确保索引在有效范围内
int safeIndex = Math.Min(currentIndex, minListCount - 1);
if (safeIndex >= 0 && safeIndex < Tip.Count && safeIndex < audio.Count)
{
Debug.Log(Tip[safeIndex] + "Tip");
Debug.Log(audio[safeIndex] + "audio");
// 处理提示文本,保留内部空格但移除空行
Tip[safeIndex] = Utility.RemoveSpacesAndEmptyLines(Tip[safeIndex]);
// 处理音频名称,移除所有空格
audio[safeIndex] = Utility.RemoveSpacesAndEmptyLines(audio[safeIndex], true);
//赋值按钮
var data = new UITextWindowData
{
text = Tip[safeIndex],
audio = audio[safeIndex]
};
UIKit.OpenPanelAsync<UITextWindow>(uiData: data, canvasLevel: UILevel.PopUI)
.ToAction()
.Start(this);
}
else
{
Debug.LogWarning($"索引 {currentIndex} 超出数据范围Tip.Count={Tip.Count}, audio.Count={audio.Count}");
}
});
}
}
}
@ -128,10 +184,8 @@ namespace QFramework.Example
}
//private void OnCloseSelf(string[] obj)
//{
// CloseSelf();
//}
@ -147,7 +201,7 @@ namespace QFramework.Example
GameObject target = GameObject.Find(TipItemList[i].name);
Debug.Log("LateUpdate");
//Debug.Log("LateUpdate");
UpdatePos(
target,
@ -219,7 +273,7 @@ namespace QFramework.Example
float length = (YuanDian.transform.position - tip.transform.position).magnitude;
//设置线的宽度 长度
zhiyinxian.GetComponent<RectTransform>().sizeDelta = new Vector2(length, 3f);
Debug.Log("UpdatePos");
//Debug.Log("UpdatePos");
}

View File

@ -1769,15 +1769,17 @@ namespace XMLTool
act.args.Add("offSet", offSet.Value);
}
XAttribute tiptextAudio = action.Attribute("tiptextAudio");
if (offSet != null)
XAttribute tiptext = action.Attribute("tiptext");
if (tiptext != null)
{
act.args.Add("tiptextAudio", tiptextAudio.Value);
act.args.Add("tiptext", tiptext.Value);
}
else
XAttribute tipaudio = action.Attribute("tipaudio");
if (tipaudio != null)
{
Debug.Log("暂时为空");
act.args.Add("tipaudio", tipaudio.Value);
}
newAction = act;
}

View File

@ -73,7 +73,7 @@
<Condition type="UIClick" value="UIRoot/PopUI/UITextTip/Mask/Content/BtnContent/确定"></Condition>
<Action type="TextWindow" title="棱柱说明" value="四棱柱:有两个面互相平行,其余每相邻两个面的交线都互相平行的多面体叫作棱柱。
<!--<Action type="TextWindow" title="棱柱说明" value="四棱柱:有两个面互相平行,其余每相邻两个面的交线都互相平行的多面体叫作棱柱。
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。
上底面的边长叫做棱柱的上底面边长
互相平行的两个面叫作棱柱的底面,位于棱柱下面,叫底面。
@ -83,26 +83,26 @@
两个底面间的距离叫作棱柱的高
底面边长与侧棱汇交的点叫做棱柱的顶点。
" position="right" scrollSpeed="25"/>
" position="right" scrollSpeed="25"/>-->
<Action type="Show" value="Main/A_SM_LengZhu" isShow="true" isDevice="false"></Action>
<Action type="UIGuideTip"
targetName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
offSet="200,0,0|200,0,0|200,0,0|-200,0,0|200,0,0|200,0,0|200,0,0|200,0,0"
showName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
tiptextAudio="
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。|sound5,
上底面的边长叫做棱柱的上底面边长|sound6,
底面的边长叫做棱柱的底面边长|sound7,
棱柱其余各面叫作棱柱的侧面|sound8,
相邻两个侧面的公共边叫作棱柱的侧棱|sound9,
两个底面间的距离叫作棱柱的高|sound10,
底面边长与侧棱汇交的点叫做棱柱的顶点。|sound11"
></Action>
targetName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
offSet="200,100,0|-200,100,0|-200,-80,0|250,50,0|-250,50,0|300,0,0|-300,50,0|-200,150,0"
showName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
tiptext="
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。,
上底面的边长叫做棱柱的上底面边长,
互相平行的两个面叫作棱柱的底面,位于棱柱下面,叫底面。,
底面的边长叫做棱柱的底面边长,
棱柱其余各面叫作棱柱的侧面,
相邻两个侧面的公共边叫作棱柱的侧棱,
两个底面间的距离叫作棱柱的高,
底面边长与侧棱汇交的点叫做棱柱的顶点。"
tipaudio="sound4.mp3 , sound5.mp3 , sound6.mp3 , sound7.mp3 , sound8.mp3 ,sound9.mp3,sound10.mp3,sound11.mp3" ></Action>
</Action>
</Enter>
@ -134,21 +134,34 @@
<!--<Action type="UIShow" value="UIGuideTip" isShow="true"></Action>-->
<Action type="UIGuideTip"
targetName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
offSet="200,0,0|200,0,0|200,0,0|-200,0,0|200,0,0|200,0,0|200,0,0|200,0,0"
showName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
tiptextAudio="
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。|sound5,
上底面的边长叫做棱柱的上底面边长|sound6,
底面的边长叫做棱柱的底面边长|sound7,
棱柱其余各面叫作棱柱的侧面|sound8,
相邻两个侧面的公共边叫作棱柱的侧棱|sound9,
两个底面间的距离叫作棱柱的高|sound10,
底面边长与侧棱汇交的点叫做棱柱的顶点。|sound11"
targetName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
offSet="200,100,0|-200,100,0|-200,-80,0|250,50,0|-250,50,0|300,0,0|-300,50,0|-200,150,0"
showName="棱柱上底面,棱柱上底面边长,棱柱底面,棱柱底面边长,棱柱侧面,侧棱,棱柱棱高,棱柱顶点"
tiptext="
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。,
上底面的边长叫做棱柱的上底面边长,
互相平行的两个面叫作棱柱的底面,位于棱柱下面,叫底面。,
底面的边长叫做棱柱的底面边长,
棱柱其余各面叫作棱柱的侧面,
相邻两个侧面的公共边叫作棱柱的侧棱,
两个底面间的距离叫作棱柱的高,
底面边长与侧棱汇交的点叫做棱柱的顶点。"
></Action>
tipaudio="
sound4.mp3,
sound5.mp3 ,
sound6.mp3,
sound7.mp3 ,
sound8.mp3 ,
sound9.mp3 ,
sound10.mp3 ,
sound11.mp3
" ></Action>
<Action type="TextWindow" title="棱柱说明" value="四棱柱:有两个面互相平行,其余每相邻两个面的交线都互相平行的多面体叫作棱柱。
<!--<Action type="TextWindow" title="棱柱说明" value="四棱柱:有两个面互相平行,其余每相邻两个面的交线都互相平行的多面体叫作棱柱。
互相平行的两个面叫作棱柱的底面,位于棱柱上面,叫上底面。
上底面的边长叫做棱柱的上底面边长
互相平行的两个面叫作棱柱的底面,位于棱柱下面,叫底面。
@ -158,7 +171,11 @@
两个底面间的距离叫作棱柱的高
底面边长与侧棱汇交的点叫做棱柱的顶点。
" position="right" scrollSpeed="25"/>
" position="right" scrollSpeed="25"/>-->
</Action>
</Enter>
@ -187,12 +204,12 @@
offSet="200,0,0 |200,0,0|-200,0,0|200,0,0 |200,0,0|-200,0,0"
showName="棱锥底面,棱锥底面边长,棱锥侧面,棱锥侧棱,棱锥棱高,棱锥顶点"
tiptextAudio="
底面:其中的多边形叫作棱锥的底面。|sound18,
底面的边长叫做棱锥的底面边长|sound19,
底面的边长叫做棱柱的底面边长|sound20,
相邻两个侧面的公共边叫作棱柱的侧棱|sound21,
相邻两个侧面的公共边叫作棱柱的侧棱|sound22,
各侧面的公共顶点叫作棱锥的顶点|sound23, "
底面:其中的多边形叫作棱锥的底面。|sound18.mp3,
底面的边长叫做棱锥的底面边长|sound19.mp3,
底面的边长叫做棱柱的底面边长|sound20.mp3,
相邻两个侧面的公共边叫作棱柱的侧棱|sound21.mp3,
相邻两个侧面的公共边叫作棱柱的侧棱|sound22.mp3,
各侧面的公共顶点叫作棱锥的顶点|sound23.mp3, "
@ -236,8 +253,8 @@
offSet="200,0,0|200,0,0"
showName="球体圆心,球体半径"
tiptextAudio="
半圆的圆心叫作球心。|sound51,
半圆的半径叫作球的半径。|sound52"
半圆的圆心叫作球心。|sound51.mp3,
半圆的半径叫作球的半径。|sound52.mp3"
></Action>
@ -285,11 +302,11 @@
offSet="200,0,0|200,0,0|-200,0,0|200,0,0|200,0,0"
showName="圆柱轴,圆柱底面,圆柱侧面,圆柱母线,圆柱高"
tiptextAudio="
旋转轴叫作圆柱的轴。|sound29,
垂直于轴的边旋转形成的圆面叫作圆柱的底面。|sound30,
平行于轴的边旋转形成的曲面叫作圆柱的侧面。|sound31,
无论旋转到什么位置,这条边都叫作侧面的母线。|sound32,
两个底面间的距离叫作圆柱的高。|sound33,"
旋转轴叫作圆柱的轴。|sound29.mp3,
垂直于轴的边旋转形成的圆面叫作圆柱的底面。|sound30.mp3,
平行于轴的边旋转形成的曲面叫作圆柱的侧面。|sound31.mp3,
无论旋转到什么位置,这条边都叫作侧面的母线。|sound32.mp3,
两个底面间的距离叫作圆柱的高。|sound33.mp3,"
></Action>
<Action type="Log" value="圆柱FINISH"></Action>
@ -333,12 +350,12 @@
offSet="200,0,0|200,0,0|-200,0,0|200,0,0|200,0,0|200,0,0"
showName="圆锥轴,圆锥高,圆锥轴,圆锥高,圆锥轴,圆锥高"
tiptextAudio="
旋转轴叫作圆锥的轴。|sound40,
另一条直角边旋转而形成的圆面叫作底面。|sound41,
斜边旋转而形成的曲面叫作侧面。|sound42,
无论旋转到什么位置,这条边都叫作侧面的母线。|sound43,
母线与轴的交点叫作顶点。|sound44,
顶点到底面的距离叫作圆锥的高|sound45"
旋转轴叫作圆锥的轴。|sound40.mp3,
另一条直角边旋转而形成的圆面叫作底面。|sound41.mp3,
斜边旋转而形成的曲面叫作侧面。|sound42.mp3,
无论旋转到什么位置,这条边都叫作侧面的母线。|sound43.mp3,
母线与轴的交点叫作顶点。|sound44.mp3,
顶点到底面的距离叫作圆锥的高|sound45.mp3"