This commit is contained in:
yzx 2024-01-04 16:36:32 +08:00
parent 4994bc6c69
commit 5619199284
7 changed files with 87 additions and 85 deletions

View File

@ -89,8 +89,8 @@ Material:
- _TexWidth: 16
- _UVSec: 0
- _WiperAmount: 0
- _WiperAngle: 0
- _WiperAxis: 1
- _WiperAngle: 76.7
- _WiperAxis: -5.65
- _WiperDirection: 0
- _WiperInterval: 0.5
- _WiperRadius: 0.8

View File

@ -112408,7 +112408,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
propertyPath: m_LocalPosition.y
value: 85.44423
value: 42.4
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
propertyPath: m_LocalPosition.z
@ -112474,7 +112474,10 @@ PrefabInstance:
propertyPath: m_Materials.Array.size
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 1863041211, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
- {fileID: 1737035857396294927, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
- {fileID: 2841325780535831473, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: ffb8dbf6042ec5c429e690af20fbde5d, type: 3}
--- !u!1 &351006295
GameObject:
@ -340162,71 +340165,6 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!21 &1099108936
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Override
m_Shader: {fileID: 4800000, guid: a3a3bc8785681554d9558e2ea68f100e, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _DirectionalFalloff: 2
- _DirectionalIntensity: 1
- _FarDistanceHeight: 0
- _FarDistanceOffset: 0
- _FogAxisMode: 1
- _FogCameraMode: 0
- _FogCat: 1
- _FogColorDuo: 1
- _FogDistanceEnd: 100
- _FogDistanceFalloff: 2
- _FogDistanceStart: 0
- _FogHeightEnd: 100
- _FogHeightFalloff: 2
- _FogHeightStart: 0
- _FogIntensity: 1
- _FogLayersMode: 0
- _IsHeightFogPreset: 1
- _IsHeightFogShader: 1
- _JitterIntensity: 1
- _NoiseCat: 1
- _NoiseDistanceEnd: 50
- _NoiseIntensity: 1
- _NoiseMax: 1
- _NoiseMin: 0
- _NoiseModeBlend: 1
- _NoiseScale: 30
- _SkyboxCat: 1
- _SkyboxFogBottom: 0
- _SkyboxFogFalloff: 1
- _SkyboxFogFill: 1
- _SkyboxFogHeight: 1
- _SkyboxFogIntensity: 1
- _SkyboxFogOffset: 0
m_Colors:
- _DirectionalColor: {r: 1, g: 0.7793103, b: 0.5, a: 1}
- _DirectionalDir: {r: 0, g: 0, b: 0, a: 0}
- _FogAxisOption: {r: 0, g: 0, b: 0, a: 0}
- _FogColorEnd: {r: 0.8862745, g: 1.443137, b: 2, a: 1}
- _FogColorStart: {r: 0.4411765, g: 0.722515, b: 1, a: 1}
- _NoiseSpeed: {r: 0.5, g: 0, b: 0.5, a: 0}
m_BuildTextureStacks: []
--- !u!1 &1099122116
GameObject:
m_ObjectHideFlags: 0
@ -378046,7 +377984,7 @@ Transform:
m_LocalScale: {x: 46.442844, y: 0.36673844, z: 50.597057}
m_Children: []
m_Father: {fileID: 1866218924}
m_RootOrder: 693
m_RootOrder: 691
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1224440451
BoxCollider:
@ -461205,7 +461143,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1482950187
Transform:
m_ObjectHideFlags: 0
@ -512342,7 +512280,7 @@ Transform:
m_LocalScale: {x: 46.442844, y: 0.36673844, z: 50.597057}
m_Children: []
m_Father: {fileID: 1866218924}
m_RootOrder: 694
m_RootOrder: 692
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1644651297
BoxCollider:
@ -612701,7 +612639,7 @@ Transform:
m_LocalScale: {x: 46.442844, y: 0.36673844, z: 50.597057}
m_Children: []
m_Father: {fileID: 1866218924}
m_RootOrder: 695
m_RootOrder: 693
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1963281148
BoxCollider:
@ -656471,7 +656409,7 @@ Transform:
m_LocalScale: {x: 55.09669, y: 0.36673844, z: 61.54306}
m_Children: []
m_Father: {fileID: 1866218924}
m_RootOrder: 692
m_RootOrder: 690
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &2085621374
BoxCollider:

View File

@ -77,6 +77,9 @@ namespace Script
{
client = new ModbusTcpClient();
await client.ConnectToServer();
// client.StartModbus();
while (true)
{
await client.SendModbusRequest();
@ -435,6 +438,13 @@ namespace Script
// vehicleStandardInput.SetThrottleValue(xx);
// SetSpeedBasedOnValue(1);
if (Input.GetKeyDown(KeyCode.F12))
{
client.SendModbusRequest();
}
}
void CheckAndUpdateGear()

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
@ -34,6 +35,10 @@ namespace ModbusManager
public Queue<CarStatusData> modbusQueue;
public static ModbusTcpClient modbusTcpClient;
private CancellationTokenSource cancellationTokenSource;
private void Awake()
{
modbusTcpClient = this;
@ -44,20 +49,24 @@ namespace ModbusManager
private void Start()
{
// StartModbus();
}
async Task StartModbus()
public void StartModbus()
{
await ConnectToServer();
while (true)
{
await SendModbusRequest();
// await SendModbusRequest12();
await Task.Delay(TimeSpan.FromSeconds(.1));
}
cancellationTokenSource = new CancellationTokenSource();
// MonitorConnection(cancellationTokenSource.Token);
MonitorQueue(cancellationTokenSource.Token);
// await ConnectToServer();
// while (true)
// {
// await SendModbusRequest();
// // await SendModbusRequest12();
// await Task.Delay(TimeSpan.FromSeconds(.1));
// }
}
private void OnDestroy()
@ -124,6 +133,47 @@ namespace ModbusManager
}
}
private async Task MonitorConnection(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
if (!tcpClient.Connected)
{
try
{
await ConnectToServer();
}
catch (Exception ex)
{
Debug.Log("连接失败: " + ex.Message);
await Task.Delay(TimeSpan.FromSeconds(1), token); // 重试前等待
}
}
await Task.Delay(TimeSpan.FromSeconds(1), token); // 检查间隔
}
}
private async Task MonitorQueue(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
if (modbusQueue.Count == 0)
{
await SendModbusRequest();
await Task.Delay(TimeSpan.FromSeconds(3), token); // 队列检查频率
}
else
{
await Task.Delay(TimeSpan.FromSeconds(1), token); // 等待一段时间后再次检查
}
}
}
/// <summary>
/// 设备回复: 00 00 00 00 00 24 01 03 20 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0A 00 0B 00 0C 00 0D 00 0E 00 0F 00 10
/// "00 00 00 00 00 24" 为TCP报文头24 表示后面有三十六个字节。
@ -241,6 +291,7 @@ namespace ModbusManager
{
tcpClient.GetStream().Close();
tcpClient.Close();
cancellationTokenSource.Cancel();
Debug.Log("已关闭与Modbus服务器的连接。");
}
}

View File

@ -28,6 +28,9 @@ public class WeatherManager : MonoBehaviour
case "雪天":
weather_snow.SetActive(true);
xuetianglass.SetActive(true);
weather_snow.transform.Find("下雪01").GetComponent<ParticleSystem>().Play();
// 地面.transform.GetComponent<MeshRenderer>().material = snowMaterial;
break;
case "雾天":

View File

@ -18,10 +18,10 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c52151802563f22213229
flags: 0
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c52111f19276439262f2434
value: 22424703114646680e0b0227036c4c0417050c6439262f2434
flags: 0
RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c4c0417050c6439262f2434
value: 22424703114646680e0b0227036c52111f19276439262f2434
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650