1、布局好场景(即需要展示的列表布局及其需要生成的数据行,且给需要显示数据的数据行添加Tag标签制作成预制体)
2、对应的界面表格生成数据加载代码
/***
* Title:"智慧工厂" 项目
* 主题:视图层:高温干燥车间的信息以表格方式展示
* Description:
* 功能:
* 1、创建展示信息的表格
* 2、在表格中加载对应的信息
* Date:2018
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Global;
using kernal;
using Control;
namespace View
{
public class View_Display_HighTemperatureDryingWorkshopXML : MonoBehaviour
{
#region 表格的基础参数
public GameObject totalRowBG; //所有数据行的背景
public Transform gridRowParent; //表格行的父节点
private string _RowDataTag = "HTDRTRowData"; //高温干燥车间---实时报警列表数据行的标签
private string _DataRowOne = "GridRow"; //数据行1预制体名称
private string _DataRowOne_PrefabPath = "Intelligent3DFactory/AlarmList/HighTemperatureDryingWorkshop/GridRow"; //数据行1预制体路径
private Vector3 _GridOne_Pos; //第一个行预制体的基础位置信息
private Dictionary _RowPrefabNameAndSelf; //表格数据行预制体物体名字
private List _CurrentGridAllRow; //当前表格的所有数据行预制体
private List _DisplayText; //数据行物体的每个显示物体Text
public Text girdPageNumberText; //表格的当前页码文本Text
//表格定义
public int gridSpace = 50; //表格之间的间隔
public int gridRowNumber = 8; //设置的表格的最大行数
private int _CurrentPageNumber = 1; //当前的表格页码
private int _AddPageNumber = 2; //与当前页码做对比的页码
private int _GridRowStartIndex = 1; //表格行的开始索引
#endregion
#region 表格需要的数据、显示组件
//高温干燥车间的XML文件信息
private int _HTDRTTotalRowNum = 0; //实时报警---高温干燥车间车间XML数据的总条数
private int _CurrentPageHTDRTRowNum; //当前页码的实时报警---高温干燥车间车间XML的数据条数
private List _HTDRTXmlAllInfo; //实时报警---高温干燥车间XML的所有信息
private Ctrl_Single_HighTemperatureDryingWorkshopData _SingleHTDRTData; //单条的实时报警---高温干燥车间数据
//查询
private List _QueryData; //实时报警---高温干燥车间XML的所有信息
//下拉列表集合
private List _Brand; //品牌列表
/*任务报表预制体行的显示Text*/
//表格行预制体1的文本
private Transform Text_SerialNum; //序号
private Transform Text_AlarmTime; //时间、日期
private Transform Text_AlarmEquipArea; //报警设备、区域
private Transform Text_Duration; //持续时间
private Transform Text_AlarmNumbers; //报警次数
private Transform Text_AlarmFaultDescription; //报警、故障描述
//查询与重置的输入框
public InputField Input_RmRTTimeOrDate; //实时报警时间
public InputField Input_RmRTEquipOrArea; //实时报警区域、设备
public InputField Input_RmRTFaultDescription; //实时报警故障描述
//表格行包含的显示文本的名字
private string _Text_SerialNumber = "Text_SerialNumber";
private string _Text_DateTime = "Text_DateTime";
private string _Text_AlarmEquipmentOrArea = "Text_AlarmEquipmentOrArea";
private string _Text_Duration = "Text_Duration";
private string _Text_AlarmNumbers = "Text_AlarmNumbers";
private string _Text_FaultDescription = "Text_FaultDescription";
#endregion
void Start()
{
Ctrl_Display_HighTemperatureDryingWorkshopXML.GetInstance().Start();
/*获取基础的表格数据行预制体物体位置*/
//获得第一个行预制体的基础位置信息
GameObject GridOne_Prefabs;
GridOne_Prefabs = LoadPrefabs.GetInstance().GetLoadPrefab(_DataRowOne_PrefabPath);
_GridOne_Pos = new Vector3(GridOne_Prefabs.transform.localPosition.x, GridOne_Prefabs.transform.localPosition.y, GridOne_Prefabs.transform.localPosition.z);
//初始生成(布局)表格,且加载数据
InitGird();
}
#region 公用的按钮方法
///
/// 查询按钮
///
public void BtnSearch()
{
string Input_RmRTTimeOrDate1 = Input_RmRTTimeOrDate.text.Trim();
string Input_RmRTEquipOrArea1 = Input_RmRTEquipOrArea.text.Trim();
string Input_RmRTFaultDescription1 = Input_RmRTFaultDescription.text.Trim();
//print("输入的任务号="+ Input_TaskReportNum);
//print("输入的品牌码=" + Input_TaskBrandCode);
//print("选择的品牌=" + Input_TaskBrnd);
//显示任务号查询信息
if (!string.IsNullOrEmpty(Input_RmRTTimeOrDate1))
{
Search(Input_RmRTTimeOrDate1);
}
//显示品牌码的查询信息
if (!string.IsNullOrEmpty(Input_RmRTEquipOrArea1))
{
Search(Input_RmRTEquipOrArea1);
}
//显示品牌的查询信息
if (!string.IsNullOrEmpty(Input_RmRTFaultDescription1))
{
Search(Input_RmRTFaultDescription1);
}
//显示所有数据
if (string.IsNullOrEmpty(Input_RmRTTimeOrDate1) && string.IsNullOrEmpty(Input_RmRTEquipOrArea1) && string.IsNullOrEmpty(Input_RmRTFaultDescription1))
{
//先获取表格的数据行
GetGridCurrentAllRowData(_RowDataTag);
//销毁存在的数据行
DestroyAppointPrefabs_PageDown(1, _CurrentGridAllRow.Count);
//加载第一页数据到表格中
LoadTaskReportXmlInfoToGrid(1, _CurrentPageHTDRTRowNum, 1);
}
}
///
/// 重置按钮
///
public void BtnReset()
{
if (Input_RmRTTimeOrDate.text.Trim() != null || Input_RmRTEquipOrArea.text.Trim() != null || Input_RmRTTimeOrDate.text.Trim() != null)
{
//输入框清空
Input_RmRTTimeOrDate.text = "";
Input_RmRTEquipOrArea.text = "";
Input_RmRTTimeOrDate.text = "";
//基础表格信息重置
_CurrentPageNumber = 1;
_AddPageNumber = 2;
_GridRowStartIndex = 1;
//列表清空
_RowPrefabNameAndSelf.Clear();
_CurrentGridAllRow.Clear();
_DisplayText.Clear();
_HTDRTXmlAllInfo.Clear();
//销毁原来的数据行,隐藏示错误提示面板
DestroyOriginalRowData(false);
//初始化表格
InitGird();
}
}
///
/// 上一页按钮
///
public void BtnPageUp()
{
//获得当前页码
_CurrentPageNumber -= 1;
//根据页码加载对应的表格与数据信息
if (_CurrentPageNumber > 0)
{
//获取当前的页码需要展示的XML数据条数
_CurrentPageHTDRTRowNum += gridRowNumber;
//获取当前页码对应表格的行开始索引
_GridRowStartIndex -= gridRowNumber;
//销毁下一页的预制体
DestroyAppointPrefabs_PageUp(_CurrentPageNumber - 1, gridRowNumber);
//获取到当前页码需要加载任务报表XML数据
LoadTaskReportXmlInfoToGrid(_GridRowStartIndex, _CurrentPageHTDRTRowNum, _CurrentPageNumber);
}
else
{
_CurrentPageNumber = 1;
//重置表格行的开始索引
_GridRowStartIndex = 1;
//给表格页码赋值
AddCurrentPageNumber(girdPageNumberText, _CurrentPageNumber);
//Debug.Log(GetType() + "/BtnPageUp()/当前页码重置为1");
//显示信息提示框及其内容
InfoTipsFrame.GetInstance().DisplayTipsFrameAndContents(totalRowBG, "信息提示", "不存在上一页数据");
}
}
///
/// 下一页按钮
///
public void BtnPageDown()
{
//获得当前页码
_CurrentPageNumber += 1;
//根据页码加载对应的表格与数据信息
if (_CurrentPageNumber > 1 && _CurrentPageNumber < _AddPageNumber)
{
//获取当前的页码需要展示的XML数据条数
_CurrentPageHTDRTRowNum -= gridRowNumber;
//获取当前页码对应表格的行开始索引
_GridRowStartIndex += gridRowNumber;
//销毁前一页的预制体
DestroyAppointPrefabs_PageDown(_CurrentPageNumber - 1, gridRowNumber);
//获取到当前页码需要加载任务报表XML数据
LoadTaskReportXmlInfoToGrid(_GridRowStartIndex, _CurrentPageHTDRTRowNum, _CurrentPageNumber);
}
else
{
_CurrentPageNumber -= 1;
//给表格页码赋值
AddCurrentPageNumber(girdPageNumberText, _CurrentPageNumber);
//Debug.Log(GetType() + "/BtnPageUp()/当前页码不变");
//显示信息提示框及其内容
InfoTipsFrame.GetInstance().DisplayTipsFrameAndContents(totalRowBG, "信息提示", "不存在下一页数据");
}
}
#endregion
#region 生成基础表格方法
///
/// 初始化表格
///
private void InitGird()
{
//获取到任务报表xml中的所有信息
GetAllTaskReportInfo();
//获取到当前页码需要加载任务报表XML数据
_CurrentPageHTDRTRowNum = _HTDRTTotalRowNum;
//print("当前的XML数据条数=" + _CurrentPageTaskReportRowNum);
//加载第一页数据到表格中
LoadTaskReportXmlInfoToGrid(1, _CurrentPageHTDRTRowNum, 1);
}
///
/// 生成(布局)表格
///
/// 表格行生成的索引
/// 表格行的数量
private void MakeGrid(int startIndex, int rowNumbers)
{
//下一页的数据行位置起点
int row = 0;
//当前页对应的表格所显示的行数
int displayCurentPageRowNum = 0;
displayCurentPageRowNum = rowNumbers + ((_CurrentPageNumber - 1) * gridRowNumber);
//print("第2页的行总数"+displayCurentPageRowNum);
_RowPrefabNameAndSelf = new Dictionary();
//设置每页可以生成1到12行的数据表格
if (rowNumbers >= 1 && rowNumbers <= 12)
{
for (int i = startIndex; i <= displayCurentPageRowNum; i++)
{
//print("生成行预制体的索引="+ startIndex);
GameObject MakeRow1;
MakeRow1 = LoadDataRowPrefabs(_DataRowOne_PrefabPath);
MakeRow1.transform.parent = gridRowParent;
MakeRow1.name = MakeRow1.name + i;
//重置预制体的位置
if (i > gridRowNumber)
{
row = i - (_CurrentPageNumber - 1) * gridRowNumber;
//print("重置后的i="+row);
MakeRow1.transform.localPosition = new Vector3(_GridOne_Pos.x, _GridOne_Pos.y - gridSpace * (row - 1), _GridOne_Pos.z);
}
else
{
MakeRow1.transform.localPosition = new Vector3(_GridOne_Pos.x, _GridOne_Pos.y - gridSpace * (i - 1), _GridOne_Pos.z);
}
MakeRow1.transform.localScale = new Vector3(1, 1, 1);
_RowPrefabNameAndSelf.Add(MakeRow1.name, MakeRow1);
//print("数据行1");
}
}
else
{
Debug.LogError(GetType() + "/MakeGrid()/表格生成失败,请检查rowNumbers需要生成的表格是否大于1小于12!!!");
}
}
///
/// 加载数据行预制体到面板中
///
/// 预制体路径和名称
private GameObject LoadDataRowPrefabs(string PrefabsPathAndName)
{
//加载预制体
GameObject RowDataPrefab = LoadPrefabs.GetInstance().GetLoadPrefab(PrefabsPathAndName);
//将加载的数据行预制体作为背景的子物体
RowDataPrefab.transform.parent = totalRowBG.transform;
RowDataPrefab.transform.localPosition = new Vector3(_GridOne_Pos.x, _GridOne_Pos.y, _GridOne_Pos.z);
RowDataPrefab.transform.localScale = new Vector3(1, 1, 1);
return RowDataPrefab;
}
///
/// 获取到实时报警--高温干燥车间车间xml中的所有信息
///
private void GetAllTaskReportInfo()
{
Ctrl_Analysis_HighTemperatureDryingWorkshopXML.GetInstance().GetHTDRTXMLInfo(Global_Parameter.REALTIME_HighTemperatureDryingWorkshop_NAME, Global_Parameter.REALTIME_HighTemperatureDryingWorkshop_ROOTName);
_HTDRTXmlAllInfo = Ctrl_Analysis_HighTemperatureDryingWorkshopXML.GetInstance().GetAllHTDRTInfo();
//获得实时报警--成品库车间XML数据的总条数
_HTDRTTotalRowNum = _HTDRTXmlAllInfo.Count;
}
///
/// 根据页码加载XML设备信息到对应的表格中
///
/// 需要显示的XML数据条数
private void LoadTaskReportXmlInfoToGrid(int startIndex, int displayXmlRowNum, int curPageNum)
{
//print("加载XML数据到表格中的索引=" + startIndex);
//print("当前表格页码加载的行数=" + displayXmlRowNum);
//print("当前的页码="+curPageNum);
//判断数据是否存在
if (displayXmlRowNum >= 1)
{
if (displayXmlRowNum > gridRowNumber)
{
//生成(布局)表格
MakeGrid(startIndex, gridRowNumber);
//增加的页码
_AddPageNumber += 1;
//给当前的表格添加对应的XML信息
LoadXmlInfoToCurrentGridPage(startIndex, gridRowNumber);
//给表格页码赋值
AddCurrentPageNumber(girdPageNumberText, curPageNum);
}
else
{
//生成(布局)表格
MakeGrid(startIndex, displayXmlRowNum);
//当前页码
//给当前的表格添加对应的XML信息
LoadXmlInfoToCurrentGridPage(startIndex, displayXmlRowNum);
//给表格页码赋值
AddCurrentPageNumber(girdPageNumberText, curPageNum);
}
}
}
///
/// 通过名字获取到对应的物体
///
/// 需要查找的物体名字
///
private GameObject GetGoFromName(string name)
{
GameObject go = null;
if (!string.IsNullOrEmpty(name))
{
if (_RowPrefabNameAndSelf.ContainsKey(name))
{
go = _RowPrefabNameAndSelf[name];
}
}
return go;
}
///
/// 查找数据行下的所有Text子物体
///
private void SearchTexts(GameObject go)
{
if (go != null)
{
//实例化
_DisplayText = new List();
//获取行组件下面的所有Text物体
int Numlable = go.transform.childCount;
if (go.transform.GetChild(0)!=null)
{
foreach (Transform Text in go.transform.GetChild(0))
{
_DisplayText.Add(Text);
}
_DisplayText.Add(go.transform.GetChild(0).GetChild(0));
if (go.transform.GetChild(1) != null)
{
foreach (Transform Text in go.transform.GetChild(1))
{
_DisplayText.Add(Text);
}
}
}
}
}
///
/// 获取列表中对应的显示文本物体
///
/// 文本Text名称
///
private Transform GetSingleDisplayText(string TextName)
{
Transform DisplayText = null;
if (!string.IsNullOrEmpty(TextName))
{
for (int i = 0; i < _DisplayText.Count; i++)
{
if (_DisplayText[i].name.Trim() == TextName)
{
DisplayText = _DisplayText[i];
}
}
}
return DisplayText;
}
///
/// 给当前表格页码赋值
///
/// 表格页码显示组件
/// 当前显示页码数字
private void AddCurrentPageNumber(Text curPageNumText, int curPageNum)
{
if (curPageNumText != null)
{
curPageNumText.text = curPageNum.ToString();
}
else
{
Debug.LogError(GetType() + "/AddCurrentPageNumber()/当前的表格页码显示组件不存在,请检查");
}
}
///
/// 销毁指定的预制体(下一页按钮)
///
/// 开始销毁的索引
/// 所需要销毁物体的行数
private void DestroyAppointPrefabs_PageDown(int startIndex, int rowNum)
{
int startIndex1 = 0;
int rowNumber = 0;
startIndex1 = (startIndex - 1) * gridRowNumber;
rowNumber = startIndex1 * rowNum;
if (startIndex1 == 0)
{
for (int i = 1; i <= gridRowNumber; i++)
{
//print("销毁索引=" + i);
//print("销毁行数=" + i);
//销毁对应预制体
DestoryPrefabs(i);
}
}
else
{
for (int i = startIndex1; i <= rowNumber; i++)
{
//print("销毁索引=" + i);
//print("销毁行数=" + i);
//销毁对应预制体
DestoryPrefabs(i);
}
}
}
///
/// 销毁指定的预制体(上一页按钮)
///
/// 开始销毁的索引
/// 所需要销毁物体的行数
private void DestroyAppointPrefabs_PageUp(int startIndex, int rowNum)
{
int startIndex1 = 0;
int rowNumber = 0;
startIndex1 = (startIndex + 1) * gridRowNumber;
rowNumber = startIndex1 * rowNum;
if (startIndex1 == 0)
{
for (int i = 1; i <= gridRowNumber; i++)
{
//print("销毁索引=" + i);
//print("销毁行数=" + i);
//销毁对应预制体
DestoryPrefabs(i);
}
}
else
{
for (int i = startIndex1; i <= rowNumber; i++)
{
//print("销毁索引=" + i);
//print("销毁行数=" + i);
//销毁对应预制体
DestoryPrefabs(i);
}
}
}
///
/// 销毁预制体
///
/// 需要销毁预制体的名字编号
private void DestoryPrefabs(int PrefabsNameNum)
{
GameObject SearchRowPrefab1;
SearchRowPrefab1 = GetGoFromName(_DataRowOne + "(Clone)" + PrefabsNameNum);
DestroyImmediate(SearchRowPrefab1);
}
///
/// 加载对应的XML信息到当前页的表格中
///
/// 当前表格页行开始的索引
/// 当前表格页显示的行数
private void LoadXmlInfoToCurrentGridPage(int startIndex, int curPageNumber)
{
GameObject SearchRowPrefab;
//下一页的行总数
int nextPageTotalRowNum = 0;
nextPageTotalRowNum = curPageNumber + ((_CurrentPageNumber - 1) * gridRowNumber);
//print("下一页的行总数="+nextPageTotalRowNum);
for (int i = startIndex; i <= nextPageTotalRowNum; i++)
{
if (_HTDRTXmlAllInfo[i - 1].Id == i)
{
_SingleHTDRTData = new Ctrl_Single_HighTemperatureDryingWorkshopData();
_SingleHTDRTData = _HTDRTXmlAllInfo[i - 1];
//print("ID="+_SingleTaskReportData.Id);
//print("设备ID="+_SearchData.EquipId);
//通过名字获取到对应的行预制体物体
SearchRowPrefab = GetGoFromName(_DataRowOne + "(Clone)" + i);
//print("奇数查找到的预制体为=" + SearchRowPrefab);
//查找数据行下的所有子物体标签
SearchTexts(SearchRowPrefab);
Text_SerialNum = GetSingleDisplayText(_Text_SerialNumber);
//print("奇数ID=" + i);
Text_AlarmTime = GetSingleDisplayText(_Text_DateTime);
Text_AlarmEquipArea = GetSingleDisplayText(_Text_AlarmEquipmentOrArea);
Text_Duration = GetSingleDisplayText(_Text_Duration);
Text_AlarmNumbers = GetSingleDisplayText(_Text_AlarmNumbers);
Text_AlarmFaultDescription = GetSingleDisplayText(_Text_FaultDescription);
Text_SerialNum.GetComponent().text = i.ToString();
Text_AlarmTime.GetComponent().text = _SingleHTDRTData.HTDRTTimeOrDate;
Text_AlarmEquipArea.GetComponent().text = _SingleHTDRTData.HTDRTEquipOrArea;
Text_AlarmFaultDescription.GetComponent().text = _SingleHTDRTData.HTDRTFaultDescription;
Text_Duration.GetComponent().text = _SingleHTDRTData.HTDRTDuration;
Text_AlarmNumbers.GetComponent().text = _SingleHTDRTData.HTDRTAlarmNumbers;
//print("奇数地址="+_SingleTaskReportData.TargetAddress);
}
}
}
///
/// 销毁原先的数据行
///
/// 是否显示错误信息面板(true表示显示)
private void DestroyOriginalRowData(bool IsDisplayErrorTips)
{
//获取到表格当前的所有数据行
GetGridCurrentAllRowData(_RowDataTag);
//如果查询有数据则销毁全部的行预制体
if (_QueryData.Count >= 1)
{
foreach (GameObject go in _CurrentGridAllRow)
{
DestroyImmediate(go);
}
}
else
{
foreach (GameObject go in _CurrentGridAllRow)
{
DestroyImmediate(go);
}
if (IsDisplayErrorTips == true)
{
//显示信息提示框及其内容
InfoTipsFrame.GetInstance().DisplayTipsFrameAndContents(totalRowBG, "信息提示", "抱歉,您输入的信息不存在,请检查后重新输入!!!");
}
}
}
#endregion
#region 查询方法
///
/// 查询方法
///
/// 查询的条件
private void Search(string searchCondition)
{
//根据条件查询
QueryDataOfCondition(searchCondition);
//销毁原来的数据行,且显示错误提示面板
DestroyOriginalRowData(true);
//加载查询出对应的XML信息到当前页的表格中
for (int i = 0; i < _QueryData.Count; i++)
{
//生成表格
_CurrentPageNumber = 1;
MakeGrid(i + 1, _QueryData.Count);
//print("加载查询出来的数据!!!");
//加载查询出对应的XML信息到当前页的表格中
LoadSearchTaskReportToGrid(i);
}
}
///
/// 根据条件查询数据
///
/// 查询条件
private void QueryDataOfCondition(string searchCondition)
{
if (searchCondition != null)
{
_QueryData = new List();
//开始查询数据
for (int i = 0; i < _HTDRTXmlAllInfo.Count; i++)
{
//根据实时报警时间查询
if (_HTDRTXmlAllInfo[i].HTDRTTimeOrDate.ToString() == searchCondition.Trim())
{
_QueryData.Add(_HTDRTXmlAllInfo[i]);
}
//根据实时报警区域、设备查询
if (_HTDRTXmlAllInfo[i].HTDRTEquipOrArea == searchCondition.Trim())
{
_QueryData.Add(_HTDRTXmlAllInfo[i]);
}
//根据实时报警故障描述查询
if (_HTDRTXmlAllInfo[i].HTDRTFaultDescription == searchCondition.Trim())
{
_QueryData.Add(_HTDRTXmlAllInfo[i]);
}
}
}
else
{
Debug.LogWarning(GetType() + "/QueryDataOfCondition()/没有查询的条件");
////隐藏错误信息面板
//DisplayOrHidePanel(ErrorInfoPanel, false);
}
}
///
/// 显示或隐藏面板
///
private void DisplayOrHidePanel(GameObject go, bool IsDisplay)
{
go.SetActive(IsDisplay);
}
///
/// 获得表格当前的所有数据行
///
///
private void GetGridCurrentAllRowData(string TagName)
{
GameObject[] rowData = GameObject.FindGameObjectsWithTag(TagName);
_CurrentGridAllRow = new List();
for (int i = 0; i < rowData.Length; i++)
{
_CurrentGridAllRow.Add(rowData[i]);
}
}
///
/// 加载查询出对应的XML信息到当前页的表格中
///
/// 查询的索引
private void LoadSearchTaskReportToGrid(int StartIndex)
{
GameObject SearchRowPrefab;
//加载对应的XML信息到当前页的表格中
SearchRowPrefab = GetGoFromName(_DataRowOne + "(Clone)" + (StartIndex + 1));
//查找数据行下的所有子物体标签
SearchTexts(SearchRowPrefab);
Text_SerialNum = GetSingleDisplayText("Text_SerialNum");
//print("奇数ID=" + i);
Text_AlarmTime = GetSingleDisplayText("Text_AlarmTime");
Text_AlarmEquipArea = GetSingleDisplayText("Text_AlarmEquipArea");
Text_Duration = GetSingleDisplayText("Text_Duration");
Text_AlarmNumbers = GetSingleDisplayText("Text_AlarmNumbers");
Text_AlarmFaultDescription = GetSingleDisplayText("Text_AlarmFaultDescription");
Text_SerialNum.GetComponent().text = _QueryData[StartIndex].Id.ToString();
Text_AlarmTime.GetComponent().text = _QueryData[StartIndex].HTDRTTimeOrDate;
Text_AlarmEquipArea.GetComponent().text = _QueryData[StartIndex].HTDRTEquipOrArea;
Text_Duration.GetComponent().text = _QueryData[StartIndex].HTDRTDuration;
Text_AlarmNumbers.GetComponent().text = _QueryData[StartIndex].HTDRTAlarmNumbers;
Text_AlarmFaultDescription.GetComponent().text = _QueryData[StartIndex].HTDRTFaultDescription;
}
#endregion
}//class_end
}
3、将2中的代码添加给一个空物体,然后指定对应的参数即可
备注:XML文件的解析
/***
* Title:"医药自动化" 项目
* 主题: 解析实时报警---高温干燥车间的XML文件
* Description:
* 功能:解析出实时报警---高温干燥车间XML文件内容
* Date:2017
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
using System.Xml;
using Global;
namespace Control
{
public class Ctrl_Analysis_HighTemperatureDryingWorkshopXML
{
private static Ctrl_Analysis_HighTemperatureDryingWorkshopXML _Instance; //本类实例
private List _HTDRTXmlInfoList; //存储实时报警---高温干燥车间的列表
private Ctrl_Single_HighTemperatureDryingWorkshopData _SingleHTDRTInfo; //任务实时报警---高温干燥车间的每一条数据
///
/// 本类实例(单例)
///
///
public static Ctrl_Analysis_HighTemperatureDryingWorkshopXML GetInstance()
{
if (_Instance == null)
{
_Instance = new Ctrl_Analysis_HighTemperatureDryingWorkshopXML();
}
return _Instance;
}
///
/// 获取到所有的实时报警---高温干燥车间列表信息
///
///
public List GetAllHTDRTInfo()
{
//Debug.Log(_HTDRTXmlInfoList.Count);
return _HTDRTXmlInfoList;
}
///
/// 获取到所有实时报警---高温干燥车间列表的数目
///
///
public int GetAllHTDRTNumbers()
{
int accountNum = 0;
accountNum = _HTDRTXmlInfoList.Count;
return accountNum;
}
///
/// 获取到实时报警---高温干燥车间列表的XML信息
///
/// 实时报警---高温干燥车间列表的XML路径
/// 实时报警---高温干燥车间列表的XML根节点名称
public void GetHTDRTXMLInfo(string xmlPath, string rootNodeName)
{
//实例化
_HTDRTXmlInfoList = new List();
string path = "file://" + Application.dataPath +Global_Parameter.REALTIME_ALARMLIST_XMLPATH + xmlPath;
//Debug.Log(path);
//判断任务报表是否存在
if (path != null && rootNodeName != null)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
//获取到根节点
XmlNode rootNode = doc.SelectSingleNode(rootNodeName);
XmlNodeList childNodes = rootNode.ChildNodes;
foreach (XmlNode nodeItem in childNodes)
{
//实例化
_SingleHTDRTInfo = new Ctrl_Single_HighTemperatureDryingWorkshopData();
_SingleHTDRTInfo.Id = Convert.ToInt32(nodeItem.Attributes[0].InnerText);
_SingleHTDRTInfo.HTDRTTimeOrDate = nodeItem.Attributes[1].InnerText;
_SingleHTDRTInfo.HTDRTEquipOrArea = nodeItem.Attributes[2].InnerText;
_SingleHTDRTInfo.HTDRTDuration = nodeItem.Attributes[3].InnerText;
_SingleHTDRTInfo.HTDRTAlarmNumbers = nodeItem.Attributes[4].InnerText;
_SingleHTDRTInfo.HTDRTFaultDescription = nodeItem.Attributes[5].InnerText;
_SingleHTDRTInfo.HTDRTCreator = nodeItem.Attributes[6].InnerText;
_SingleHTDRTInfo.HTDRTModifier = nodeItem.Attributes[7].InnerText;
_SingleHTDRTInfo.ModifyPreviousLogonTime = nodeItem.Attributes[8].InnerText;
_SingleHTDRTInfo.ModifyCurrentLogonTime = nodeItem.Attributes[9].InnerText;
_HTDRTXmlInfoList.Add(_SingleHTDRTInfo);
}
}
else
{
Debug.LogError(GetType() + "/GetHTDRTXMLInfo()/需要获取的实时报警---高温干燥车间列表XML文件不存在,请检查!!!");
}
}
}//class_end
}
/***
* Title:"医药自动化" 项目
* 主题:高温干燥车间--实时报警单条信息
* Description:
* 功能:XXX
* Date:2017
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Control
{
public class Ctrl_Single_HighTemperatureDryingWorkshopData
{
//序号
private int id;
//时间、日期
private string hTDRTTimeOrDate;
//报警设备、区域
private string hTDRTEquipOrArea;
//持续时间
private string hTDRTDuration;
//报警次数
private string hTDRTAlarmNumbers;
//故障描述
private string hTDRTFaultDescription;
//创建者
private string hTDRTCreator;
//修改者
private string hTDRTModifier;
//修改的上一次时间
private string modifyPreviousLogonTime;
//修改的当前时间
private string modifyCurrentLogonTime;
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
public string HTDRTTimeOrDate
{
get
{
return hTDRTTimeOrDate;
}
set
{
hTDRTTimeOrDate = value;
}
}
public string HTDRTEquipOrArea
{
get
{
return hTDRTEquipOrArea;
}
set
{
hTDRTEquipOrArea = value;
}
}
public string HTDRTFaultDescription
{
get
{
return hTDRTFaultDescription;
}
set
{
hTDRTFaultDescription = value;
}
}
public string HTDRTDuration
{
get
{
return hTDRTDuration;
}
set
{
hTDRTDuration = value;
}
}
public string HTDRTAlarmNumbers
{
get
{
return hTDRTAlarmNumbers;
}
set
{
hTDRTAlarmNumbers = value;
}
}
public string HTDRTCreator
{
get
{
return hTDRTCreator;
}
set
{
hTDRTCreator = value;
}
}
public string HTDRTModifier
{
get
{
return hTDRTModifier;
}
set
{
hTDRTModifier = value;
}
}
public string ModifyPreviousLogonTime
{
get
{
return modifyPreviousLogonTime;
}
set
{
modifyPreviousLogonTime = value;
}
}
public string ModifyCurrentLogonTime
{
get
{
return modifyCurrentLogonTime;
}
set
{
modifyCurrentLogonTime = value;
}
}
}//class_end
}