This commit is contained in:
yzx 2023-12-24 16:09:42 +08:00
parent 7091841463
commit 0b6ea93017
15 changed files with 10899 additions and 6173 deletions

View File

@ -42,6 +42,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Assets\Resources\UI\DrivePanel\Scripts\DrivePanel.cs" />
<Compile Include="Assets\Script\TurnSignalController.cs" />
<Compile Include="Assets\Plugin\FXVShieldEffect\Scripts\Other\FXVResetTrigger.cs" />
<Compile Include="Assets\Plugin\Standard Assets\Effects\ImageEffects\Scripts\ColorCorrectionCurves.cs" />
<Compile Include="Assets\Script\Old\StartUI.cs" />
@ -347,6 +348,7 @@
<Compile Include="Assets\Plugin\Standard Assets\Utility\AutoMobileShaderSwitch.cs" />
<Compile Include="Assets\SuperSplinesPro\SuperSplines\Spline\SplineInterpolator.cs" />
<Compile Include="Assets\Script\Old\Bule_SceneManager.cs" />
<Compile Include="Assets\Script\AnimationController.cs" />
<Compile Include="Assets\Plugin\Standard Assets\Characters\ThirdPersonCharacter\Scripts\AICharacterControl.cs" />
<Compile Include="Assets\Plugin\Standard Assets\Utility\AlphaButtonClickMask.cs" />
<Compile Include="Assets\Plugin\XFrame\Core\Tool\SystemWindowControl.cs" />

View File

@ -5,7 +5,7 @@ ModelImporter:
internalIDToNameTable:
- first:
74: 1827226128182048838
second: Take 001
second: donghua
externalObjects: {}
materials:
materialImportMode: 1
@ -30,10 +30,39 @@ ModelImporter:
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 2
animationWrapMode: 1
extraExposedTransformPaths: []
extraUserProperties: []
clipAnimations: []
clipAnimations:
- serializedVersion: 16
name: donghua
takeName: Take 001
internalID: 0
firstFrame: 0
lastFrame: 100
wrapMode: 0
orientationOffsetY: 0
level: 0
cycleOffset: 0
loop: 0
hasAdditiveReferencePose: 0
loopTime: 0
loopBlend: 0
loopBlendOrientation: 0
loopBlendPositionY: 0
loopBlendPositionXZ: 0
keepOriginalOrientation: 0
keepOriginalPositionY: 1
keepOriginalPositionXZ: 0
heightFromFeet: 0
mirror: 0
bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
curves: []
events: []
transformMask: []
maskType: 3
maskSource: {instanceID: 0}
additiveReferencePoseFrame: 0
isReadable: 0
meshes:
lODScreenPercentages: []

View File

