Skip to content

Commit

Permalink
Add battery input display
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Dec 9, 2023
1 parent f4fb7ed commit 38ac53f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions Assets/Scripts/SS3D/Systems/Electricity/SmesBattery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private void HandleUpdate(ref EventContext context, in UpdateEvent updateEvent)
{
AdjustBatteryLevel();
AdjustBatteryOutput();
AdjustBatteryInput();
_previousPowerStored = StoredPower;
}


Expand All @@ -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;
Expand All @@ -80,13 +91,11 @@ private void AdjustBatteryOutput()
{
SmesSkinnedMesh.SetBlendShapeWeight(_currentLightOutput, 0);
_currentLightOutput -= 1;
}


}
}

/// <summary>
/// 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.
/// </summary>
private void ComputeLightOutputTarget()
{
Expand Down

0 comments on commit 38ac53f

Please sign in to comment.