-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bargraph functionality is implemented
- Loading branch information
Showing
4 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Assets/MirageXR/Player/Prefabs/eROBSON/Scripts/BargraphController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using UnityEngine; | ||
|
||
public class BargraphController : MonoBehaviour | ||
{ | ||
[SerializeField] private Renderer[] lightRenderers; | ||
[SerializeField] private Material onMaterial; | ||
[SerializeField] private Material offMaterial; | ||
|
||
|
||
/// <summary> | ||
/// turn on the bargraph light depends on the power | ||
/// </summary> | ||
/// <param name="status">is connected or not</param> | ||
/// <param name="power">the power received to this bit</param> | ||
public void TurnOnLights(bool status, float power) | ||
{ | ||
// Turn off all lights first | ||
TurnOffAllLights(); | ||
|
||
//bit is disconnected | ||
if (!status) | ||
{ | ||
return; | ||
} | ||
|
||
// Determine how many lights to turn on based on the power level | ||
var lightsToTurnOn = power switch | ||
{ | ||
> 0f and <= 0.2f => 1, | ||
> 0.2f and <= 0.4f => 2, | ||
> 0.4f and <= 0.6f => 3, | ||
> 0.6f and <= 0.8f => 4, | ||
> 0.8f and <= 1.0f => 5, | ||
_ => 0 | ||
}; | ||
|
||
// Turn on the appropriate number of lights | ||
for (var i = 0; i < lightsToTurnOn; i++) | ||
{ | ||
lightRenderers[i].material = onMaterial; | ||
} | ||
} | ||
|
||
|
||
private void Start() | ||
{ | ||
TurnOffAllLights(); | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// Turn off all lights first | ||
/// </summary> | ||
private void TurnOffAllLights() | ||
{ | ||
foreach (var led in lightRenderers) | ||
{ | ||
led.material = offMaterial; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/MirageXR/Player/Prefabs/eROBSON/Scripts/BargraphController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters