Skip to content

Commit ed2d78d

Browse files
committed
Add "Controls" menu.
1 parent d435ef7 commit ed2d78d

File tree

63 files changed

+373
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+373
-93
lines changed

LowLevel/Sandbox/Assets/Sandbox.unity

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,76 @@ MonoBehaviour:
471471
StartScene: Shooter
472472
DebuggingMenu: {fileID: 1603435387}
473473
ShortcutMenu: {fileID: 465066520}
474+
ControlsMenu: {fileID: 931634909}
474475
UpdatePeriodFPS: 0.1
476+
--- !u!1 &931634905
477+
GameObject:
478+
m_ObjectHideFlags: 0
479+
m_CorrespondingSourceObject: {fileID: 0}
480+
m_PrefabInstance: {fileID: 0}
481+
m_PrefabAsset: {fileID: 0}
482+
serializedVersion: 6
483+
m_Component:
484+
- component: {fileID: 931634908}
485+
- component: {fileID: 931634907}
486+
- component: {fileID: 931634909}
487+
m_Layer: 0
488+
m_Name: ControlsMenu
489+
m_TagString: Untagged
490+
m_Icon: {fileID: 0}
491+
m_NavMeshLayer: 0
492+
m_StaticEditorFlags: 0
493+
m_IsActive: 1
494+
--- !u!114 &931634907
495+
MonoBehaviour:
496+
m_ObjectHideFlags: 0
497+
m_CorrespondingSourceObject: {fileID: 0}
498+
m_PrefabInstance: {fileID: 0}
499+
m_PrefabAsset: {fileID: 0}
500+
m_GameObject: {fileID: 931634905}
501+
m_Enabled: 1
502+
m_EditorHideFlags: 0
503+
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
504+
m_Name:
505+
m_EditorClassIdentifier:
506+
m_PanelSettings: {fileID: 11400000, guid: b3cc2d097ffb6c846acc69277ba50b67, type: 2}
507+
m_ParentUI: {fileID: 0}
508+
sourceAsset: {fileID: 9197481963319205126, guid: dce047227e337534b954188459dc4903, type: 3}
509+
m_SortingOrder: 0
510+
m_Position: 0
511+
m_WorldSpaceSizeMode: 1
512+
m_WorldSpaceWidth: 1920
513+
m_WorldSpaceHeight: 1080
514+
m_PivotReferenceSize: 0
515+
m_Pivot: 0
516+
m_WorldSpaceCollider: {fileID: 0}
517+
--- !u!4 &931634908
518+
Transform:
519+
m_ObjectHideFlags: 0
520+
m_CorrespondingSourceObject: {fileID: 0}
521+
m_PrefabInstance: {fileID: 0}
522+
m_PrefabAsset: {fileID: 0}
523+
m_GameObject: {fileID: 931634905}
524+
serializedVersion: 2
525+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
526+
m_LocalPosition: {x: 0, y: 0, z: 0}
527+
m_LocalScale: {x: 1, y: 1, z: 1}
528+
m_ConstrainProportionsScale: 0
529+
m_Children: []
530+
m_Father: {fileID: 0}
531+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
532+
--- !u!114 &931634909
533+
MonoBehaviour:
534+
m_ObjectHideFlags: 0
535+
m_CorrespondingSourceObject: {fileID: 0}
536+
m_PrefabInstance: {fileID: 0}
537+
m_PrefabAsset: {fileID: 0}
538+
m_GameObject: {fileID: 931634905}
539+
m_Enabled: 1
540+
m_EditorHideFlags: 0
541+
m_Script: {fileID: 11500000, guid: b1d48707d99a69d479dfc6c5cf6e6ac8, type: 3}
542+
m_Name:
543+
m_EditorClassIdentifier: Assembly-CSharp::ControlsMenu
475544
--- !u!1 &1133641123
476545
GameObject:
477546
m_ObjectHideFlags: 0
@@ -734,3 +803,4 @@ SceneRoots:
734803
- {fileID: 633824030}
735804
- {fileID: 1603435385}
736805
- {fileID: 465066522}
806+
- {fileID: 931634908}

