243 lines
9.4 KiB
C#
243 lines
9.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
using ZXK.Framework;
|
|
using ZXK.UTility;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function
|
|
*******************************************************************************/
|
|
namespace ZXK.ZPS
|
|
{
|
|
public class GameRoot : MonoSingleton<GameRoot>
|
|
{
|
|
[MyReadOnly]
|
|
public EnumCtrl.Model _CurModel = EnumCtrl.Model.None;
|
|
[MyReadOnly]
|
|
public EnumCtrl.Type _CurType = EnumCtrl.Type.None;
|
|
[MyReadOnly]
|
|
public string _CurFirstProcess = null;
|
|
[MyReadOnly]
|
|
public string _CurSecondProcess = null;
|
|
[MyReadOnly]//主要用于在实训模式预测下一步
|
|
public string _NextSecondProcess = null;
|
|
|
|
[MyReadOnly]
|
|
public string _WQBName;
|
|
[MyReadOnly]
|
|
public string _DHBName;
|
|
|
|
[SerializeField]
|
|
private Button _returnExit = null;
|
|
[SerializeField]
|
|
private Sprite _returnImg = null;
|
|
[SerializeField]
|
|
private Sprite _exitImg = null;
|
|
|
|
private Dictionary<string, Dictionary<string, DataItemModel>> _dataWQBArray = new Dictionary<string, Dictionary<string, DataItemModel>>();
|
|
private Dictionary<string, Dictionary<string, DataItemModel>> _dataDHBArray = new Dictionary<string, Dictionary<string, DataItemModel>>();
|
|
public Dictionary<string, Dictionary<string, DataItemModel>> DataWQBArray { get => _dataWQBArray; }
|
|
public Dictionary<string, Dictionary<string, DataItemModel>> DataDHBArray { get => _dataDHBArray; }
|
|
|
|
[System.NonSerialized]
|
|
public TrainManager _TrainMng = null;
|
|
[System.NonSerialized]
|
|
public ExamManager _ExamMng = null;
|
|
[System.NonSerialized]
|
|
public DataUICtrl _DataUICtrl = null;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_CurType = EnumCtrl.Type.None;
|
|
_CurModel = EnumCtrl.Model.Home;
|
|
_CurFirstProcess = null;
|
|
_CurSecondProcess = null;
|
|
//#if UNITY_WEBGL
|
|
StartCoroutine("ReadExcelDataWeb");
|
|
//#elif UNITY_EDITOR ||UNITY_EDITOR_WIN
|
|
// ReadExcelData();
|
|
//#endif
|
|
|
|
_returnExit.onClick.AddListener(() =>
|
|
{
|
|
ReturnExit();
|
|
});
|
|
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (_CurModel == EnumCtrl.Model.Home)
|
|
{
|
|
if (_CurType == EnumCtrl.Type.None)
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _exitImg;
|
|
}
|
|
else
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _returnImg;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _returnImg;
|
|
}
|
|
}
|
|
|
|
public void ReturnExit()
|
|
{
|
|
Transform canvas = transform.Find("Canvas").transform;
|
|
foreach (Transform item in canvas)
|
|
{
|
|
if (!item.name.Equals("logo")&& !item.name.Equals("ReturnExit"))
|
|
{
|
|
Destroy(item.gameObject);
|
|
}
|
|
}
|
|
|
|
if (_CurModel == EnumCtrl.Model.Home)
|
|
{
|
|
if (_CurType == EnumCtrl.Type.None)
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _exitImg;
|
|
UtilitiesMng.CustomQuit();
|
|
}
|
|
else
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _returnImg;
|
|
_CurType = EnumCtrl.Type.None;
|
|
UtilitiesMng.LoadScene(EnumCtrl.Model.Home.ToString());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_returnExit.GetComponent<Image>().sprite = _returnImg;
|
|
UtilitiesMng.LoadScene(EnumCtrl.Model.Home.ToString());
|
|
}
|
|
}
|
|
//private void OnGUI()
|
|
//{
|
|
// ////显示logo
|
|
// //GUI.DrawTexture(new Rect(0, 0, 504, 117), _logoImg.texture);
|
|
// //显示退出按钮
|
|
// GUIStyle buttonStyle = new GUIStyle();
|
|
// buttonStyle.normal.background = null;
|
|
// buttonStyle.onNormal.background = null;
|
|
// if (_CurModel == EnumCtrl.Model.Home)
|
|
// {
|
|
// if(_CurType == EnumCtrl.Type.None)
|
|
// {
|
|
// if (GUI.Button(new Rect(1810, 10, _exitImg.texture.width, _exitImg.texture.height), _exitImg.texture, buttonStyle))
|
|
// {
|
|
// UtilitiesMng.CustomQuit();
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// if (GUI.Button(new Rect(1810, 10, _returnImg.texture.width, _returnImg.texture.height), _returnImg.texture, buttonStyle))
|
|
// {
|
|
// _CurType = EnumCtrl.Type.None;
|
|
// UtilitiesMng.LoadScene(EnumCtrl.Model.Home.ToString());
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// if (GUI.Button(new Rect(1810, 10, _returnImg.texture.width, _returnImg.texture.height), _returnImg.texture, buttonStyle))
|
|
// {
|
|
// UtilitiesMng.LoadScene(EnumCtrl.Model.Home.ToString());
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
#region 数据相关操作
|
|
private IEnumerator ReadExcelDataWeb()
|
|
{
|
|
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_CONFIG_PATH);
|
|
using (UnityWebRequest www = UnityWebRequest.Get(filePath))
|
|
{
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Debug.LogError("Error: " + www.error);
|
|
}
|
|
else
|
|
{
|
|
// 处理数据
|
|
byte[] data = www.downloadHandler.data;
|
|
ProcessExcelData(data);
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
void ProcessExcelData(byte[] data)
|
|
{
|
|
System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
|
|
System.Data.DataSet dataTables = ExcelFileHandle.ReadExcel(stream);
|
|
ReadExcelDataSet(dataTables);
|
|
}
|
|
private void ReadExcelData()
|
|
{
|
|
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_CONFIG_PATH);
|
|
System.Data.DataSet dataTables = ExcelFileHandle.ReadExcel(filePath);
|
|
Debug.Log("数据对象:" + dataTables + "数据位置:" + filePath);
|
|
ReadExcelDataSet(dataTables);
|
|
}
|
|
private void ReadExcelDataSet(System.Data.DataSet dataTables)
|
|
{
|
|
if (dataTables.Tables.Count > 1)
|
|
{
|
|
_WQBName = dataTables.Tables[0].TableName;
|
|
_DHBName = dataTables.Tables[1].TableName;
|
|
string itemDataID = "";
|
|
for (int a = 0; a < dataTables.Tables.Count; a++)
|
|
{
|
|
int rows = dataTables.Tables[a].Rows.Count;
|
|
int columns = dataTables.Tables[a].Columns.Count;
|
|
itemDataID = a + "-";
|
|
Debug.Log("table:"+ dataTables.Tables[a] .TableName+ "row:" + rows + "...col:" + columns);
|
|
Dictionary<string, Dictionary<string, DataItemModel>> firstProTemp = new Dictionary<string, Dictionary<string, DataItemModel>>();
|
|
Dictionary<string, DataItemModel> secondProTemp = new Dictionary<string, DataItemModel>();
|
|
int firstNumber = 0;
|
|
int secondNumber = 0;
|
|
for (int i = 1; i < rows; i++)
|
|
{
|
|
string firstProName = dataTables.Tables[a].Rows[i][0].ToString();
|
|
if (!string.IsNullOrEmpty(firstProName))
|
|
{//说明有一级工序
|
|
secondProTemp = new Dictionary<string, DataItemModel>();
|
|
firstProTemp.Add(firstProName, secondProTemp);
|
|
itemDataID = a + "-"+ firstNumber;
|
|
firstNumber++;
|
|
secondNumber = 0;
|
|
}
|
|
else
|
|
{
|
|
secondNumber++;
|
|
}
|
|
|
|
//形成一个二级工序对象
|
|
string firstName = dataTables.Tables[a].Rows[i][0].ToString();
|
|
string secondName = dataTables.Tables[a].Rows[i][1].ToString();
|
|
string[] tools = dataTables.Tables[a].Rows[i][2].ToString().Split('、');
|
|
string anmHint = dataTables.Tables[a].Rows[i][3].ToString();
|
|
string voiceHint = dataTables.Tables[a].Rows[i][4].ToString();
|
|
DataItemModel dataItem = new DataItemModel(itemDataID + '-'+ secondNumber, firstName, secondName, tools, anmHint, voiceHint);
|
|
secondProTemp.Add(secondName, dataItem);
|
|
}
|
|
if (a == 0)
|
|
_dataWQBArray = firstProTemp;
|
|
else if (a == 1)
|
|
_dataDHBArray = firstProTemp;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |