diff --git a/Assets/Resources/Prefabs/Fix/Body Module System.prefab b/Assets/Resources/Prefabs/Fix/Body Module System.prefab index 33d1c8f0b..c37a5d890 100644 --- a/Assets/Resources/Prefabs/Fix/Body Module System.prefab +++ b/Assets/Resources/Prefabs/Fix/Body Module System.prefab @@ -99,7 +99,7 @@ Transform: m_GameObject: {fileID: 250470736151292147} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.906, y: -0.005, z: 0} + m_LocalPosition: {x: -0.907, y: -0.013, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 1 m_Children: [] @@ -194,7 +194,7 @@ Transform: m_GameObject: {fileID: 555303476111083303} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.823, y: -0.017, z: 0} + m_LocalPosition: {x: -3.73, y: 1.36, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -495,12 +495,13 @@ Transform: m_GameObject: {fileID: 2195061089379433005} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 5.17, y: -1.08, z: 0} + m_LocalPosition: {x: 4.99, y: -2.44, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1743353464033058114} - {fileID: 3859112564590585838} + - {fileID: 7241028875149812054} - {fileID: 1535758981242426442} - {fileID: 1569079734487556461} m_Father: {fileID: 3722350651361937496} @@ -811,6 +812,7 @@ MonoBehaviour: oscilloscopeSystem: {fileID: 0} heatMapController: {fileID: 0} inHotErr: 0 + isAvailable: 0 plugSnappingRange: 1 --- !u!1 &4168341163486249011 GameObject: @@ -1237,14 +1239,14 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4645710116166496809} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalRotation: {x: 0, y: 0, z: 1, w: 0} + m_LocalPosition: {x: -3.77, y: -0.36, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 5095564283598629642} m_Father: {fileID: 2117906688623379083} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 180} --- !u!212 &2511148540085322114 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1605,6 +1607,174 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &7941528351979412028 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7241028875149812054} + - component: {fileID: 8510989684355122179} + - component: {fileID: 6419949317661297543} + - component: {fileID: 5032000501216978222} + m_Layer: 0 + m_Name: PhysicCable + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7241028875149812054 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7941528351979412028} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2117906688623379083} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!120 &8510989684355122179 +LineRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7941528351979412028} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 0 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 51099a9679b002c46b76c25f9ac139e3, type: 2} + 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: 1134468525 + m_SortingLayer: 10 + m_SortingOrder: 48 + m_Positions: + - {x: 0, y: 0, z: 0} + m_Parameters: + serializedVersion: 3 + widthMultiplier: 1 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0.012138367 + value: 0.3029231 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + serializedVersion: 2 + key0: {r: 0.0012815695, g: 0.18719505, b: 0.33962262, a: 1} + key1: {r: 0, g: 0.41209447, b: 0.5660378, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65342 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + numCornerVertices: 6 + numCapVertices: 6 + alignment: 0 + textureMode: 0 + textureScale: {x: 1, y: 1} + shadowBias: 0.5 + generateLightingData: 0 + m_MaskInteraction: 0 + m_UseWorldSpace: 1 + m_Loop: 0 + m_ApplyActiveColorSpace: 1 +--- !u!114 &6419949317661297543 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7941528351979412028} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cc956cb4eb967a4498d7eeef575ceb63, type: 3} + m_Name: + m_EditorClassIdentifier: + StartTranform: {fileID: 1569079734487556461} + endTransform: {fileID: 1743353464033058114} + physicLine: {fileID: 5032000501216978222} +--- !u!114 &5032000501216978222 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7941528351979412028} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1198bee0150e12d4aa20514b2c8f3362, type: 3} + m_Name: + m_EditorClassIdentifier: + segmentSpacing: 0.1 + k: 30 + lineRenderer: {fileID: 0} + gravity: -15 --- !u!1 &8134912130971034244 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/PeipeiFixScene.unity b/Assets/Scenes/PeipeiFixScene.unity index 2789f31e8..e593c4352 100644 --- a/Assets/Scenes/PeipeiFixScene.unity +++ b/Assets/Scenes/PeipeiFixScene.unity @@ -37223,14 +37223,6 @@ PrefabInstance: propertyPath: m_SortingOrder value: 9 objectReference: {fileID: 0} - - target: {fileID: 1535758981242426442, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} - propertyPath: m_LocalPosition.x - value: -0.907 - objectReference: {fileID: 0} - - target: {fileID: 1535758981242426442, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} - propertyPath: m_LocalPosition.y - value: -0.013 - objectReference: {fileID: 0} - target: {fileID: 1953141088643421057, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_Color.b value: 0 @@ -37243,14 +37235,6 @@ PrefabInstance: propertyPath: m_Color.r value: 0 objectReference: {fileID: 0} - - target: {fileID: 2117906688623379083, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} - propertyPath: m_LocalPosition.x - value: 4.99 - objectReference: {fileID: 0} - - target: {fileID: 2117906688623379083, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} - propertyPath: m_LocalPosition.y - value: -2.44 - objectReference: {fileID: 0} - target: {fileID: 2411966172391820548, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_IsActive value: 1 diff --git a/Assets/Scenes/Persistence.unity b/Assets/Scenes/Persistence.unity index c8663d0d9..ec97e9980 100644 --- a/Assets/Scenes/Persistence.unity +++ b/Assets/Scenes/Persistence.unity @@ -6343,7 +6343,7 @@ Transform: m_GameObject: {fileID: 519420028} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalPosition: {x: -4.66, y: 0, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -8254,10 +8254,10 @@ MonoBehaviour: - {fileID: 11400000, guid: 8d8b11f0c2fbc4d4cb8c2857d98383c9, type: 2} - {fileID: 11400000, guid: afc5b01ef301cc74db7cae741acad427, type: 2} - {fileID: 11400000, guid: ac5ca9a66ff22ab4b9cd5adbdade6b8c, type: 2} - runMode: 1 + runMode: 2 firstTalkSo: {fileID: 11400000, guid: ac5ca9a66ff22ab4b9cd5adbdade6b8c, type: 2} testTalkSo: {fileID: 11400000, guid: bd44f6c25aa17a4408e172d16b903176, type: 2} - saveFileName: "PeipeiDay1_\u7ED3\u675F\u5BF9\u8BDD" + saveFileName: "PeipeiDay1_UF\u68C0\u67E5" --- !u!4 &719228339 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/FixSystem/Cable/PhysicCable.cs b/Assets/Scripts/FixSystem/Cable/PhysicCable.cs index ad892c234..922581b9f 100644 --- a/Assets/Scripts/FixSystem/Cable/PhysicCable.cs +++ b/Assets/Scripts/FixSystem/Cable/PhysicCable.cs @@ -13,10 +13,10 @@ public class PhysicCable : MonoBehaviour { physicLine=transform.GetChild(0).GetComponent(); } - public void Init() + public void Init(Vector3 endPos) { - physicLine.Initialize(StartTranform.position,endTransform.position); + physicLine.Initialize(StartTranform.position,endPos); } // Update is called once per frame diff --git a/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs b/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs index 1dff27caf..a4c7c4cbd 100644 --- a/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs +++ b/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using UnityEngine; +using DG.Tweening; [RequireComponent(typeof(LineRenderer))] public class PhysicLineSegment : MonoBehaviour @@ -13,16 +14,24 @@ public class PhysicLineSegment : MonoBehaviour private List sticks = new List(); [HideInInspector] public LineRenderer lineRenderer; - public int segmentCount; + private int segmentCount; public float gravity = -9.8f; private float originalLength; + private float targetLength; public void Initialize(Vector3 start, Vector3 end) { + particles.Clear(); + sticks.Clear(); + if (lineRenderer != null) + { + lineRenderer.positionCount = 0; + } this.start = start; this.end = end; originalLength = Vector3.Distance(start, end); + targetLength = originalLength; // 初始化目标长度 segmentCount = Mathf.RoundToInt(originalLength / segmentSpacing); lineRenderer = GetComponent(); @@ -51,11 +60,10 @@ public class PhysicLineSegment : MonoBehaviour UpdateLine(); for (int i = 0; i < segmentCount; i++) { - if(lineRenderer!=null) + if (lineRenderer != null) { lineRenderer.SetPosition(i, particles[i].position); } - } } @@ -77,6 +85,51 @@ public class PhysicLineSegment : MonoBehaviour } } } + + public void SetTargetLength(float newLength, float duration) + { + DOTween.To(() => targetLength, x => targetLength = x, newLength, duration); + } + + public void UpdateLineLength(float newLength) + { + // 计算新的段数 + int newSegmentCount = Mathf.RoundToInt(newLength / segmentSpacing); + + // 如果新的段数大于当前段数,增加粒子 + if (newSegmentCount > segmentCount) + { + for (int i = segmentCount; i < newSegmentCount; i++) + { + var particle = new VerletParticle(Vector3.Lerp(start, end, i / (float)newSegmentCount)); + particles.Add(particle); + if (i > 0) + { + sticks.Add(new VerletStick(particles[i - 1], particles[i], segmentSpacing)); + } + } + } + // 如果新的段数小于当前段数,减少粒子 + else if (newSegmentCount < segmentCount) + { + particles.RemoveRange(newSegmentCount, segmentCount - newSegmentCount); + sticks.RemoveRange(newSegmentCount - 1, segmentCount - newSegmentCount); + } + + // 更新段数 + segmentCount = newSegmentCount; + if(lineRenderer!=null) + { + lineRenderer.positionCount = segmentCount; + } + + // 更新粒子位置 + for (int i = 0; i < segmentCount; i++) + { + particles[i].position = Vector3.Lerp(start, end, i / (float)segmentCount); + } + } + public void UpdatePlug(Transform plug) { if (plug != null && particles.Count > 1) @@ -87,14 +140,12 @@ public class PhysicLineSegment : MonoBehaviour float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; plug.rotation = Quaternion.Euler(0, 0, angle - 90f); plug.position = plugPosition + direction.normalized * (plugLength / 2); - - } } + public void UpdateEndPoint(Transform transform) { particles[particles.Count - 1].isLocked = true; particles[particles.Count - 1].position = transform.position; } - } \ No newline at end of file diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs index b38a747e8..64123ec15 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs @@ -67,7 +67,7 @@ namespace AibisDream.FixSystem float t = Mathf.InverseLerp(config.dstMin, config.dstMax, (_start.position - _end.position).magnitude); float F = Mathf.Lerp(config.forceMin, config.forceMax, t); _points[0] = _start.position; - _points[^1] = _end.GetChild(0).position; + _points[^1] = _end.position; for (int ik = 0; ik < config.k; ik++) { for (int i = 1; i < _points.Length - 1; i++) diff --git a/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs b/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs index 0c8e551d1..dea7763e9 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/CableSystem.cs @@ -67,8 +67,9 @@ namespace AibisDream.FixSystem private void InitSystem() { - //PlugRef.InitPlug(InitSocket); - PhysicCableRef.Init(); + + //PhysicCableRef.Init(); + PlugRef.InitPlug(InitSocket); } public void Update() { @@ -81,7 +82,7 @@ namespace AibisDream.FixSystem if (curSocket == InitSocket) return; // 不在初始插孔里,就从当前插孔拔出来,插回初始插孔 PlugRef.PullUpSocket(); - PlugRef.InsertSocket(InitSocket); + PlugRef.ReturnToStartPosition(); } /// diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs index b2b2bbefa..74164c05c 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs @@ -13,10 +13,12 @@ namespace AibisDream.FixSystem #region 插头当前信息 private Vector3 _startPos; - private Vector3 _startRotate; private readonly Vector3 _pickupOffset = new(0, 0, 0); private readonly Quaternion _pickupRotationOffset = Quaternion.Euler(0, 0, 30); + private readonly Quaternion initRotation = Quaternion.Euler(0, 0, 180); + + #endregion #region 索引 @@ -29,11 +31,13 @@ namespace AibisDream.FixSystem #endregion private bool _isDragging; + private bool _isPhysicCableActive=false; private void Awake() { InitComponentRef(); EventRegister(); + _startPos = transform.position; // 初始化时记录初始位置 } private void InitComponentRef() @@ -53,14 +57,9 @@ namespace AibisDream.FixSystem public void InitPlug(ISocket initSocket) { - //InsertSocket(initSocket); + ReturnToStartPosition(); } - public void Update() - { - //_cableSystem.PhysicCableRef.physicLine.UpdateEndPoint(this.transform); - _cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform); - } /// /// 插入某个socket @@ -129,11 +128,17 @@ namespace AibisDream.FixSystem // 开启拖拽 _isDragging = true; + // 进行插拔动作 if (_cableSystem.curSocket != null) PullUpSocket(); // 调整插头形状 AdjustPlugPos(); + + // 关闭 PhysicCable 的更新,并显示 Cable 的 LineRenderer + _cableSystem.PhysicCableRef.GetComponent().enabled = false; + _isPhysicCableActive = false; + _cableSystem.CableRef.GetComponent().enabled = true; } private void OnPointerUp(BaseEventData eventData) @@ -149,19 +154,51 @@ namespace AibisDream.FixSystem } else { - // 没找到就插回初始Socket,需要播动画 - // transform.DOMove(_cableSystem.InitSocket.GetSocketPos(), 0.1f).OnComplete(() => - // { - // InsertSocket(_cableSystem.InitSocket); - // }); + // 没找到就插回初始位置 + ReturnToStartPosition(); } } + public void ReturnToStartPosition() + { + transform.DOMove(_startPos, 0.1f).OnComplete(() => + { + SwitchToPhysicCableState(); + }); + } + private void AdjustPlugPos() { transform.position += _pickupOffset; transform.rotation = _pickupRotationOffset; } + private void PlugPosBack() + { + transform.position -= _pickupOffset; + transform.rotation = initRotation; + } + private void SwitchToPhysicCableState() + { + + // 隐藏 Cable 的 LineRenderer + PlugPosBack(); + _cableSystem.PhysicCableRef.Init(transform.position); + _cableSystem.CableRef.GetComponent().enabled = false; + // 激活 PhysicCable + _cableSystem.PhysicCableRef.GetComponent().enabled = true; + _isPhysicCableActive = true; + + } + + + + private void Update() + { + if (_isPhysicCableActive) + { + _cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform); + } + } void OnDrawGizmosSelected() {