CameraConfigProxy.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class CameraConfigProxy : DataProxy
  6. {
  7. private List<CameraConfigInfo> m_CameraConfigInfos;
  8. public override void OnRegister()
  9. {
  10. InitData();
  11. }
  12. public override void OnRemove()
  13. {
  14. }
  15. /// <summary>
  16. /// 初始化数据
  17. /// </summary>
  18. private void InitData()
  19. {
  20. //表格读取
  21. string path = Application.streamingAssetsPath + "/TableData/相机配置.csv";
  22. m_CameraConfigInfos = ReadOperationFromTable(path);
  23. }
  24. /// <summary>
  25. /// 获取相机配置数据
  26. /// </summary>
  27. /// <returns></returns>
  28. public List<CameraConfigInfo> GetCameraConfigData()
  29. {
  30. return m_CameraConfigInfos;
  31. }
  32. /// <summary>
  33. /// 从表格读取流程信息
  34. /// </summary>
  35. /// <param name="path"></param>
  36. /// <returns></returns>
  37. private List<CameraConfigInfo> ReadOperationFromTable(string path)
  38. {
  39. List<CameraConfigInfo> tmpInfos = new List<CameraConfigInfo>();
  40. using (StreamReader streamReader = new StreamReader(path, System.Text.Encoding.UTF8))
  41. {
  42. string tmpOperationInfo = streamReader.ReadToEnd().Trim();
  43. if (tmpOperationInfo.Contains("\r")) tmpOperationInfo = tmpOperationInfo.Replace("\r", "");
  44. string[] tempOperationInfos = tmpOperationInfo.Split('\n');
  45. for (int i = 2; i < tempOperationInfos.Length; i++)
  46. {
  47. string operationInfo = tempOperationInfos[i];
  48. string[] operationInfoElements = operationInfo.Split(',');
  49. CameraConfigInfo tmpInfo = new CameraConfigInfo();
  50. for (int j = 0; j < operationInfoElements.Length; j++)
  51. {
  52. if (j == 0) tmpInfo.m_ID = int.Parse(operationInfoElements[0]);
  53. if (j == 1) tmpInfo.m_EquipmentName = operationInfoElements[1];
  54. if (j == 2) tmpInfo.m_EquipmentUniqueID = int.Parse(operationInfoElements[2]);
  55. if (j == 3) tmpInfo.m_CameraInitPosition = GeneralMethod.String2Vector3(operationInfoElements[3],'|');
  56. if (j == 4) tmpInfo.m_CameraInitRotation = GeneralMethod.String2Vector3(operationInfoElements[4],'|');
  57. }
  58. tmpInfos.Add(tmpInfo);
  59. }
  60. }
  61. return tmpInfos;
  62. }
  63. }