138 lines
5.9 KiB
C#
138 lines
5.9 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
using ZXK.Framework;
|
||
using ZXK.UTility;
|
||
/*******************************************************************************
|
||
*Create By CG
|
||
*Function 设备认知数据处理
|
||
*******************************************************************************/
|
||
namespace ZXK.BYSS
|
||
{
|
||
public class EquipmentInfo
|
||
{
|
||
private string _modelID;
|
||
private string _modelName;
|
||
private string _modelExplain;
|
||
private GameObject _modelPrefab;
|
||
|
||
public EquipmentInfo(string modelID, string modelName, string modelExplain, GameObject modelPrefab)
|
||
{
|
||
_ModelID = modelID;
|
||
_ModelName = modelName;
|
||
_ModelExplain = modelExplain;
|
||
_ModelPrefab = modelPrefab;
|
||
}
|
||
public static EquipmentInfo Default => new EquipmentInfo("", "", "", null);
|
||
|
||
public string _ModelID { get => _modelID; set => _modelID = value; }
|
||
public string _ModelName { get => _modelName; set => _modelName = value; }
|
||
public string _ModelExplain { get => _modelExplain; set => _modelExplain = value; }
|
||
public GameObject _ModelPrefab { get => _modelPrefab; set => _modelPrefab = value; }
|
||
}
|
||
public class CognizeModel
|
||
{
|
||
private Dictionary<string, List<EquipmentInfo>> _equipmentsData = new Dictionary<string, List<EquipmentInfo>>();
|
||
public Dictionary<string, List<EquipmentInfo>> _EquipmentData { get => _equipmentsData; }
|
||
|
||
///// <summary>
|
||
///// 初始化数据
|
||
///// </summary>
|
||
public IEnumerator InitDataIEnum()
|
||
{
|
||
yield return null;
|
||
string url = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_COGNIZE_PATH);
|
||
UnityWebRequest request = UnityWebRequest.Get(url);
|
||
yield return request.SendWebRequest();
|
||
|
||
if (request.result != UnityWebRequest.Result.Success)
|
||
{
|
||
Debug.LogError("Error: " + request.error);
|
||
}
|
||
else
|
||
{
|
||
string t = request.downloadHandler.text;
|
||
string[] lines = t.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||
|
||
string curTypeNameTemp = "";
|
||
List<EquipmentInfo> typeEquipmentArrayTemp = null;
|
||
for (int i = 2; i < lines.Length; i++)
|
||
{
|
||
if (lines[i].Contains("*"))
|
||
{
|
||
curTypeNameTemp = lines[i].Replace("*", "");
|
||
typeEquipmentArrayTemp = new List<EquipmentInfo>();
|
||
curTypeNameTemp = curTypeNameTemp.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\r\n", string.Empty);
|
||
WDebug.Log("添加物体:" + curTypeNameTemp);
|
||
|
||
//byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(curTypeNameTemp);
|
||
//string temp = BitConverter.ToString(utf8Bytes);
|
||
//byte[] utf8Bytes1 = System.Text.Encoding.UTF8.GetBytes("循环搬运机械手虚拟仿真系统");
|
||
//string temp1 = BitConverter.ToString(utf8Bytes1);
|
||
//WDebug.Log(temp + "=====" + temp1);
|
||
|
||
if (curTypeNameTemp.Equals("循环搬运机械手虚拟仿真系统"))
|
||
{
|
||
WDebug.Log("相等了");
|
||
curTypeNameTemp = EnumCtrl.GetEnumDescription(EnumCtrl.Type.XHBY);
|
||
}
|
||
_equipmentsData.Add(curTypeNameTemp, typeEquipmentArrayTemp);
|
||
}
|
||
else
|
||
{
|
||
if (lines[i].Contains("|"))
|
||
{
|
||
string[] infos = lines[i].Split('|');
|
||
|
||
if (infos.Length >= 3)
|
||
{
|
||
EquipmentInfo equipmentTemp = new EquipmentInfo(
|
||
infos[0],
|
||
infos[1],
|
||
infos[2],
|
||
null
|
||
);
|
||
typeEquipmentArrayTemp.Add(equipmentTemp);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning("跳过数据行,因为数据不足: " + lines[i]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning("跳过格式不正确的行: " + lines[i]);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
for (int i = 0; i < _EquipmentData[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)].Count; i++)
|
||
{
|
||
string idTemp = _EquipmentData[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)][i]._ModelID;
|
||
WDebug.Log("1加载到"+ idTemp);
|
||
string itemPath = ConstCtrl.DATA_MODEL_PATH+AppManagement.Instance._CurType.ToString()+ "/" + idTemp + ".prefab";
|
||
//itemPath = "Assets/10_Prefabs/ModelPrefabs/Cognize/ZXJXSBYJGZhengTiPrefab.prefab";
|
||
AddressablesManager.Instance.LoadAsset<GameObject>(itemPath, OnLoadedCall);
|
||
}
|
||
}
|
||
|
||
private void OnLoadedCall(GameObject obj)
|
||
{
|
||
for (int i = 0; i < _EquipmentData[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)].Count; i++)
|
||
{
|
||
WDebug.Log($"2加载到物体:{obj.name}");
|
||
EquipmentInfo temp = _EquipmentData[EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)][i];
|
||
if (temp._ModelID.Equals(obj.name))
|
||
{
|
||
temp._ModelPrefab = obj;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} |