103 lines
4.4 KiB
C#
103 lines
4.4 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 DataItemModel
|
|
{
|
|
private int _id;
|
|
private string _processName;
|
|
private string[] _tools;
|
|
private string _hint;
|
|
private string[] _realityTools;//实际操作工具
|
|
private string _realityPlace;//实际操作工具
|
|
private float _score;//操作正确得分
|
|
private string _rightImg;//正确操作截屏存在地址
|
|
|
|
public DataItemModel(int id, string processName, string[] tools, string hint,float score)
|
|
{
|
|
_id = id;
|
|
_processName = processName;
|
|
_tools = tools;
|
|
_hint = hint;
|
|
_realityTools = tools;
|
|
_realityPlace = _processName;
|
|
_score = score;
|
|
}
|
|
public static DataItemModel Default => new DataItemModel(-1, "", new string[0], "",0);
|
|
|
|
public int ID { get => _id; set => _id = value; }
|
|
public string ProcessName { get => _processName; set => _processName = value; }
|
|
public string[] Tools { get => _tools; set => _tools = value; }
|
|
public string Hint { get => _hint; set => _hint = value; }
|
|
public string[] RealityTools { get => _realityTools; set => _realityTools = value; }
|
|
public string RealityPlace { get => _realityPlace; set => _realityPlace = value; }
|
|
public float Score { get => _score; set => _score = value; }
|
|
public string RightImg { get => _rightImg; set => _rightImg = value; }
|
|
|
|
public override string ToString()
|
|
{
|
|
System.Text.StringBuilder toolsTemp = new System.Text.StringBuilder();
|
|
foreach (var item in _tools)
|
|
{
|
|
toolsTemp.Append(item+",");
|
|
}
|
|
return $"_id:{_id}-_processName:{_processName}-_id:{toolsTemp.ToString().Replace(",","")}-_hint:{_hint}";
|
|
}
|
|
}
|
|
|
|
public class AppModel
|
|
{
|
|
//加载的数据资源
|
|
private Dictionary<string, Dictionary<string, DataItemModel>> _dataJDSBArray = new Dictionary<string, Dictionary<string, DataItemModel>>();
|
|
public Dictionary<string, Dictionary<string, DataItemModel>> DataJDSBArray { get => _dataJDSBArray; }
|
|
|
|
///// <summary>
|
|
///// 初始化数据
|
|
///// </summary>
|
|
public IEnumerator ReadExcelDataWeb()
|
|
{
|
|
string url = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_CONFIG_PATH);
|
|
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
|
|
{
|
|
// 处理数据
|
|
string[] lines = t.Split(System.Environment.NewLine);
|
|
string curprocessName = "";
|
|
//byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(curprocessName);
|
|
//string temp = System.BitConverter.ToString(utf8Bytes);
|
|
//byte[] utf8Bytes1 = System.Text.Encoding.UTF8.GetBytes("循环搬运机械手虚拟仿真系统");
|
|
//string temp1 = System.BitConverter.ToString(utf8Bytes1);
|
|
//WDebug.Log(temp + "=====" + temp1);
|
|
foreach (string line in lines)
|
|
{
|
|
if (string.IsNullOrEmpty(line)) continue;
|
|
if (line.Contains("*"))
|
|
{
|
|
curprocessName = line.Replace("*", "");
|
|
curprocessName = curprocessName.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\r\n", string.Empty);
|
|
_dataJDSBArray.Add(curprocessName, new Dictionary<string, DataItemModel>());
|
|
}
|
|
else
|
|
{
|
|
string[] items = line.Split("-");
|
|
DataItemModel datamodel = new DataItemModel(_dataJDSBArray[curprocessName].Count, items[0], items[1].Split("|"), items[2],float.Parse(items[3]));
|
|
_dataJDSBArray[curprocessName].Add(items[0], datamodel);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |