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.
342 lines
13 KiB
342 lines
13 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Xml; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class BaseInfoMsgBind : MonoBehaviour |
|
{ |
|
#region 基本情况 |
|
[Rename("单位名称")] |
|
public Text Name; |
|
[Rename("企业法人")] |
|
public Text LegalPerson; |
|
[Rename("电话")] |
|
public Text LPPhone; |
|
[Rename("单位地址")] |
|
public Text Address; |
|
[Rename("消防负责人")] |
|
public Text FireChief; |
|
[Rename("电话")] |
|
public Text FCPhone; |
|
[Rename("经纬度坐标")] |
|
public Text Coordinate; |
|
[Rename("使用性质")] |
|
public Text Function; |
|
[Rename("占地面积")] |
|
public Text CoveredArea; |
|
[Rename("耐火等级")] |
|
public Text FireResistanceRating; |
|
[Rename("建筑面积")] |
|
public Text BuildArea; |
|
[Rename("建筑结构")] |
|
public Text BuildStructure; |
|
#endregion |
|
#region 周边环境 |
|
[Rename("道路东")] |
|
public Text RoadEast; |
|
[Rename("道路西")] |
|
public Text RoadWest; |
|
[Rename("道路南")] |
|
public Text RoadSouth; |
|
[Rename("道路北")] |
|
public Text RoadNorth; |
|
[Rename("建筑东")] |
|
public Text BuildingEast; |
|
[Rename("建筑西")] |
|
public Text BuildingWest; |
|
[Rename("建筑南")] |
|
public Text BuildingSouth; |
|
[Rename("建筑北")] |
|
public Text BuildingNorth; |
|
[Rename("距离东")] |
|
public Text DistanceEast; |
|
[Rename("距离西")] |
|
public Text DistanceWest; |
|
[Rename("距离南")] |
|
public Text DistanceSouth; |
|
[Rename("距离北")] |
|
public Text DistanceNorth; |
|
#endregion |
|
[Rename("一行横线预设")] |
|
public GameObject BorderH; |
|
[Rename("信息栏")] |
|
public GameObject AutoParent; |
|
#region 联动单位 |
|
[Rename("联动单位一行预设")] |
|
public GameObject PowerMsgPrefab; |
|
[Rename("联动单位标题栏")] |
|
public GameObject PowerMsgTitle; |
|
#endregion |
|
#region 罐区信息 |
|
[Rename("罐区信息一行预设")] |
|
public GameObject OilCanPrefab; |
|
[Rename("罐区信息标题栏")] |
|
public GameObject OilCanTitle; |
|
#endregion |
|
#region XML相关 |
|
private XmlDocument XmlDoc = new XmlDocument(); |
|
public string Path = @"\StreamingAssets\MainMapXml.xml"; |
|
private XmlNode BaseInfo; |
|
private XmlNode Surroundings; |
|
private XmlNode LinkageUnit; |
|
private XmlNode TankField; |
|
#endregion |
|
void Awake() |
|
{ |
|
GetAllXmlNodes(); |
|
BindBaseInfoData(); |
|
BindArroundData(); |
|
BindPowerUnitData(); |
|
BindOilCanData(); |
|
} |
|
public void ResetBaseInfo() |
|
{ |
|
Name.text = ""; |
|
LegalPerson.text = ""; |
|
LPPhone.text = ""; |
|
Address.text = ""; |
|
FireChief.text = ""; |
|
FCPhone.text = ""; |
|
Coordinate.text = ""; |
|
Function.text = ""; |
|
CoveredArea.text = ""; |
|
FireResistanceRating.text = ""; |
|
BuildArea.text = ""; |
|
BuildStructure.text = ""; |
|
} |
|
public void ResetArround() |
|
{ |
|
RoadEast.text = ""; |
|
RoadWest.text = ""; |
|
RoadSouth.text = ""; |
|
RoadNorth.text = ""; |
|
BuildingEast.text = ""; |
|
BuildingWest.text = ""; |
|
BuildingSouth.text = ""; |
|
BuildingNorth.text = ""; |
|
DistanceEast.text = ""; |
|
DistanceWest.text = ""; |
|
DistanceSouth.text = ""; |
|
DistanceNorth.text = ""; |
|
} |
|
//获取XML文档中的所有信息结点 |
|
public void GetAllXmlNodes() |
|
{ |
|
XmlDoc.Load(Application.dataPath + Path); |
|
|
|
var children = XmlDoc.SelectSingleNode("Maps").ChildNodes; |
|
XmlElement Map = null; |
|
foreach (XmlElement node in children) |
|
{ |
|
if (node.Name == "Map") |
|
{ |
|
Map = node; |
|
break; |
|
} |
|
} |
|
XmlNode DeptInfo = Map.FirstChild; |
|
foreach (XmlNode item in DeptInfo.ChildNodes) |
|
{ |
|
switch (item.Name) |
|
{ |
|
case "BaseInfo": |
|
BaseInfo = item; |
|
break; |
|
case "Surroundings": |
|
Surroundings = item; |
|
break; |
|
case "LinkageUnit": |
|
LinkageUnit = item; |
|
break; |
|
case "TankField": |
|
TankField = item; |
|
break; |
|
default: break; |
|
} |
|
} |
|
|
|
} |
|
//绑定基本情况显示方法 |
|
public void BindBaseInfoData() |
|
{ |
|
if (BaseInfo != null) |
|
{ |
|
foreach (XmlNode node in BaseInfo.ChildNodes) |
|
{ |
|
switch (node.Name) |
|
{ |
|
case "Name": |
|
Name.text = ((XmlElement)node).GetAttribute("Name"); |
|
break; |
|
case "LegalPerson": |
|
LegalPerson.text = ((XmlElement)node).GetAttribute("LegalPerson"); |
|
break; |
|
case "LPPhone": |
|
LPPhone.text = ((XmlElement)node).GetAttribute("Phone"); |
|
break; |
|
case "Address": |
|
Address.text = ((XmlElement)node).GetAttribute("Address"); |
|
break; |
|
case "FireChief": |
|
FireChief.text = ((XmlElement)node).GetAttribute("FireChief"); |
|
break; |
|
case "FCPhone": |
|
FCPhone.text = ((XmlElement)node).GetAttribute("Phone"); |
|
break; |
|
case "Coordinate": |
|
Coordinate.text = ((XmlElement)node).GetAttribute("Coordinate"); |
|
break; |
|
case "Function": |
|
Function.text = ((XmlElement)node).GetAttribute("Function"); |
|
break; |
|
case "CoveredArea": |
|
CoveredArea.text = ((XmlElement)node).GetAttribute("CoveredArea"); |
|
break; |
|
case "FireResistanceRating": |
|
FireResistanceRating.text = ((XmlElement)node).GetAttribute("FireResistanceRating"); |
|
break; |
|
case "BuildArea": |
|
BuildArea.text = ((XmlElement)node).GetAttribute("BuildArea"); |
|
break; |
|
case "BuildStructure": |
|
BuildStructure.text = ((XmlElement)node).GetAttribute("BuildStructure"); |
|
break; |
|
default: break; |
|
} |
|
} |
|
} |
|
} |
|
//绑定周边环境显示方法 |
|
public void BindArroundData() |
|
{ |
|
XmlNode ArroundNode = null; |
|
if (Surroundings != null) |
|
{ |
|
foreach (XmlNode node in Surroundings.ChildNodes) |
|
{ |
|
switch (node.Name) |
|
{ |
|
case "East": |
|
ArroundNode = node; |
|
foreach (XmlNode childnode in ArroundNode.ChildNodes) |
|
{ |
|
switch (childnode.Name) |
|
{ |
|
case "Road": |
|
RoadEast.text = ((XmlElement)childnode).GetAttribute("Road"); |
|
break; |
|
case "Building": |
|
BuildingEast.text = ((XmlElement)childnode).GetAttribute("Building"); |
|
break; |
|
case "Distance": |
|
DistanceEast.text = ((XmlElement)childnode).GetAttribute("Distance"); |
|
break; |
|
default: break; |
|
} |
|
} |
|
break; |
|
case "West": |
|
ArroundNode = node; |
|
foreach (XmlNode childnode in ArroundNode.ChildNodes) |
|
{ |
|
switch (childnode.Name) |
|
{ |
|
case "Road": |
|
RoadWest.text = ((XmlElement)childnode).GetAttribute("Road"); |
|
break; |
|
case "Building": |
|
BuildingWest.text = ((XmlElement)childnode).GetAttribute("Building"); |
|
break; |
|
case "Distance": |
|
DistanceWest.text = ((XmlElement)childnode).GetAttribute("Distance"); |
|
break; |
|
default: break; |
|
} |
|
} |
|
break; |
|
case "South": |
|
ArroundNode = node; |
|
foreach (XmlNode childnode in ArroundNode.ChildNodes) |
|
{ |
|
switch (childnode.Name) |
|
{ |
|
case "Road": |
|
RoadSouth.text = ((XmlElement)childnode).GetAttribute("Road"); |
|
break; |
|
case "Building": |
|
BuildingSouth.text = ((XmlElement)childnode).GetAttribute("Building"); |
|
break; |
|
case "Distance": |
|
DistanceSouth.text = ((XmlElement)childnode).GetAttribute("Distance"); |
|
break; |
|
default: break; |
|
} |
|
} |
|
break; |
|
case "North": |
|
ArroundNode = node; |
|
foreach (XmlNode childnode in ArroundNode.ChildNodes) |
|
{ |
|
switch (childnode.Name) |
|
{ |
|
case "Road": |
|
RoadNorth.text = ((XmlElement)childnode).GetAttribute("Road"); |
|
break; |
|
case "Building": |
|
BuildingNorth.text = ((XmlElement)childnode).GetAttribute("Building"); |
|
break; |
|
case "Distance": |
|
DistanceNorth.text = ((XmlElement)childnode).GetAttribute("Distance"); |
|
break; |
|
default: break; |
|
} |
|
} |
|
break; |
|
default: break; |
|
} |
|
} |
|
} |
|
} |
|
//绑定联动单位显示方法 |
|
public void BindPowerUnitData() |
|
{ |
|
if (LinkageUnit != null) |
|
{ |
|
if (LinkageUnit.ChildNodes.Count > 0) |
|
{ |
|
Instantiate(PowerMsgTitle, AutoParent.transform); |
|
foreach (XmlNode node in LinkageUnit.ChildNodes) |
|
{ |
|
Instantiate(BorderH, AutoParent.transform); |
|
GameObject PowerUnit = Instantiate(PowerMsgPrefab, AutoParent.transform); |
|
PowerUnit.transform.Find("NameShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("Name"); |
|
PowerUnit.transform.Find("FaRenShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("PersonInCharge"); |
|
PowerUnit.transform.Find("PhoneShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("Phone"); |
|
} |
|
Instantiate(BorderH, AutoParent.transform); |
|
} |
|
} |
|
} |
|
//绑定罐区信息显示方法 |
|
public void BindOilCanData() |
|
{ |
|
if (TankField != null) |
|
{ |
|
if (TankField.ChildNodes.Count > 0) |
|
{ |
|
Instantiate(OilCanTitle, AutoParent.transform); |
|
foreach (XmlNode node in TankField.ChildNodes) |
|
{ |
|
Instantiate(BorderH, AutoParent.transform); |
|
GameObject OilCan = Instantiate(OilCanPrefab, AutoParent.transform); |
|
//PowerUnit.transform.Find("NameShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("Name"); |
|
//PowerUnit.transform.Find("FaRenShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("PersonInCharge"); |
|
//PowerUnit.transform.Find("PhoneShow").GetComponent<Text>().text = ((XmlElement)node).GetAttribute("Phone"); |
|
} |
|
Instantiate(BorderH, AutoParent.transform); |
|
} |
|
} |
|
} |
|
|
|
}
|
|
|