196 lines
8.5 KiB
C#
196 lines
8.5 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Networking;
|
|||
|
|
using ZXK.UTility;
|
|||
|
|
/*******************************************************************************
|
|||
|
|
*Create By CG
|
|||
|
|
*Function
|
|||
|
|
*******************************************************************************/
|
|||
|
|
namespace ZXK.BYSS
|
|||
|
|
{
|
|||
|
|
public class TerminalModel
|
|||
|
|
{
|
|||
|
|
public List<string> _LinesID { get; set; } = new List<string>();
|
|||
|
|
public string _CtrlBoard { get; set; }
|
|||
|
|
public string _TerminalName { get; set; }
|
|||
|
|
public GameObject _TerminalGeo { get; set; }
|
|||
|
|
|
|||
|
|
public Vector3 _ChaTouPos { get; set; } = Vector3.zero;//<2F><>ͷ<EFBFBD><CDB7>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ľֲ<C4BE>λ<EFBFBD><CEBB>
|
|||
|
|
public Vector3 _ChaTouRot { get; set; } = Vector3.up*-90;//<2F><>ͷ<EFBFBD><CDB7>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ľֲ<C4BE>λ<EFBFBD><CEBB>
|
|||
|
|
|
|||
|
|
public List<GameObject> _ConnectGeos { get; set; } = new List<GameObject>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class LineConnectModel
|
|||
|
|
{
|
|||
|
|
[SerializeField]
|
|||
|
|
public Dictionary<string, List<TerminalModel[][]>> _terminalDic = new Dictionary<string, List<TerminalModel[][]>>();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>List<73><74><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ٶ<EFBFBD><D9B6>ӿ<EFBFBD><D3BF>ư<EFBFBD>,ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ٸ<EFBFBD><D9B8><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
|
|||
|
|
public Dictionary<string, List<TerminalModel[][]>> _TerminalDic { get => _terminalDic;}
|
|||
|
|
|
|||
|
|
|
|||
|
|
///// <summary>
|
|||
|
|
///// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
///// </summary>
|
|||
|
|
public IEnumerator ReadLineConnectDataWeb(Transform contain,System.Action completeCall)
|
|||
|
|
{
|
|||
|
|
string url = "";
|
|||
|
|
//<2F><><EFBFBD>˼<EFBFBD><CBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>߱<EFBFBD>
|
|||
|
|
if (AppManagement.Instance._TrainExam == EnumCtrl.Model.Exam)
|
|||
|
|
{
|
|||
|
|
url = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_LINECONNECT_PATH);
|
|||
|
|
WDebug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>߱<EFBFBD>" + url);
|
|||
|
|
}
|
|||
|
|
//<2F><>ϰ<EFBFBD><CFB0>ѧ<EFBFBD><D1A7><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD>
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
url = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_TeachAndTrainLINECONNECT_PATH);
|
|||
|
|
Debug.Log("<22><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD>" + url);
|
|||
|
|
}
|
|||
|
|
UnityWebRequest request = UnityWebRequest.Get(url);
|
|||
|
|
yield return request.SendWebRequest();
|
|||
|
|
string t = request.downloadHandler.text;
|
|||
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|||
|
|
{
|
|||
|
|
Debug.LogError("Error: " + request.error);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Dictionary<string, GameObject> allChildren = new Dictionary<string, GameObject>();
|
|||
|
|
AddAllChildren(contain, allChildren);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string[] lines = t.Split(System.Environment.NewLine);
|
|||
|
|
|
|||
|
|
string curTypeNameTemp = "";
|
|||
|
|
List<TerminalModel[][]> terminalArray = null;
|
|||
|
|
string[] ctrlBoardName = null;
|
|||
|
|
|
|||
|
|
for (int a = 0; a < lines.Length; a++)
|
|||
|
|
{
|
|||
|
|
string line = lines[a];
|
|||
|
|
if (string.IsNullOrEmpty(line)) continue;
|
|||
|
|
if (lines[a].Contains("*"))
|
|||
|
|
{
|
|||
|
|
line = line.TrimStart('*').TrimEnd('*');
|
|||
|
|
line = line.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\r\n", string.Empty);
|
|||
|
|
string[] titleStr = line.Split("*");
|
|||
|
|
curTypeNameTemp = titleStr[0];
|
|||
|
|
if (EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType).Equals(curTypeNameTemp))
|
|||
|
|
{
|
|||
|
|
string[] explain = titleStr[1].Split("|");
|
|||
|
|
ctrlBoardName = new string[explain.Length - 1];
|
|||
|
|
for (int index = 0; index < ctrlBoardName.Length; index++)
|
|||
|
|
{
|
|||
|
|
ctrlBoardName[index] = explain[index + 1];
|
|||
|
|
}
|
|||
|
|
terminalArray = new List<TerminalModel[][]>();
|
|||
|
|
_terminalDic.Add(curTypeNameTemp, terminalArray);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
terminalArray = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if (terminalArray == null) continue;
|
|||
|
|
line = line.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\r\n", string.Empty);
|
|||
|
|
string[] ctrlBoards = line.Split("|");
|
|||
|
|
string lineID = ctrlBoards[0];
|
|||
|
|
TerminalModel[][] terminalGroupModels = new TerminalModel[ctrlBoards.Length - 1][];
|
|||
|
|
for (int i = 1; i < ctrlBoards.Length; i++)
|
|||
|
|
{
|
|||
|
|
WDebug.Log("add<64><64><EFBFBD><EFBFBD>1<EFBFBD><31>" + ctrlBoards[i]);
|
|||
|
|
if (!string.IsNullOrEmpty(ctrlBoards[i])&&!string.IsNullOrWhiteSpace(ctrlBoards[i]))
|
|||
|
|
{
|
|||
|
|
WDebug.Log("add<64><64><EFBFBD><EFBFBD>2<EFBFBD><32>" + ctrlBoards[i]);
|
|||
|
|
string[] terminals = ctrlBoards[i].Split("_");
|
|||
|
|
TerminalModel[] terminalModels = new TerminalModel[terminals.Length];
|
|||
|
|
for (int j = 0; j < terminals.Length; j++)
|
|||
|
|
{
|
|||
|
|
TerminalModel temp = new TerminalModel();
|
|||
|
|
temp._LinesID.Add(lineID);
|
|||
|
|
temp._CtrlBoard = ctrlBoardName[i - 1];
|
|||
|
|
temp._TerminalName = terminals[j];
|
|||
|
|
if (allChildren.ContainsKey(temp._TerminalName))
|
|||
|
|
{
|
|||
|
|
temp._TerminalGeo = allChildren[temp._TerminalName];
|
|||
|
|
TerminalCtrl tempCtrl = temp._TerminalGeo.GetComponent<TerminalCtrl>();
|
|||
|
|
if (tempCtrl == null)
|
|||
|
|
{
|
|||
|
|
tempCtrl = temp._TerminalGeo.AddComponent<TerminalCtrl>();
|
|||
|
|
}
|
|||
|
|
tempCtrl.Init(temp);
|
|||
|
|
}
|
|||
|
|
terminalModels[j] = temp;
|
|||
|
|
}
|
|||
|
|
terminalGroupModels[i - 1] = terminalModels;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
WDebug.Log("NoAdd<64><64><EFBFBD><EFBFBD>2<EFBFBD><32>" + ctrlBoards[i]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
terminalArray.Add(terminalGroupModels);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
completeCall?.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="parent"></param>
|
|||
|
|
/// <param name="list"></param>
|
|||
|
|
private void AddAllChildren(Transform parent, Dictionary<string, GameObject> list)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < parent.childCount; i++)
|
|||
|
|
{
|
|||
|
|
GameObject childGeo = parent.GetChild(i).gameObject;
|
|||
|
|
if (list.ContainsKey(childGeo.name))
|
|||
|
|
{
|
|||
|
|
//Debug.LogWarning($"<22><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>{childGeo.name}");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
list.Add(childGeo.name, childGeo);
|
|||
|
|
}
|
|||
|
|
AddAllChildren(parent.GetChild(i), list);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public override string ToString()
|
|||
|
|
{
|
|||
|
|
string returnStr = "";
|
|||
|
|
for (int i = 0; i < _TerminalDic[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)].Count; i++)
|
|||
|
|
{
|
|||
|
|
TerminalModel[][] terminals = _TerminalDic[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)][i];
|
|||
|
|
string temp = "";
|
|||
|
|
for (int a = 0; a < terminals.GetLength(0); a++)
|
|||
|
|
{
|
|||
|
|
if (terminals[a] != null)
|
|||
|
|
{
|
|||
|
|
for (int b = 0; b < terminals[a].Length; b++)
|
|||
|
|
{
|
|||
|
|
temp += terminals[a][b]._TerminalName + "_";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
temp= temp.TrimEnd('_');
|
|||
|
|
temp += "|";
|
|||
|
|
}
|
|||
|
|
temp = temp.Substring(0, temp.Length-1);
|
|||
|
|
Debug.Log(temp);
|
|||
|
|
returnStr = $"{returnStr}\n{temp}";
|
|||
|
|
}
|
|||
|
|
return returnStr;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|