Skip to content

Commit

Permalink
add a ui with speed/play/pause/reset controls
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBuhler committed Jun 20, 2020
1 parent 0c6d722 commit 488473c
Show file tree
Hide file tree
Showing 2 changed files with 1,308 additions and 1 deletion.
47 changes: 47 additions & 0 deletions UI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

using UnityEngine;
using UnityEngine.UI;

public class UI : MonoBehaviour {

public Text generateButton;
public Text playButton;
public Text speed;
public Text step;

private void Update () {
speed.text = State.STEPS_PER_SECOND.ToString();
step.text = "Step: " + Simulation.CURRENT_STEP.ToString();
}

public void FasterButtonClicked () {
State.STEPS_PER_SECOND = Mathf.Clamp(++State.STEPS_PER_SECOND, 1, 30);
}

public void GenerateButtonClicked () {
generateButton.text = "Generate";
playButton.text = "Play";
State.PAUSED = true;
Simulation.Init();
Simulation.Render();
}

public void PlayButtonClicked () {
generateButton.text = "Reset";
if ( State.PAUSED ) {
State.PAUSED = false;
playButton.text = "Pause";
State.DELTA_TIME = 0;
Simulation.Step();
Simulation.Render();
} else {
State.PAUSED = true;
playButton.text = "Play";
}
}

public void SlowerButtonClicked () {
State.STEPS_PER_SECOND = Mathf.Clamp(--State.STEPS_PER_SECOND, 1, 30);
}

}
Loading

0 comments on commit 488473c

Please sign in to comment.