LowLevel/Sandbox/Assets/Sandbox/Scripts/SandboxManager.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Unity.Collections;
55
using Unity.Jobs.LowLevel.Unsafe;
66
using Unity.Mathematics;
7+
using UnityEditor;
78
using UnityEngine;
89
using UnityEngine.InputSystem;
910
using UnityEngine.LowLevelPhysics2D;
@@ -25,11 +26,13 @@ public float CameraZoom
2526
public UIDocument SceneOptionsUI { get; set; }
2627

2728
private bool ColorShapeState { get; set; }
29+
private ControlsMenu.CustomButton m_QuitButton;
2830

2931
public string StartScene = string.Empty;
3032
public Action SceneResetAction;
3133
public DebuggingMenu DebuggingMenu;
3234
public ShortcutMenu ShortcutMenu;
35+
public ControlsMenu ControlsMenu;
3336
public float UpdatePeriodFPS = 0.1f;
3437

3538
public void SetOverrideDrawOptions(PhysicsWorld.DrawOptions overridenOptions, PhysicsWorld.DrawOptions fixedOptions)
@@ -252,6 +255,10 @@ private void Start()
252255

253256
// Show the Shortcut menu by default.
254257
ShortcutMenu.gameObject.SetActive(true);
258+
259+
// Reset the controls.
260+
ControlsMenu.ResetControls();
261+
m_QuitButton = ControlsMenu.quitButton;
255262

256263
var defaultWorld = PhysicsWorld.defaultWorld;
257264
m_MenuDefaults = new MenuDefaults
@@ -290,9 +297,13 @@ private void Update()
290297
var currentKeyboard = Keyboard.current;
291298

292299
// Quit.
293-
if (currentKeyboard.escapeKey.wasPressedThisFrame)
300+
if (m_QuitButton.isPressed || currentKeyboard.escapeKey.wasPressedThisFrame)
294301
{
302+
#if UNITY_EDITOR
303+
EditorApplication.isPlaying = false;
304+
#else
295305
Application.Quit();
306+
#endif
296307
return;
297308
}
298309

@@ -305,7 +316,7 @@ private void Update()
305316
if (m_ShowDebuggingElement.value)
306317
DebuggingMenu.gameObject.SetActive(m_ShowUI);
307318

308-
// Toggle Shortcut Men.
319+
// Toggle Shortcut Menu.
309320
ShortcutMenu.gameObject.SetActive(!ShortcutMenu.gameObject.activeInHierarchy);
310321

311322
// Main Menu.
@@ -700,6 +711,9 @@ private void TreeSelectionChanged()
700711
DebuggingMenu.ResetStats();
701712
m_CameraManipulator.OverlapUI = 0;
702713

714+
// Reset the controls.
715+
ControlsMenu.ResetControls();
716+
703717
SceneOptionsUI = null;
704718
SceneResetAction = null;
705719
m_SceneManifest.LoadScene(sceneName, ResetSceneState);

LowLevel/Sandbox/Assets/Sandbox/UI/ControlsMenu.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEngine.UIElements;
4+
5+
public class ControlsMenu : MonoBehaviour
6+
{
7+
public sealed class CustomButton
8+
{
9+
public CustomButton(Button button)
10+
{
11+
this.button = button;
12+
isPressed = false;
13+
14+
button.RegisterCallback<PointerDownEvent>(ButtonPointerDown, TrickleDown.TrickleDown);
15+
button.RegisterCallback<PointerUpEvent>(ButtonPointerUp, TrickleDown.TrickleDown);
16+
}
17+
18+
public void Set(string label)
19+
{
20+
button.text = label;
21+
button.style.display = DisplayStyle.Flex;
22+
}
23+
24+
public void Reset()
25+
{
26+
button.UnregisterCallback<PointerDownEvent>(ButtonPointerDown, TrickleDown.TrickleDown);
27+
button.UnregisterCallback<PointerUpEvent>(ButtonPointerUp, TrickleDown.TrickleDown);
28+
}
29+
30+
private void ButtonPointerDown(PointerDownEvent evt) => isPressed = true;
31+
private void ButtonPointerUp(PointerUpEvent evt) => isPressed = false;
32+
33+
public Button button { get; }
34+
public bool isPressed { get; set; }
35+
}
36+
37+
public CustomButton quitButton { get; private set; }
38+
39+
public CustomButton this[int index]
40+
{
41+
get
42+
{
43+
if (index < 0 || index >= m_CustomButtons.Length)
44+
throw new ArgumentOutOfRangeException(nameof(index));
45+
46+
return m_CustomButtons[index];
47+
}
48+
private set
49+
{
50+
if (index < 0 || index >= m_CustomButtons.Length)
51+
throw new ArgumentOutOfRangeException(nameof(index));
52+
53+
m_CustomButtons[index] = value;
54+
}
55+
}
56+
57+
private CameraManipulator m_CameraManipulator;
58+
private UIDocument m_UIDocument;
59+
private readonly CustomButton[] m_CustomButtons = new CustomButton[3];
60+
61+
private void OnEnable()
62+
{
63+
m_CameraManipulator = FindFirstObjectByType<CameraManipulator>();
64+
m_UIDocument = GetComponent<UIDocument>();
65+
var root = m_UIDocument.rootVisualElement;
66+
67+
// Menu Region.
68+
{
69+
var menuRegion = root.Q<VisualElement>("menu-region");
70+
menuRegion.RegisterCallback<PointerEnterEvent>(_ => ++m_CameraManipulator.OverlapUI);
71+
menuRegion.RegisterCallback<PointerLeaveEvent>(_ => --m_CameraManipulator.OverlapUI);
72+
}
73+
74+
// Buttons.
75+
{
76+
this[0] = new CustomButton(root.Q<Button>("button0"));
77+
this[1] = new CustomButton(root.Q<Button>("button1"));
78+
this[2] = new CustomButton(root.Q<Button>("button2"));
79+
80+
quitButton = new CustomButton(root.Q<Button>("quit"));
81+
82+
ResetControls();
83+
}
84+
}
85+
86+
private void OnDisable()
87+
{
88+
quitButton.Reset();
89+
90+
foreach (var button in m_CustomButtons)
91+
button.Reset();
92+
}
93+
94+
public void ResetControls()
95+
{
96+
foreach (var customButton in m_CustomButtons)
97+
{
98+
// Reset the button.
99+
customButton.button.text = "...";
100+
customButton.button.style.display = DisplayStyle.None;
101+
customButton.isPressed = false;
102+
}
103+
}
104+
}

LowLevel/Sandbox/Assets/Sandbox/UI/ControlsMenu/ControlsMenu.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
2+
<Style src="project://database/Assets/Sandbox/UI/Styling/SandboxStyleOverrides.uss?fileID=7433441132597879392&amp;guid=e140b35909eadcf48959626f553b2145&amp;type=3#SandboxStyleOverrides"/>
3+
<ui:VisualElement name="VisualElement" picking-mode="Ignore" style="width: 100%; height: 100%; align-items: flex-start; justify-content: flex-end; align-content: auto; padding-right: 8px; padding-bottom: 8px;">
4+
<ui:VisualElement name="menu-region" style="margin-top: 0; margin-right: 0; margin-bottom: 2px; margin-left: 0; align-items: auto; align-self: center; align-content: flex-end; width: auto; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; height: 6%; justify-content: center;">
5+
<ui:VisualElement name="controls" style="flex-grow: 1; flex-shrink: 0; color: rgba(210, 210, 210, 0.5); -unity-text-align: middle-left; align-self: stretch; padding-top: 3px; padding-left: 2px; padding-right: 2px; padding-bottom: 3px; flex-direction: row;">
6+
<ui:Button text="..." name="button0" enabled="true" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" enable-rich-text="false" emoji-fallback-support="false" focusable="false"/>
7+
<ui:Button text="..." name="button1" emoji-fallback-support="false" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" enable-rich-text="false" focusable="false"/>
8+
<ui:Button text="..." name="button2" enable-rich-text="false" emoji-fallback-support="false" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" focusable="false"/>
9+
<ui:Button text="Quit" name="quit" enable-rich-text="false" emoji-fallback-support="false" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" focusable="false"/>
10+
</ui:VisualElement>
11+
</ui:VisualElement>
12+
</ui:VisualElement>
13+
</ui:UXML>

LowLevel/Sandbox/Assets/Sandbox/UI/ControlsMenu/ControlsMenu.uxml.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LowLevel/Sandbox/Assets/Sandbox/UI/DebuggingMenu/DebuggingMenu.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
2-
<Style src="project://database/Assets/Sandbox/UI/Common/SandboxStyleOverrides.uss?fileID=7433441132597879392&amp;guid=e140b35909eadcf48959626f553b2145&amp;type=3#SandboxStyleOverrides"/>
2+
<Style src="project://database/Assets/Sandbox/UI/Styling/SandboxStyleOverrides.uss?fileID=7433441132597879392&amp;guid=e140b35909eadcf48959626f553b2145&amp;type=3#SandboxStyleOverrides"/>
33
<ui:VisualElement name="VisualElement" picking-mode="Ignore" style="width: 100%; height: 100%; align-items: auto; margin-right: 0; padding-right: 8px; padding-top: 8px;">
44
<ui:VisualElement name="menu-region" style="width: auto; height: auto; margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; align-items: auto; align-self: flex-end;">
55
<ui:TabView tabindex="0" style="width: 100%; height: 100%;">

LowLevel/Sandbox/Assets/Sandbox/UI/MainMenu/MainMenu.uxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
2-
<Style src="project://database/Assets/Sandbox/UI/Common/SandboxStyleOverrides.uss?fileID=7433441132597879392&amp;guid=e140b35909eadcf48959626f553b2145&amp;type=3#SandboxStyleOverrides"/>
2+
<Style src="project://database/Assets/Sandbox/UI/Styling/SandboxStyleOverrides.uss?fileID=7433441132597879392&amp;guid=e140b35909eadcf48959626f553b2145&amp;type=3#SandboxStyleOverrides"/>
33
<ui:VisualElement name="VisualElement" picking-mode="Ignore" style="width: 100%; height: 100%; align-items: flex-start; padding-left: 8px; padding-top: 8px;">
44
<ui:VisualElement name="menu-region" style="width: auto; height: auto; margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; align-items: auto;">
55
<ui:TabView tabindex="0" name="selected-tab" style="width: 100%; height: 100%;">
66
<ui:Tab label="Scenes" tabindex="0" name="Tab">
77
<ui:TreeView name="scenes" virtualization-method="DynamicHeight" focusable="false"/>
88
</ui:Tab>
9-
<ui:Tab label="World2D" name="Tab" tabindex="1">
9+
<ui:Tab label="World" name="Tab" tabindex="1">
1010
<ui:VisualElement name="world">
1111
<ui:SliderInt label="Workers" value="64" high-value="64" show-input-field="true" name="workers" fill="true"/>
1212
<ui:SliderInt label="Sub-steps" value="4" high-value="64" show-input-field="true" low-value="1" inverted="false" name="sub-steps" focusable="false" fill="true"/>

LowLevel/Sandbox/Assets/Sandbox/UI/ShortcutsMenu/ShortcutMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private void OnEnable()
2424
const string color = "<color=#7FFFD4>";
2525
const string endColor = "</color>";
2626

27-
var sceneDescription = root.Q<Label>("scene-description");
27+
var sceneDescription = root.Q<Label>("shortcuts-description");
2828
sceneDescription.text =
2929
$"[{color}P{endColor}]\t\tPause/Continue\n" +
3030
$"[{color}S{endColor}]\t\tSingle Step\n" +

0 commit comments

Comments
 (0)