DataDock.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. public class DataDock : MonoSingleton<DataDock>
  7. {
  8. #region 私有字段
  9. /// <summary>
  10. /// 是否使用多场景加载
  11. /// </summary>
  12. private bool m_IsLoadMultiScene = false;
  13. /// <summary>
  14. /// 操作类型配置数据
  15. /// </summary>
  16. private OperationTypeConfig m_OperationTypeConfig;
  17. /// <summary>
  18. /// 操作类型
  19. /// </summary>
  20. private string m_OperationType;
  21. /// <summary>
  22. /// 构建的场景数量
  23. /// </summary>
  24. private int m_BuildSettingsNumber = 0;
  25. /// <summary>
  26. /// 记录所有构建场景的信息
  27. /// </summary>
  28. private Dictionary<int, string> m_RecordAllBuildSceneInfos = new Dictionary<int, string>();
  29. /// <summary>
  30. /// 记录需要调整场景的名称
  31. /// </summary>
  32. private string m_RecordSceneName;
  33. #endregion
  34. #region 公开字段
  35. /// <summary>
  36. /// 软件名称
  37. /// </summary>
  38. public string m_SoftName;
  39. /// <summary>
  40. /// 连接IP
  41. /// </summary>
  42. public string m_ConnectIP;
  43. #endregion
  44. void Start()
  45. {
  46. Init(false);
  47. }
  48. /// <summary>
  49. /// 初始化
  50. /// </summary>
  51. /// <param name="_isLoadMultiScene">是否加载多场景</param>
  52. public void Init(bool _isLoadMultiScene = true)
  53. {
  54. m_RecordSceneName = string.Empty;
  55. m_IsLoadMultiScene = _isLoadMultiScene;
  56. InitOperationConfig();
  57. InitStartupData();
  58. }
  59. /// <summary>
  60. /// 初始化启动数据
  61. /// </summary>
  62. private void InitStartupData()
  63. {
  64. string[] args = Environment.GetCommandLineArgs();
  65. Debug.Log(args[1]);
  66. if (args.Length < 2)
  67. {
  68. return;
  69. }
  70. //模拟数据
  71. //string simulationData = "5c7fd0eaf63d8ecbd466043657c87d09ffeb09c8/Practice/高压侧套管更换检修处理/Chiva/4000801390/47.92.0.243:15155";
  72. //string[] tmpArgs = simulationData.Split('/');
  73. //截断
  74. string tmpArgsDecrypt = args[1].Decrypt("chivatech");
  75. string[] tmpArgs = tmpArgsDecrypt.Split('/');
  76. string tmpMode = tmpArgs[1];
  77. m_OperationType = tmpArgs[1];
  78. string tmpCourseName = tmpArgs[2];
  79. string tmpPhoneNumber = tmpArgs[4];
  80. string tmpAddress = tmpArgs[5];
  81. // 文件各种:手机号/课程名/模式/地址
  82. //string tmpPhoneNumber = tmpArgs[0];
  83. //string tmpCourseName = tmpArgs[1];
  84. //string tmpMode = tmpArgs[2];
  85. //string tmpAddress = tmpArgs[3];
  86. GrpcChannelContronller.Instance.StartClient(tmpAddress);
  87. GetInfoaboutSpecifiedUser(tmpPhoneNumber);
  88. SetOperationMode(tmpMode);
  89. GlobalConfig.m_SelectDevice = tmpCourseName;
  90. if (m_IsLoadMultiScene)
  91. {
  92. StartCoroutine(LazyLoadProcess());
  93. }
  94. else
  95. {
  96. SceneManager.LoadSceneAsync(2, LoadSceneMode.Single);
  97. }
  98. }
  99. /// <summary>
  100. /// 获取指定用户信息
  101. /// </summary>
  102. /// <param name="_phoneNumber"></param>
  103. private void GetInfoaboutSpecifiedUser(string _phoneNumber)
  104. {
  105. UserProxy userProxy = DAL.Instance.Get<UserProxy>();
  106. SearchInfoResponse tmpResponse = GrpcChannelContronller.Instance.client.StudentInfoSearch(new SearchRequest()
  107. {
  108. PhoneNumber = _phoneNumber
  109. });
  110. if (tmpResponse.Result)
  111. {
  112. userProxy.userInfo.userName = tmpResponse.StudentInfos[0].Name;
  113. userProxy.userInfo.phoneNumber = _phoneNumber;
  114. }
  115. }
  116. /// <summary>
  117. /// 初始化操作相关配置文件
  118. /// </summary>
  119. private void InitOperationConfig()
  120. {
  121. m_OperationTypeConfig = JsonDataAnalyze.GetOperationConfigData();
  122. }
  123. /// <summary>
  124. /// 设置操作模式
  125. /// </summary>
  126. /// <param name="_mode"></param>
  127. private void SetOperationMode(string _mode)
  128. {
  129. switch (_mode)
  130. {
  131. case "学习":
  132. GlobalData.m_CurrentOperationMode = OperationMode.Learn;
  133. break;
  134. case "练习":
  135. GlobalData.m_CurrentOperationMode = OperationMode.Practice;
  136. break;
  137. case "考核":
  138. GlobalData.m_CurrentOperationMode = OperationMode.Exam;
  139. break;
  140. case "Learn":
  141. GlobalData.m_CurrentOperationMode = OperationMode.Learn;
  142. break;
  143. case "Practice":
  144. GlobalData.m_CurrentOperationMode = OperationMode.Practice;
  145. break;
  146. case "Exam":
  147. GlobalData.m_CurrentOperationMode = OperationMode.Exam;
  148. break;
  149. }
  150. }
  151. /// <summary>
  152. /// 延迟加载处理
  153. /// </summary>
  154. /// <returns></returns>
  155. private IEnumerator LazyLoadProcess()
  156. {
  157. yield return new WaitForSeconds(0.5f);
  158. m_BuildSettingsNumber = SceneManager.sceneCountInBuildSettings;
  159. for (int i = 0; i < m_BuildSettingsNumber; i++)
  160. {
  161. if (!m_RecordAllBuildSceneInfos.ContainsKey(i))
  162. {
  163. // 获取完整路径
  164. string buildPath = SceneUtility.GetScenePathByBuildIndex(i);
  165. if (!string.IsNullOrEmpty(buildPath))
  166. {
  167. string buildSceneName = buildPath.Substring(buildPath.LastIndexOf('/') + 1).Split('.')[0];
  168. m_RecordAllBuildSceneInfos.Add(i, buildSceneName);
  169. }
  170. }
  171. }
  172. foreach (var item in m_RecordAllBuildSceneInfos)
  173. {
  174. string[] tmpInfo = item.Value.Split('_');
  175. //判定类型是否相同
  176. if (m_OperationType.Contains(tmpInfo[tmpInfo.Length - 1]))
  177. {
  178. m_RecordSceneName = item.Value;
  179. }
  180. }
  181. if (!string.IsNullOrEmpty(m_RecordSceneName))
  182. {
  183. SceneManager.LoadSceneAsync(m_RecordSceneName, LoadSceneMode.Single);
  184. }
  185. }
  186. }