@ -107769,6 +107769,7 @@ GameObject:
m_Component:
- component: {fileID: 1017393515}
- component: {fileID: 1017393516}
- component: {fileID: 1017393517}
m_Layer: 0
m_Name: CarInfo
m_TagString: Untagged
@ -107803,8 +107804,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
target: {fileID: 2037673176}
leftIndicator: {fileID: 330160449}
rightIndicator: {fileID: 372195432}
headlights: {fileID: 509049154}
windshieldWipers: {fileID: 925284883}
waterSpray: {fileID: 726134054}
@ -107818,6 +107817,20 @@ MonoBehaviour:
fuelLevel: {fileID: 1182716856}
fuelLevelValue: 100
totalDistanceTraveled: 0
--- !u!114 &1017393517
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1017393514}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b35b068fe71a3a247b1475999018324a, type: 3}
m_Name:
m_EditorClassIdentifier:
leftTurnSignal: {fileID: 330160449}
rightTurnSignal: {fileID: 372195432}
--- !u!1 &1017395938
GameObject:
m_ObjectHideFlags: 0
@ -118854,7 +118867,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1128464581}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 1559914993}
m_TargetAssemblyTypeName: AnimationController, Assembly-CSharp
m_MethodName: StopAnimationLoop
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1128464581
MonoBehaviour:
m_ObjectHideFlags: 0
@ -133240,45 +133265,6 @@ GameObject:
type: 3}
m_PrefabInstance: {fileID: 2037673174}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1276762318
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1276762317}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b4decbca4aaf413abd074ba71736660a, type: 3}
m_Name:
m_EditorClassIdentifier:
currentGear: 1
gearSpeeds:
- 0
- 5
- 40
- 60
xx: 0
carInfoManager: {fileID: 1017393516}
thirdPerson: {fileID: 1136185827}
firstPerson: {fileID: 2037673177}
shache:
- {fileID: 1953679095}
- {fileID: 1911478031}
--- !u!114 &1276762327
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1276762317}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5be1af227faf7b740b2a9b062718d7d9, type: 3}
m_Name:
m_EditorClassIdentifier:
puncture: {fileID: 1953679095}
UIl: {fileID: 6735400887519992078}
--- !u!1 &1276810904
GameObject:
m_ObjectHideFlags: 0
@ -167227,6 +167213,18 @@ GameObject:
type: 3}
m_PrefabInstance: {fileID: 2037673174}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1559914993
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1559914990}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6f761fb6984a4d53aa25f930746bc35b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1560932504
GameObject:
m_ObjectHideFlags: 0
@ -206918,102 +206916,6 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1909568741}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1911478031
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1911478032}
- component: {fileID: 1911478035}
- component: {fileID: 1911478034}
- component: {fileID: 1911478033}
m_Layer: 0
m_Name: "\u7206\u80CE (1)"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1911478032
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1911478031}
m_LocalRotation: {x: -0.26746163, y: -0.055704076, z: 0.043036826, w: 0.9609938}
m_LocalPosition: {x: -0.804, y: 0.114, z: -0.743}
m_LocalScale: {x: 0.4536, y: 0.072123155, z: 0.36368668}
m_Children: []
m_Father: {fileID: 2037673175}
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: -30.615, y: -8.694, z: 7.512}
--- !u!65 &1911478033
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1911478031}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1911478034
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1911478031}
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1911478035
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1911478031}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1911799428
GameObject:
m_ObjectHideFlags: 0
@ -210924,12 +210826,6 @@ Transform:
m_Father: {fileID: 526762205}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1953679095 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9404289244154715, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
m_PrefabInstance: {fileID: 2037673174}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1954022718
GameObject:
m_ObjectHideFlags: 0
@ -221803,101 +221699,40 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11461196, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: m_Enabled
value: 0
- target: {fileID: 1276762318, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: ygq
value:
objectReference: {fileID: 1559914993}
- target: {fileID: 1276762318, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: thirdPerson
value:
objectReference: {fileID: 1136185827}
- target: {fileID: 1276762318, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: carInfoManager
value:
objectReference: {fileID: 1017393516}
- target: {fileID: 1276762318, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: turnSignalController
value:
objectReference: {fileID: 1017393517}
- target: {fileID: 1276762318, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: gearSpeeds.Array.data[1]
value: 10
objectReference: {fileID: 0}
- target: {fileID: 11476534, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: maxSpeedForward
value: 20
objectReference: {fileID: 0}
- target: {fileID: 15384928, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: m_ConnectedAnchor.x
value: -0.394989
objectReference: {fileID: 0}
- target: {fileID: 15384928, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: m_ConnectedAnchor.z
value: -0.04498291
objectReference: {fileID: 0}
- target: {fileID: 9404289244154715, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2793264845307687955, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.122
objectReference: {fileID: 0}
- target: {fileID: 2793264845307687955, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalPosition.z
value: -0.744
objectReference: {fileID: 0}
- target: {fileID: 3190887408370009811, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalPosition.x
value: -0.34838867
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalPosition.y
value: 1.23
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.027679443
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.99916136
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalRotation.x
value: 0.037859958
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.015582657
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalRotation.z
value: -0.0005904539
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 4.34
objectReference: {fileID: 0}
- target: {fileID: 4279975699638886894, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 1.787
objectReference: {fileID: 0}
- target: {fileID: 5284178280183930675, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5843707903603987244, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6592002126774414827, guid: 4292160a5e1fde347934ac660b2c5d30,
- target: {fileID: 1276762327, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
propertyPath: UIl
value:
objectReference: {fileID: 6735400887519992078}
- target: {fileID: 6214432986421238931, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6214432986421238931, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
propertyPath: m_PlayAutomatically
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4292160a5e1fde347934ac660b2c5d30, type: 3}
--- !u!4 &2037673175 stripped
@ -221918,12 +221753,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2078a92a1f7b07b43aae2988fb3bf9aa, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2037673177 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3190887408370009811, guid: 4292160a5e1fde347934ac660b2c5d30,
type: 3}
m_PrefabInstance: {fileID: 2037673174}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2037822358
GameObject:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,49 @@
using UnityEngine;
using System.Collections;
public class AnimationController : MonoBehaviour
{
private Animation animationComponent;
private bool isPlaying = false; // 用于跟踪动画是否正在播放
private bool loopAnimation = true;
void Start()
{
animationComponent = GetComponent<Animation>();
}
public void PlayAnimation(string animationName)
{
if (!isPlaying) // 如果动画当前未在播放
{
StartCoroutine(PlayAnimationLoop(animationName));
}
}
IEnumerator PlayAnimationLoop(string animationName)
{
isPlaying = true; // 标记动画正在播放
loopAnimation = true;
while (loopAnimation)
{
animationComponent.Play(animationName);
// 等待动画播放完毕
yield return new WaitForSeconds(animationComponent[animationName].length/2);
// 检查是否应该继续循环
if (!loopAnimation)
{
break;
}
}
isPlaying = false; // 标记动画播放结束
}
// 调用此方法来停止循环播放动画
public void StopAnimationLoop()
{
loopAnimation = false;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6f761fb6984a4d53aa25f930746bc35b
timeCreated: 1703399326

View File

@ -38,6 +38,12 @@ namespace Script
public GameObject[] shache;
public AnimationController ygq;
public TurnSignalController turnSignalController;
private bool inputUp = false;
private int inputUpV;
void Start()
{
vehicleController = GetComponent<VehicleController>();
@ -71,9 +77,9 @@ namespace Script
// Debug.Log(client.modbusQueue.Count);
if (client.modbusQueue.Count > 0)
{
carData = client.modbusQueue.Dequeue();
Debug.Log(client.modbusQueue.Count);
Debug.Log(vehicleController.steerInput);
carData = client.modbusQueue.Dequeue();
//方向盘
@ -131,21 +137,21 @@ namespace Script
//转向灯 00是未开转向灯1是左转向灯2是右转向灯
//当钥匙转为通电才能启动转向灯 0熄火1通电2启动
if (carData.IgnitionSwitch == 1)
{
switch (carData.TurnSignalStatus)
{
case 0:
carInfoManager.StopBlinking();
break;
case 1:
carInfoManager.LeftStartBlinking();
break;
case 2:
carInfoManager.RightStartBlinking();
break;
}
}
// if (carData.IgnitionSwitch == 1)
// {
// switch (carData.TurnSignalStatus)
// {
// case 0:
// carInfoManager.StopBlinking();
// break;
// case 1:
// carInfoManager.LeftStartBlinking();
// break;
// case 2:
// carInfoManager.RightStartBlinking();
// break;
// }
// }
//上1,右2,下3左4
@ -153,13 +159,52 @@ namespace Script
{
NewValue = carData.ButtonData;
CarMenuButton(NewValue);
}
// else
// {
// continue;
// }
//雨刮器
if (carData.WiperStatus == 2)
{
ygq.PlayAnimation("donghua");
}
else
{
ygq.StopAnimationLoop();
}
if (carData.ButtonData == 1)
{
inputUpV = carData.TurnSignalStatus;
}
if ( inputUpV == carData.TurnSignalStatus)
{
turnSignalController.SetSignal(3);
}
else
{
inputUpV = -1;
switch (carData.TurnSignalStatus)
{
case 0:
turnSignalController.SetSignal(0);
break;
case 1:
turnSignalController.SetSignal(1);
break;
case 2:
turnSignalController.SetSignal(2);
break;
}
}
//刹车
if (carData.BrakePedalPosition > 40)
{
if (shache[0].activeInHierarchy)

View File

@ -12,8 +12,8 @@ public class CarInfoManager : MonoBehaviour
public VehicleController target;
[Header("左向灯")] public GameObject leftIndicator; // 左向灯
[Header("右向灯")] public GameObject rightIndicator; // 右向灯
// [Header("左向灯")] public GameObject leftIndicator; // 左向灯
// [Header("右向灯")] public GameObject rightIndicator; // 右向灯
[Header("前照灯")] public GameObject headlights; // 前照灯
[Header("雨刷器")] public GameObject windshieldWipers; // 雨刷器
[Header("喷水")] public GameObject waterSpray; // 喷水
@ -124,13 +124,12 @@ public class CarInfoManager : MonoBehaviour
public void LeftStartBlinking()
{
Indicator = leftIndicator;
StartBlinking(Indicator);
}
public void RightStartBlinking()
{
Indicator = rightIndicator;
StartBlinking(Indicator);
}
@ -141,7 +140,6 @@ public class CarInfoManager : MonoBehaviour
if (isBlinking)
return;
StopBlinking();
if (!isBlinking)

View File

@ -165,7 +165,7 @@ namespace ModbusManager
carStatusData.HornStatus = dataValue;
break;
case 3://0-100,踩到底为100
Debug.Log($"刹车踏板数据: {dataValue}");
// Debug.Log($"刹车踏板数据: {dataValue}");
carStatusData.BrakePedalPosition = dataValue;
break;
case 4://0-100,踩到底为100
@ -185,15 +185,15 @@ namespace ModbusManager
carStatusData.GearPosition = dataValue;
break;
case 8://00是空档1是手动一次雨刮2是自动雨刮慢速3是自动雨刮快速
//Debug.Log($"雨刮状态: {dataValue}");
// Debug.Log($"雨刮状态: {dataValue}");
carStatusData.WiperStatus = dataValue;
break;
case 9://00是未开灯1是示廓灯2是近光远光。。没有找到远光信号。
//Debug.Log($"灯光状态: {dataValue}");
// Debug.Log($"灯光状态: {dataValue}");
carStatusData.LightStatus = dataValue;
break;
case 10://00是未开转向灯1是左转向灯2是右转向灯
// Debug.Log($"转向灯状态: {dataValue}");
Debug.Log($"转向灯状态: {dataValue}");
carStatusData.TurnSignalStatus = dataValue;
break;
case 11://00是熄火1是通电2是点火

View File

@ -0,0 +1,106 @@
using System.Threading;
using UnityEngine;
using System.Threading.Tasks;
public class TurnSignalController : MonoBehaviour
{
public GameObject leftTurnSignal;
public GameObject rightTurnSignal;
private Task currentBlinkTask = null;
private CancellationTokenSource cancellationTokenSource;
private int currentSignalType = 0; // 当前的信号类型
public void SetSignal(int signalType)
{
// 如果当前信号类型与请求的信号类型相同,则不执行任何操作
if (currentSignalType == signalType)
{
return;
}
currentSignalType = signalType; // 更新当前信号类型
// 取消当前的动画任务(如果存在)
if (cancellationTokenSource != null)
{
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
}
cancellationTokenSource = new CancellationTokenSource();
switch (signalType)
{
case 1: // 左转向灯
currentBlinkTask = BlinkSignalAsync(leftTurnSignal, cancellationTokenSource.Token);
rightTurnSignal.SetActive(false);
break;
case 2: // 右转向灯
currentBlinkTask = BlinkSignalAsync(rightTurnSignal, cancellationTokenSource.Token);
leftTurnSignal.SetActive(false);
break;
case 3: // 双闪灯
currentBlinkTask = BlinkBothSignalsAsync(cancellationTokenSource.Token);
break;
// case 0: // 全部停止
// StopAllSignals();
// break;
}
}
private async Task BlinkSignalAsync(GameObject signal, CancellationToken ct)
{
bool isOn = false;
try
{
while (!ct.IsCancellationRequested)
{
isOn = !isOn;
signal.SetActive(isOn);
await Task.Delay(500, ct); // 等待500毫秒
}
}
catch (TaskCanceledException)
{
// 任务被取消时执行
}
signal.SetActive(false); // 确保灯光关闭
}
private async Task BlinkBothSignalsAsync(CancellationToken ct)
{
bool isOn = false;
try
{
while (!ct.IsCancellationRequested)
{
isOn = !isOn;
leftTurnSignal.SetActive(isOn);
rightTurnSignal.SetActive(isOn);
await Task.Delay(500, ct); // 等待500毫秒
}
}
catch (TaskCanceledException)
{
// 任务被取消时执行
}
leftTurnSignal.SetActive(false);
rightTurnSignal.SetActive(false);
}
private void StopAllSignals()
{
if (cancellationTokenSource != null)
{
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
}
leftTurnSignal.SetActive(false);
rightTurnSignal.SetActive(false);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b35b068fe71a3a247b1475999018324a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +0,0 @@
Base path: 'D:/2021.1.24f1/Editor/Data', plugins path 'D:/2021.1.24f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler