-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,7 @@ Label { | |
margin-bottom: 0; | ||
margin-top: 0; | ||
} | ||
|
||
#Speed > Button { | ||
background-color: rgba(53, 59, 72, 255); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
Evacuation Simulation/Assets/Scripts/JMTools/Extensions/UIToolkit Extensions.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,19 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine.UIElements; | ||
|
||
namespace JMTools | ||
{ | ||
#nullable enable | ||
public static class UIToolkitExtensions | ||
{ | ||
public static void AddRange(this VisualElement parent, IEnumerable<VisualElement?> children) | ||
{ | ||
foreach (var child in children) | ||
{ | ||
parent.Add(child); | ||
} | ||
} | ||
|
||
public static void AddRange(this VisualElement parent, params VisualElement?[] childrenParams) => AddRange(parent, children: childrenParams); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Evacuation Simulation/Assets/Scripts/JMTools/Extensions/UIToolkit Extensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
Evacuation Simulation/Assets/Scripts/UI/Controllers/TimeScaleController.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,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Globalization; | ||
using System.Linq; | ||
using JMTools; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace PedestrianSimulation.UI | ||
{ | ||
[RequireComponent(typeof(UIDocument))] | ||
public class TimeScaleController : MonoBehaviour | ||
{ | ||
|
||
private VisualElement element; | ||
private void Start() | ||
{ | ||
var uiDocument = GetComponent<UIDocument>(); | ||
var rootVisualElement = uiDocument.rootVisualElement; | ||
|
||
element = rootVisualElement.Q("speed"); | ||
|
||
element.AddRange(GenerateSpeedControls(1,2,4)); | ||
} | ||
|
||
|
||
private static List<VisualElement> GenerateSpeedControls(params float[] speedParams) => GenerateSpeedControls(speeds: speedParams); | ||
private static List<VisualElement> GenerateSpeedControls(IEnumerable<float> speeds) | ||
{ | ||
var elements = new List<VisualElement>(); | ||
|
||
foreach (float speed in speeds) | ||
{ | ||
var button = new Button(() => | ||
{ | ||
SetTimeScale(speed); | ||
}) | ||
{ | ||
text = $"{speed}", | ||
}; | ||
|
||
elements.Add(button); | ||
} | ||
|
||
return elements; | ||
} | ||
|
||
private static void SetTimeScale(float value) => Time.timeScale = value; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Evacuation Simulation/Assets/Scripts/UI/Controllers/TimeScaleController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.