You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.2 KiB
109 lines
3.2 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Xml;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class LeftRuleInit : MonoBehaviour {
|
||
|
|
||
|
public GameObject Content;
|
||
|
public GameObject ModePrefab;
|
||
|
public GameObject RuleItem;
|
||
|
public GameObject RuleRadioItem;
|
||
|
|
||
|
public List< Dictionary<string, List<string>> > rules = new List< Dictionary<string, List<string>> >();
|
||
|
public Dictionary<string, List<string>> modeRules = new Dictionary<string, List<string>>();
|
||
|
public List<string> ruleList = new List<string>();
|
||
|
|
||
|
private GameObject ruleItem;
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Awake () {
|
||
|
Content = transform.Find("Viewport/Content").gameObject;
|
||
|
|
||
|
LoadRulesData();
|
||
|
|
||
|
CteateUI();
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 加载左侧灭火规则数据
|
||
|
/// </summary>
|
||
|
private void LoadRulesData()
|
||
|
{
|
||
|
var doc = new XmlDocument();
|
||
|
|
||
|
doc.Load(Application.dataPath + @"\StreamingAssets\OperationalPreparations\OperationalPreparations.xml");
|
||
|
|
||
|
var children = doc.SelectSingleNode("Root").ChildNodes;
|
||
|
|
||
|
XmlElement left = null;
|
||
|
|
||
|
foreach (XmlElement node in children)
|
||
|
{
|
||
|
if (node.Name == "Left")
|
||
|
left = node;
|
||
|
}
|
||
|
|
||
|
if (left != null)
|
||
|
{
|
||
|
foreach (XmlElement mode in left.ChildNodes)
|
||
|
{
|
||
|
ruleList = new List<string>();
|
||
|
foreach (XmlElement rule in mode.ChildNodes)
|
||
|
{
|
||
|
ruleList.Add(rule.Attributes["name"].Value);
|
||
|
}
|
||
|
|
||
|
modeRules = new Dictionary<string, List<string>>();
|
||
|
modeRules.Add(mode.Attributes["name"].Value, ruleList);
|
||
|
rules.Add(modeRules);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据加载的数据创建UI
|
||
|
/// </summary>
|
||
|
private void CteateUI()
|
||
|
{
|
||
|
foreach (var item in rules)
|
||
|
{
|
||
|
GameObject mode = GameObject.Instantiate(ModePrefab, Content.transform) as GameObject;
|
||
|
|
||
|
string modeName = "";
|
||
|
foreach (var key in item.Keys)
|
||
|
{
|
||
|
modeName = key;
|
||
|
}
|
||
|
|
||
|
mode.transform.Find("Name/Text").GetComponent<Text>().text = modeName;
|
||
|
|
||
|
for (int i = 0; i < item[modeName].Count; i++)
|
||
|
{
|
||
|
if (modeName != "战斗展开")
|
||
|
{
|
||
|
ruleItem = GameObject.Instantiate(RuleItem, mode.transform.Find("Viewport/Content")) as GameObject;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ruleItem = GameObject.Instantiate(RuleRadioItem, mode.transform.Find("Viewport/Content")) as GameObject;
|
||
|
ruleItem.GetComponent<Toggle>().group = mode.transform.Find("Viewport/Content").GetComponent<ToggleGroup>();
|
||
|
}
|
||
|
|
||
|
ruleItem.transform.Find("Label").GetComponent<Text>().text = item[modeName][i];
|
||
|
|
||
|
if (!CurrentUserInfo.generalCommanding)
|
||
|
{
|
||
|
ruleItem.GetComponent<Toggle>().interactable = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|