Commit 3a937be2 authored by 杨泽宇's avatar 杨泽宇

更新

parent 0b09ad0c
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zeus.DTC;
public class AGVDemoV2 : MonoBehaviour
{
public LoginManager manager;
public DTAGVManager AGVManager;
public void Update()
{
UpdatePosition();
}
private void UpdatePosition()
{
AGVManager.AddMoveMsg("AGV1", manager.position);
}
}
fileFormatVersion: 2
guid: 70ce38d3ef83a1f438e6ed87bac54356
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Zeus.SQLite;
using LitJson;
using System.IO;
using System.Diagnostics;
using System.Linq;
using Debug = UnityEngine.Debug;
using System;
/// <summary>
/// 模拟数据功能中心
/// </summary>
public class CrrcSimManager : MonoBehaviour
{
public bool IsRecord;
public string DBName = "crrc";
protected SQLiteConnection _connection;
public LoginManager Manager;
public TMPro.TMP_Text Msg;
public TMPro.TMP_Text Error;
public Button StartBtn;
public Button StopBtn;
public Button QuitBtn;
public Button OpenFile;
[Header("模拟播放设置")]
[Tooltip("加载数据的开始时间")]
public float StartTime = 0;
[Tooltip("时间尺度,越小时间越快")]
public float TimeScale = 1;
[Tooltip("初始加载数据的时间间隔")]
public int PreLoadSecond = 100;
private string _dbName;
private int _errorNumber;
private System.DateTime _startTime;
private int _dataNumber;
private bool _isRecording = false;
private float _recordTime = 0;
private float _playTime = 0;
/// <summary>
/// 加载的数据
/// </summary>
private IEnumerable<IGrouping<float, SimJsonData>> _rsBuffer;
private Dictionary<float, IEnumerable<SimJsonData>> _dataDic;
void Start()
{
if (IsRecord)
{
Manager.OnReceiveMsg.AddListener(_saveData);
Manager.OnReceiveError.AddListener(_onError);
StartBtn?.onClick.AddListener(StartRecord);
StopBtn?.onClick.AddListener(StopRecord);
QuitBtn?.onClick.AddListener(() => { Application.Quit(); });
OpenFile.onClick.AddListener(_openFile);
//Manager.LoadConfig();
}
else
{
}
}
public virtual void StartPlay()
{
string path = DBName + ".db";
if (!File.Exists(path))
{
Debug.Log($"数据库:{path}不存在");
}
_connection = new SQLiteConnection(path, SQLiteOpenFlags.ReadOnly);
var start_time = StartTime;
var end_time = start_time + PreLoadSecond;
Debug.Log($"{start_time}-{end_time}");
_selectDataSet(start_time, end_time);
StartSendSimMsg();
//Debug.Log(_rsBuffer.Count());
//foreach (var item in _rsBuffer)
//{
// Debug.Log(item.Key.ToString("G"));
// foreach (var item2 in item)
// {
// Debug.Log(item2.DataType);
// }
//}
}
/// <summary>
/// 从数据库中选择延迟时间在指定范围内的数据,并按照延迟时间进行分组,最终将结果存储在 _rsBuffer 变量中。
/// </summary>
/// <param name="start_time"></param>
/// <param name="end_time"></param>
private void _selectDataSet(float start_time, float end_time)
{
_rsBuffer = _connection.Table<SimJsonData>()
.Where(x => x.DelaySecond >= start_time && x.DelaySecond < end_time)
.GroupBy(x => x.DelaySecond);
}
private bool _isSending = false;
public void StartSendSimMsg()
{
if (_isSending)
{
return;
}
_isSending = true;
StartCoroutine(_startSend());
}
public void StopSendSimMsg()
{
_isSending = false;
}
private IEnumerator _startSend()
{
var em = _rsBuffer.GetEnumerator();
em.MoveNext();
if (_rsBuffer.Count()<1)
{
Debug.LogError("没有数据");
yield break;
}
_playTime = _rsBuffer.First().Key;
Debug.Log(_playTime);
while (_isSending)
{
var current = em.Current;
var ctime = current.Key*TimeScale;
if (ctime<=_playTime)
{
foreach (var item in current)
{
if (item.DataType.Equals("LitJson.JsonData"))
{
var msg = JsonMapper.ToObject(item.JsonValue);
Manager.OnReceiveMsg.Invoke(msg, item.Param);
}
else
{
var tt = System.Type.GetType(item.Param);
var msg = JsonMapper.ToObject(item.JsonValue, tt);
Manager.OnReceiveMsg.Invoke(msg, null);
}
}
if (!em.MoveNext())
{
var start_time = ctime;
var end_time = start_time + PreLoadSecond;
//Debug.Log($"{start_time}-{end_time}");
_selectDataSet(start_time,end_time);
em = _rsBuffer.GetEnumerator();
em.MoveNext();
}
}
_playTime += Time.deltaTime;
yield return null;
}
}
#region 记录相关逻辑
public virtual void StartRecord()
{
Msg.text = "开始";
Error.text = "";
_errorNumber = 0;
_dataNumber = 0;
_startTime = System.DateTime.Now;
_dbName = DBName + System.DateTime.Now.ToString("yyyy-MM-dd-hhmmss") + ".db";
try
{
_connection = new SQLiteConnection(_dbName, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
}
catch(Exception e){
Msg.text = e.ToString();
}
_connection.CreateTable<SimJsonData>();
_isRecording = true;
_recordTime = 0;
Manager.StartLogin();
}
public virtual void StopRecord()
{
_connection.Dispose();
_isRecording = false;
//Manager.StopRequestData();
}
protected void _onError(string eeror)
{
_errorNumber++;
Error.text = $"采集失败:{_errorNumber}";
}
protected void _saveData(object data, string parameter)
{
SimJsonData js = new SimJsonData() { JsonValue = JsonMapper.ToJson(data), DelaySecond = _recordTime, DataType = data.GetType().ToString(), Param = parameter };
_connection.Insert(js);
_dataNumber++;
}
protected void _openFile()
{
if (File.Exists(_dbName))
{
Process.Start("explorer", "/select,\"" + _dbName + "\"");
}
}
#endregion
private void Update()
{
if (_isRecording)
{
Msg.text = $"采集时长:{_recordTime.ToString("0")},采集数据:{_dataNumber}";
_recordTime += Time.deltaTime;
}
}
private void OnDisable()
{
if (_connection != null)
{
_connection.Dispose();
}
}
[System.Serializable]
public class SimJsonData
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public float DelaySecond { get; set; }
public string DataType { get; set; }
public string JsonValue { get; set; }
public string Param { get; set; }
}
}
fileFormatVersion: 2
guid: 15ea17d1782e6ce46946baa53e2270a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zeus.SQLite;
using System.Linq;
using LitJson;
using System.IO;
/// <summary>
/// 读取db文件数据
/// </summary>
public class DatabaseReader : MonoBehaviour
{
[Tooltip("db文件的名字")]
public string DBName;
[Tooltip("获取信息管理器")]
public LoginManager Manager;
[Header("模拟播放设置")]
[Tooltip("加载数据的开始时间")]
public float StartTime = 0;
[Tooltip("时间尺度,越小时间越快")]
public float TimeScale = 1; // 模拟数据的播放速度
[Tooltip("初始加载数据的时间间隔")]
public int PreLoadSecond = 100; // 控制在开始播放模拟数据时预先加载的时间范围,确保模拟数据的流畅播放。
[Tooltip("存储模拟数据的数据结构")]
private IEnumerable<IGrouping<float, SimJsonData>> _rsBuffer;//存储模拟数据并按延迟时间进行分组的数据结构,为模拟数据的加载和处理提供了便利。
[Tooltip("是否正在发送模拟消息")]
private bool _isSending = false;
[Tooltip("记录模拟数据播放的当前时间")]
private float _playTime = 0;
[Tooltip("SQLite连接对象")]
private SQLiteConnection connection;
// Start is called before the first frame update
void Start()
{
StartPlay();
}
/// <summary>
/// 读取db文件中的测试数据
/// </summary>
public virtual void StartPlay()
{
string path = DBName + ".db";
if (!File.Exists(path))
{
Debug.Log($"数据库:{path}不存在");
}
connection = new SQLiteConnection(path, SQLiteOpenFlags.ReadOnly);
var start_time = StartTime;
var end_time = start_time + PreLoadSecond;
Debug.Log($"{start_time}-{end_time}");
_selectDataSet(start_time, end_time);
StartSendSimMsg();
}
/// <summary>
/// 负责从数据库中选择数据并按延迟时间进行分组,为后续模拟数据的加载和处理提供了准备工作。
/// </summary>
/// <param name="start_time"></param>
/// <param name="end_time"></param>
private void _selectDataSet(float start_time, float end_time)
{
_rsBuffer = connection.Table<SimJsonData>()
.Where(x => x.DelaySecond >= start_time && x.DelaySecond < end_time)
.GroupBy(x => x.DelaySecond);
}
/// <summary>
/// 启动模拟消息的发送过程,从而触发模拟数据的播放或发送,用于模拟特定场景下的消息传递、事件触发等情况。
/// </summary>
public void StartSendSimMsg()
{
if (_isSending)
{
return;
}
_isSending = true;
StartCoroutine(_startSend());
}
/// <summary>
/// 用于模拟数据的发送过程。
/// </summary>
/// <returns></returns>
private IEnumerator _startSend()
{
var em = _rsBuffer.GetEnumerator();
em.MoveNext();
if (_rsBuffer.Count() < 1)
{
Debug.LogError("没有数据");
yield break;
}
_playTime = _rsBuffer.First().Key;
Debug.Log(_playTime);
while (_isSending)
{
var current = em.Current;
var ctime = current.Key * TimeScale;
if (ctime <= _playTime)
{
foreach (var item in current)
{
if (item.DataType.Equals("LitJson.JsonData"))
{
var msg = JsonMapper.ToObject(item.JsonValue);
Manager.OnReceiveMsg.Invoke(msg, item.Param);
}
else
{
var tt = System.Type.GetType(item.Param);
var msg = JsonMapper.ToObject(item.JsonValue, tt);
Manager.OnReceiveMsg.Invoke(msg, null);
}
}
if (!em.MoveNext())
{
var start_time = ctime;
var end_time = start_time + PreLoadSecond;
//Debug.Log($"{start_time}-{end_time}");
_selectDataSet(start_time, end_time);
em = _rsBuffer.GetEnumerator();
em.MoveNext();
}
}
_playTime += Time.deltaTime;
yield return null;
}
}
/// <summary>
/// 用于标识模拟数据中的一条记录
/// </summary>
[System.Serializable]
public class SimJsonData
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public float DelaySecond { get; set; }
public string DataType { get; set; }
public string JsonValue { get; set; }
public string Param { get; set; }
}
}
fileFormatVersion: 2
guid: 688aa349ad8f0444fa5e8033f6379dee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using UnityEngine.Networking;
using UnityEngine;
using TMPro;
public class LoginManager : MonoBehaviour
{
public TMP_InputField productionlineID;
public string ProductionlineID;
private RobotPositionData positionData;
[Header("收到服务器信息事件")]
public ReceiveMsgEvent<object, string> OnReceiveMsg = new ReceiveMsgEvent<object, string>();
public ReceiveMsgEvent<string> OnReceiveError = new ReceiveMsgEvent<string>();
[Space]
[Header("获取的信息")]
public Vector3 position;
private void Awake()
{
OnReceiveMsg.AddListener(_getData);
......@@ -25,6 +27,10 @@ public class LoginManager : MonoBehaviour
StartCoroutine(GetPositionData());
}
public void StartLogin()
{
StartCoroutine(GetPositionData());
}
protected void _getData(object data, string parameter)
{
......@@ -40,7 +46,8 @@ public class LoginManager : MonoBehaviour
{
while (true)
{
using (UnityWebRequest request = UnityWebRequest.Get(ProductionlineID))
using (UnityWebRequest request = UnityWebRequest.Get(productionlineID.text))
{
// 设置请求头
request.SetRequestHeader("Content-Type", "application/json");
......
This diff is collapsed.
fileFormatVersion: 2
guid: 2b6b1e3fbd74e734f83f4c1db822d90f
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -18,12 +18,11 @@ public class TouristModeController : MonoBehaviour
public GameObject FreeCamera;
[Tooltip("固定摄像头中动画的名字")]
public string animName;
[Tooltip("模式选择UI")]
public GameObject ModeSelectionUI;
[Tooltip("导览模式UI")]
public GameObject VisitUI;
[Tooltip("机器巡检模式UI")]
public GameObject MachineInspectionUI;
[Tooltip("人物模式UI")]
public GameObject CharacterModeUI;
[Tooltip("人物模式UI")]
public GameObject ReturnUI;
[Tooltip("复位按钮")]
public Button ResetBtn;
[Tooltip("播/放按钮")]
......@@ -78,6 +77,11 @@ public class TouristModeController : MonoBehaviour
// 将Animator的播放位置转换为Slider的数值
float value = planeAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
slider.value = value;
// 检查动画是否播放完毕
if (value >= 1.0f)
{
Restart();
}
}
}
......@@ -89,8 +93,8 @@ public class TouristModeController : MonoBehaviour
ExitObserve();
RobotInspection.SetActive(true);
IsArtificial = true;
ModeSelectionUI.SetActive(false);
MachineInspectionUI.SetActive(true);
CharacterModeUI.SetActive(false);
ReturnUI.SetActive(true);
}
......@@ -101,7 +105,10 @@ public class TouristModeController : MonoBehaviour
public void SetEncircle()
{
ExitObserve();
Player.AutoRotate = true;
CharacterModeUI.SetActive(false);
ReturnUI.SetActive(true);
}
......@@ -112,11 +119,11 @@ public class TouristModeController : MonoBehaviour
{
ExitObserve();
FixCamera.SetActive(true);
VisitUI.SetActive(true);
ModeSelectionUI.SetActive(false);
MachineInspectionUI.SetActive(false);
Player.BackToInitPosition();
Player.IsPause = true;
PauseOrResumeAnimator();
CharacterModeUI.SetActive(false);
ReturnUI.SetActive(true);
}
/// <summary>
......@@ -203,14 +210,13 @@ public class TouristModeController : MonoBehaviour
PauseOrResumeAnimator();
//FreeCamera.SetActive(false);
FixCamera.SetActive(false);
VisitUI.SetActive(false);
ModeSelectionUI.SetActive(true);
MachineInspectionUI.SetActive(false);
Player.BackToInitPosition();
Player.IsPause = false;
Player.AutoRotate = false;
RobotInspection.SetActive(false);
IsArtificial = false;
CharacterModeUI.SetActive(true);
ReturnUI.SetActive(false);
}
/// <summary>
......@@ -237,6 +243,7 @@ public class TouristModeController : MonoBehaviour
slider.value = 0f;
planeAnimator.Play(animName, 0, 0); // 将Animator的播放位置设置为0
planeAnimator.speed = speeds; // 确保动画按照当前设置的速度播放
}
/// <summary>
......
......@@ -103,7 +103,7 @@ MonoBehaviour:
m_PrefilterSSAOSampleCountHigh: 1
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 1
m_PrefilterDBufferMRT3: 0
m_PrefilterSoftShadowsQualityLow: 1
m_PrefilterSoftShadowsQualityMedium: 1
m_PrefilterSoftShadowsQualityHigh: 1
......
......@@ -103,7 +103,7 @@ MonoBehaviour:
m_PrefilterSSAOSampleCountHigh: 0
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 1
m_PrefilterDBufferMRT3: 0
m_PrefilterSoftShadowsQualityLow: 1
m_PrefilterSoftShadowsQualityMedium: 1
m_PrefilterSoftShadowsQualityHigh: 1
......
This diff is collapsed.
This diff is collapsed.
fileFormatVersion: 2
guid: 7cb79544f5cf7bb41afc6ff81fa0afd7
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -54,7 +54,7 @@ AnimationClip:
m_Curve:
- serializedVersion: 3
time: 0
value: {x: -22.1, y: 3.5, z: 2.9}
value: {x: -22.1, y: 2.17, z: 2.9}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0
......@@ -63,7 +63,7 @@ AnimationClip:
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 20
value: {x: 9.08, y: 3.5, z: 2.9}
value: {x: 9.08, y: 2.17, z: 2.9}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0
......@@ -72,7 +72,7 @@ AnimationClip:
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 25
value: {x: 9.08, y: 3.5, z: -8.94}
value: {x: 9.08, y: 2.17, z: -8.94}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0
......@@ -81,7 +81,7 @@ AnimationClip:
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 45
value: {x: -16.34, y: 3.5, z: -8.94}
value: {x: -16.34, y: 2.17, z: -8.94}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0
......@@ -196,7 +196,7 @@ AnimationClip:
m_Curve:
- serializedVersion: 3
time: 0
value: 3.5
value: 2.17
inSlope: 0
outSlope: 0
tangentMode: 136
......@@ -205,7 +205,7 @@ AnimationClip:
outWeight: 0.33333334
- serializedVersion: 3
time: 20
value: 3.5
value: 2.17
inSlope: 0
outSlope: 0
tangentMode: 136
......@@ -214,7 +214,7 @@ AnimationClip:
outWeight: 0.33333334
- serializedVersion: 3
time: 25
value: 3.5
value: 2.17
inSlope: 0
outSlope: 0
tangentMode: 136
......@@ -223,7 +223,7 @@ AnimationClip:
outWeight: 0.33333334
- serializedVersion: 3
time: 45
value: 3.5
value: 2.17
inSlope: 0
outSlope: 0
tangentMode: 136
......
......@@ -41,7 +41,7 @@ Material:
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: 1f5e75ae75e59c14fa83bfe60f419474, type: 3}
m_Scale: {x: 20, y: 20}
m_Scale: {x: 50, y: 50}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 2800000, guid: 5cb7cf199de3cf04295c4f7d70b8a3f8, type: 3}
......@@ -65,7 +65,7 @@ Material:
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 1f5e75ae75e59c14fa83bfe60f419474, type: 3}
m_Scale: {x: 20, y: 20}
m_Scale: {x: 50, y: 50}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 2800000, guid: d96163e0e505e3b47b8d014b9cc60b44, type: 3}
......@@ -101,7 +101,7 @@ Material:
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 3
- _BumpScale: 5
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
......@@ -119,7 +119,7 @@ Material:
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.314
- _Smoothness: 0.532
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
......@@ -128,8 +128,8 @@ Material:
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.8773585, g: 0.8773585, b: 0.8773585, a: 1}
- _Color: {r: 0.8773585, g: 0.8773585, b: 0.8773585, a: 1}
- _BaseColor: {r: 0.6886792, g: 0.6886792, b: 0.6886792, a: 1}
- _Color: {r: 0.6886792, g: 0.6886792, b: 0.6886792, a: 1}
- _EmissionColor: {r: 1.4017444, g: 1.6688899, b: 1.6981132, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
This diff is collapsed.
fileFormatVersion: 2
guid: 65f7dfec384977d42a8296bdbde6b01c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"DebugDataKind": 1,
"EnableArmv9SecurityFeatures": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX32": 6,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}
......@@ -5,7 +5,7 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
- enabled: 0
path: Assets/_Scenes/1_Main.unity
guid: a1193329f89803b4f8a14f6c0b15d2c1
- enabled: 0
......@@ -14,6 +14,9 @@ EditorBuildSettings:
- enabled: 0
path: Assets/_Scenes/1_MainScene.unity
guid: e4c39eb47535a384593b511e167b172c
- enabled: 1
path: Assets/_Scenes/CollectData.unity
guid: 7cb79544f5cf7bb41afc6ff81fa0afd7
m_configObjects:
com.unity.xr.management.loader_settings: {fileID: 11400000, guid: 01409c78069629f4b9a3f0db365bece6,
type: 2}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment