123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class DataDock : MonoSingleton<DataDock>
- {
- #region 私有字段
- /// <summary>
- /// 是否使用多场景加载
- /// </summary>
- private bool m_IsLoadMultiScene = false;
- /// <summary>
- /// 操作类型配置数据
- /// </summary>
- private OperationTypeConfig m_OperationTypeConfig;
- /// <summary>
- /// 操作类型
- /// </summary>
- private string m_OperationType;
- /// <summary>
- /// 构建的场景数量
- /// </summary>
- private int m_BuildSettingsNumber = 0;
- /// <summary>
- /// 记录所有构建场景的信息
- /// </summary>
- private Dictionary<int, string> m_RecordAllBuildSceneInfos = new Dictionary<int, string>();
- /// <summary>
- /// 记录需要调整场景的名称
- /// </summary>
- private string m_RecordSceneName;
- #endregion
- #region 公开字段
- /// <summary>
- /// 软件名称
- /// </summary>
- public string m_SoftName;
- /// <summary>
- /// 连接IP
- /// </summary>
- public string m_ConnectIP;
- #endregion
- void Start()
- {
- Init(false);
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="_isLoadMultiScene">是否加载多场景</param>
- public void Init(bool _isLoadMultiScene = true)
- {
- m_RecordSceneName = string.Empty;
- m_IsLoadMultiScene = _isLoadMultiScene;
- InitOperationConfig();
- InitStartupData();
- }
- /// <summary>
- /// 初始化启动数据
- /// </summary>
- private void InitStartupData()
- {
- string[] args = Environment.GetCommandLineArgs();
- Debug.Log(args[1]);
- if (args.Length < 2)
- {
- return;
- }
- //模拟数据
- //string simulationData = "5c7fd0eaf63d8ecbd466043657c87d09ffeb09c8/Practice/高压侧套管更换检修处理/Chiva/4000801390/47.92.0.243:15155";
- //string[] tmpArgs = simulationData.Split('/');
- //截断
- string tmpArgsDecrypt = args[1].Decrypt("chivatech");
- string[] tmpArgs = tmpArgsDecrypt.Split('/');
- string tmpMode = tmpArgs[1];
- m_OperationType = tmpArgs[1];
- string tmpCourseName = tmpArgs[2];
- string tmpPhoneNumber = tmpArgs[4];
- string tmpAddress = tmpArgs[5];
- // 文件各种:手机号/课程名/模式/地址
- //string tmpPhoneNumber = tmpArgs[0];
- //string tmpCourseName = tmpArgs[1];
- //string tmpMode = tmpArgs[2];
- //string tmpAddress = tmpArgs[3];
- GrpcChannelContronller.Instance.StartClient(tmpAddress);
- GetInfoaboutSpecifiedUser(tmpPhoneNumber);
- SetOperationMode(tmpMode);
- GlobalConfig.m_SelectDevice = tmpCourseName;
- if (m_IsLoadMultiScene)
- {
- StartCoroutine(LazyLoadProcess());
- }
- else
- {
- SceneManager.LoadSceneAsync(2, LoadSceneMode.Single);
- }
- }
- /// <summary>
- /// 获取指定用户信息
- /// </summary>
- /// <param name="_phoneNumber"></param>
- private void GetInfoaboutSpecifiedUser(string _phoneNumber)
- {
- UserProxy userProxy = DAL.Instance.Get<UserProxy>();
- SearchInfoResponse tmpResponse = GrpcChannelContronller.Instance.client.StudentInfoSearch(new SearchRequest()
- {
- PhoneNumber = _phoneNumber
- });
- if (tmpResponse.Result)
- {
- userProxy.userInfo.userName = tmpResponse.StudentInfos[0].Name;
- userProxy.userInfo.phoneNumber = _phoneNumber;
- }
- }
- /// <summary>
- /// 初始化操作相关配置文件
- /// </summary>
- private void InitOperationConfig()
- {
- m_OperationTypeConfig = JsonDataAnalyze.GetOperationConfigData();
- }
- /// <summary>
- /// 设置操作模式
- /// </summary>
- /// <param name="_mode"></param>
- private void SetOperationMode(string _mode)
- {
- switch (_mode)
- {
- case "学习":
- GlobalData.m_CurrentOperationMode = OperationMode.Learn;
- break;
- case "练习":
- GlobalData.m_CurrentOperationMode = OperationMode.Practice;
- break;
- case "考核":
- GlobalData.m_CurrentOperationMode = OperationMode.Exam;
- break;
- case "Learn":
- GlobalData.m_CurrentOperationMode = OperationMode.Learn;
- break;
- case "Practice":
- GlobalData.m_CurrentOperationMode = OperationMode.Practice;
- break;
- case "Exam":
- GlobalData.m_CurrentOperationMode = OperationMode.Exam;
- break;
- }
- }
- /// <summary>
- /// 延迟加载处理
- /// </summary>
- /// <returns></returns>
- private IEnumerator LazyLoadProcess()
- {
- yield return new WaitForSeconds(0.5f);
- m_BuildSettingsNumber = SceneManager.sceneCountInBuildSettings;
- for (int i = 0; i < m_BuildSettingsNumber; i++)
- {
- if (!m_RecordAllBuildSceneInfos.ContainsKey(i))
- {
- // 获取完整路径
- string buildPath = SceneUtility.GetScenePathByBuildIndex(i);
- if (!string.IsNullOrEmpty(buildPath))
- {
- string buildSceneName = buildPath.Substring(buildPath.LastIndexOf('/') + 1).Split('.')[0];
- m_RecordAllBuildSceneInfos.Add(i, buildSceneName);
- }
- }
- }
- foreach (var item in m_RecordAllBuildSceneInfos)
- {
- string[] tmpInfo = item.Value.Split('_');
- //判定类型是否相同
- if (m_OperationType.Contains(tmpInfo[tmpInfo.Length - 1]))
- {
- m_RecordSceneName = item.Value;
- }
- }
- if (!string.IsNullOrEmpty(m_RecordSceneName))
- {
- SceneManager.LoadSceneAsync(m_RecordSceneName, LoadSceneMode.Single);
- }
- }
- }
|