From 38ac53f58c3693d4c1520ac13aa567a45f672ce0 Mon Sep 17 00:00:00 2001 From: stilnat Date: Sat, 9 Dec 2023 01:02:24 +0100 Subject: [PATCH] Add battery input display --- .../Machines/Engineering/SMES.prefab | 4 ++- .../SS3D/Systems/Electricity/SmesBattery.cs | 27 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Assets/Content/WorldObjects/Furniture/Machines/Engineering/SMES.prefab b/Assets/Content/WorldObjects/Furniture/Machines/Engineering/SMES.prefab index 35a01b2115..9ac419f076 100644 --- a/Assets/Content/WorldObjects/Furniture/Machines/Engineering/SMES.prefab +++ b/Assets/Content/WorldObjects/Furniture/Machines/Engineering/SMES.prefab @@ -84,9 +84,11 @@ MonoBehaviour: _componentIndexCache: 0 _addedNetworkObject: {fileID: -5414623717715724467} _networkObjectCache: {fileID: -5414623717715724467} - _maxCapacity: 1000 + _maxCapacity: 10000 _storedPower: 0 + _maxPowerRate: 5 SmesSkinnedMesh: {fileID: 755838239801065349} + _updateLightPeriod: 25 --- !u!114 &4642179228716895328 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs b/Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs index 70f6e4630b..7426e1639d 100644 --- a/Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs +++ b/Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs @@ -39,6 +39,8 @@ private void HandleUpdate(ref EventContext context, in UpdateEvent updateEvent) { AdjustBatteryLevel(); AdjustBatteryOutput(); + AdjustBatteryInput(); + _previousPowerStored = StoredPower; } @@ -58,19 +60,28 @@ private void AdjustBatteryLevel() } } + private void AdjustBatteryInput() + { + float powerAdded = Mathf.Max(StoredPower - _previousPowerStored, 0f); + + if(powerAdded > 0f) + { + SmesSkinnedMesh.SetBlendShapeWeight(11, 100f); + } + else + { + SmesSkinnedMesh.SetBlendShapeWeight(0, 100f); + } + } + private void AdjustBatteryOutput() { ComputeLightOutputTarget(); - _previousPowerStored = StoredPower; - _updateCount++; if (_updateCount != _updateLightPeriod) return; _updateCount = 0; - Debug.Log("target = " + _lightOutputTarget); - Debug.Log("current = " + _currentLightOutput); - if (_currentLightOutput < _lightOutputTarget) { _currentLightOutput += 1; @@ -80,13 +91,11 @@ private void AdjustBatteryOutput() { SmesSkinnedMesh.SetBlendShapeWeight(_currentLightOutput, 0); _currentLightOutput -= 1; - } - - + } } /// - /// Index of the light that should be turned on. + /// Index of the light that should be turned on. Can be 0 and in that case no light should be on. /// private void ComputeLightOutputTarget() {