UI逻辑介绍

逻辑框架一览

  • 分为四层:
    • 逻辑服务层:提供全局服务
    • 系统业务层:处理模块内部业务逻辑
    • 界面表现层:控制UI界面交互表现
    • 公共组件层:公共工具类、配置常量定义、数据模型类等

使用Queue来缓存Tips

在示例中使用了lock语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

namespace DarknessWarGodLearning
{
public class DynamicWnd : WindowRoot
{
public Animation tipsAni;
public TextMeshProUGUI textTips;

private bool isTipsShow = false;//保证tips一条一条显示
private Queue<string> tipsQue = new Queue<string>();
protected override void InitWnd()
{
base.InitWnd();
SetActive(textTips, false);
}
public void AddTipsQue(string text)
{
lock(tipsQue)//lock Queue
{
tipsQue.Enqueue(text);
}
}
private void Update()
{
if (tipsQue.Count > 0 && isTipsShow == false)
{
string tips = tipsQue.Dequeue();
SetTips(tips);
isTipsShow = true;
}
}
public void SetTips(string text)
{
SetActive(textTips);
SetText(textTips, text);

AnimationClip clip = tipsAni.GetClip("TipsShowAnime");
tipsAni.Play();

StartCoroutine(AniPlayDone(clip.length, () =>
{
SetActive(textTips, false);
isTipsShow = false;
}));
}
IEnumerator AniPlayDone(float sec,Action cb)
{
yield return new WaitForSeconds(sec);
cb?.Invoke();
}
}
}

使用Excel配置XML

使用Excel的开发工具面板导入XML配置和导出XML。

Excel的开发工具面板需要在“文件——选项——自定义功能区”中打开。

首先在“开发工具面板——XML”导入XML格式文件,Excel能自动识别格式。然后在Excel当中填入配置数据,再在“开发工具面板——XML”导出XML格式文件

读取XML配置的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#region 初始化各种配置文件
private List<string> surnameList = new List<string>(10);
private List<string> manList = new List<string>(10);
private List<string> womanList = new List<string>(10);
private void InitRDNameCfg()
{
TextAsset rdNameCfgText = Resources.Load<TextAsset>(PathDefine.RDNameCfgPath);
if(rdNameCfgText != null)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(rdNameCfgText.text);

XmlNodeList nodeList = xmlDocument.SelectSingleNode("root").ChildNodes;
for (int i = 0; i < nodeList.Count; i++)
{
XmlElement ele = nodeList[i] as XmlElement;
if (ele.GetAttributeNode("ID") == null) continue;

int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText);
foreach (XmlElement e in nodeList[i].ChildNodes)//将ChildNode强制转换为XMLElement
{
switch (e.Name)
{
case "surname":
surnameList.Add(e.InnerText);
break;
case "man":
manList.Add(e.InnerText);
break;
case "woman":
womanList.Add(e.InnerText);
break;
}
}
}
}else
{
Debug.LogError("xml file:" + PathDefine.RDNameCfgPath + "nor exist");
}
}
#endregion