Skip to content

Commit 5ae1ba8

Browse files
committed
WIP adding old functionality in extra script and adjusting old script to work with UI toolkit
1 parent 42baf89 commit 5ae1ba8

File tree

8 files changed

+199
-39
lines changed

8 files changed

+199
-39
lines changed

Assets/Prefabs/UI/SettingsPanelCanvas.prefab

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ MonoBehaviour:
9090
m_OnClick:
9191
m_PersistentCalls:
9292
m_Calls:
93-
- m_Target: {fileID: 294265330276786214}
93+
- m_Target: {fileID: 0}
9494
m_TargetAssemblyTypeName: BossRoom.Visual.UISettingsCanvas, BossRoom.Client
9595
m_MethodName: OnClickSettingsButton
9696
m_Mode: 1
@@ -144,7 +144,7 @@ GameObject:
144144
- component: {fileID: 294265330276786216}
145145
- component: {fileID: 294265330276786219}
146146
- component: {fileID: 294265330276786218}
147-
- component: {fileID: 294265330276786214}
147+
- component: {fileID: 6740915811087831969}
148148
m_Layer: 5
149149
m_Name: SettingsPanelCanvas
150150
m_TagString: Untagged
@@ -238,7 +238,7 @@ MonoBehaviour:
238238
m_BlockingMask:
239239
serializedVersion: 2
240240
m_Bits: 4294967295
241-
--- !u!114 &294265330276786214
241+
--- !u!114 &6740915811087831969
242242
MonoBehaviour:
243243
m_ObjectHideFlags: 0
244244
m_CorrespondingSourceObject: {fileID: 0}
@@ -247,7 +247,7 @@ MonoBehaviour:
247247
m_GameObject: {fileID: 294265330276786221}
248248
m_Enabled: 1
249249
m_EditorHideFlags: 0
250-
m_Script: {fileID: 11500000, guid: 190bc18b6f6f06340acb887d88806593, type: 3}
250+
m_Script: {fileID: 11500000, guid: 0b86c208fa760224e852eef9dfe1f4f1, type: 3}
251251
m_Name:
252252
m_EditorClassIdentifier:
253253
m_SettingsPanelRoot: {fileID: 6417648243838381817}
@@ -1676,7 +1676,7 @@ MonoBehaviour:
16761676
m_OnClick:
16771677
m_PersistentCalls:
16781678
m_Calls:
1679-
- m_Target: {fileID: 294265330276786214}
1679+
- m_Target: {fileID: 0}
16801680
m_TargetAssemblyTypeName: Unity.Multiplayer.Samples.BossRoom.Visual.UISettingsCanvas,
16811681
Unity.Multiplayer.Samples.BossRoom.Client
16821682
m_MethodName: OnClickQuitButton

Assets/Prefabs/UI/UIToolkit/UIDocumentSettingsPanel.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ MonoBehaviour:
4747
m_PanelSettings: {fileID: 11400000, guid: 30704bc49d34869449e8bfdb3ab57841, type: 2}
4848
m_ParentUI: {fileID: 0}
4949
sourceAsset: {fileID: 9197481963319205126, guid: b3d4e0fc4dc0779409b489ef4872ba77, type: 3}
50-
m_SortingOrder: 2.67
50+
m_SortingOrder: 2
5151
m_WorldSpaceSizeMode: 1
5252
m_WorldSpaceWidth: 1920
5353
m_WorldSpaceHeight: 1080

Assets/Prefabs/UI/UIToolkit/USS/SettingsPanelCanvas.uss

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
height: 100px;
2828
}
2929

30-
.settingsLabel {
31-
-unity-font-definition: url("project://database/Library/unity%20default%20resources?fileID=10102&guid=0000000000000000e000000000000000&type=0#LegacyRuntime");
32-
-unity-font-style: bold-and-italic;
33-
color: rgb(235, 209, 63);
34-
font-size: 50px;
35-
-unity-text-align: upper-center;
36-
}
37-
3830
.slider .unity-base-slider__dragger {
3931
background-color: rgb(253, 247, 2);
4032
border-radius: 6px;
@@ -64,10 +56,66 @@
6456
-unity-text-align: upper-left;
6557
border-radius: 8px;
6658
font-size: 20px;
59+
margin-bottom: 10px;
60+
margin-top: 4px;
61+
padding-top: 3px;
62+
}
63+
64+
.label {
65+
-unity-font-definition: url("project://database/Library/unity%20default%20resources?fileID=10102&guid=0000000000000000e000000000000000&type=0#LegacyRuntime");
66+
-unity-font-style: bold-and-italic;
67+
color: rgb(235, 209, 63);
68+
font-size: 40px;
69+
-unity-text-align: upper-center;
70+
margin-bottom: 32px;
71+
margin-top: 30px;
6772
}
6873

6974
.unity-base-slider__fill {
7075
background-color: rgb(222, 198, 60);
7176
border-bottom-left-radius: 4px;
7277
border-top-left-radius: 4px;
7378
}
79+
80+
.menuButton {
81+
background-image: url("project://database/Assets/Textures/UI/ui_btn_blank.png?fileID=2800000&guid=41948b4cc6087644b983dce55b466d50&type=3#ui_btn_blank");
82+
background-size: 408px 90px;
83+
-unity-font-definition: url("project://database/Assets/TextMesh%20Pro/Fonts/Bungee-Regular.ttf?fileID=12800000&guid=b8a509d3b3ce60847bbafb5a38462ecf&type=3#Bungee-Regular");
84+
color: rgb(247, 213, 32);
85+
width: 374px;
86+
height: 90px;
87+
align-self: center;
88+
font-size: 44px;
89+
border-top-width: 0;
90+
border-right-width: 0;
91+
border-bottom-width: 0;
92+
border-left-width: 0;
93+
margin-bottom: 30px;
94+
}
95+
96+
.panel {
97+
background-image: url("project://database/Assets/Textures/UI/ui_dialog.png?fileID=2800000&guid=222f76e9081efb6428be38c0e10f7bde&type=3#ui_dialog");
98+
-unity-background-image-tint-color: rgba(255, 255, 255, 0.75);
99+
background-size: 100% 100%;
100+
width: 420px;
101+
height: 376px;
102+
position: absolute;
103+
top: -156px;
104+
right: 111px;
105+
}
106+
107+
.menuButton {
108+
background-image: url("project://database/Assets/Textures/UI/ui_btn_blank.png?fileID=2800000&guid=41948b4cc6087644b983dce55b466d50&type=3#ui_btn_blank");
109+
background-size: 435px 75px;
110+
-unity-font-definition: url("project://database/Assets/TextMesh%20Pro/Fonts/Bungee-Regular.ttf?fileID=12800000&guid=b8a509d3b3ce60847bbafb5a38462ecf&type=3#Bungee-Regular");
111+
color: rgb(247, 213, 32);
112+
width: 320px;
113+
height: 65px;
114+
align-self: center;
115+
font-size: 44px;
116+
margin-top: 10px;
117+
border-top-width: 0;
118+
border-right-width: 0;
119+
border-bottom-width: 0;
120+
border-left-width: 0;
121+
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
22
<Style src="project://database/Assets/Prefabs/UI/UIToolkit/USS/SettingsPanelCanvas.uss?fileID=7433441132597879392&amp;guid=d5e6eac383531594b983eb9318a78a8a&amp;type=3#SettingsPanelCanvas" />
3+
<engine:VisualElement name="buttonRoot" style="height: 161px; width: 118px; align-items: center; transform-origin: right top; right: -90%; top: 0;">
4+
<engine:Button name="quitButton" class="simpleButton ExitButton" style="background-size: 70% 70%; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
5+
<engine:Button name="settingsButton" class="simpleButton settingsButton" style="background-size: 70% 70%; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
6+
</engine:VisualElement>
37
<engine:VisualElement name="root" style="flex-grow: 1;">
4-
<engine:VisualElement name="settingsPanelRoot" style="background-image: url(&quot;project://database/Assets/Textures/UI/ui_dialog.png?fileID=2800000&amp;guid=222f76e9081efb6428be38c0e10f7bde&amp;type=3#ui_dialog&quot;); -unity-background-image-tint-color: rgba(255, 255, 255, 0.75); background-size: 100% 100%;">
5-
<engine:Label text="Settings" name="settingsLabel" class="settingsLabel" style="margin-bottom: 8px;" />
6-
<engine:Button name="closeButton" class="ExitButton" style="position: absolute; top: -10px; right: -10px;" />
8+
<engine:VisualElement name="settingsPanelRoot" class="panel">
9+
<engine:Button name="closeButton" class="ExitButton" style="position: absolute; top: -10px; right: -64px; background-size: 90% 90%; visibility: visible; overflow: visible;" />
10+
<engine:Label text="Settings" name="settingsLabel" class="settingsLabel label" style="margin-bottom: 8px;" />
711
<engine:Label text="Overall Volume" name="masterVolumeLabel" class="slider" style="translate: 7.5% 50%; transform-origin: center 40%;" />
812
<engine:Slider high-value="100" name="masterVolume" fill="true" show-input-field="false" enabled="true" inverted="false" value="50" class="slider" style="-unity-background-image-tint-color: rgba(255, 4, 4, 0.96); width: 85%; translate: 7.5% 0; border-top-left-radius: 8px; border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px;" />
913
<engine:Label text="Music Volume" name="musicVolumeLabel" class="slider" style="translate: 7.5% 50%; transform-origin: center 40%;" />
1014
<engine:Slider high-value="100" name="musicVolume" enabled="true" show-input-field="false" fill="true" low-value="0" value="50" class="slider" style="width: 85%; translate: 7.5% 0;" />
11-
<engine:Button text="Low" name="settingPanelButton" style="background-image: url(&quot;project://database/Assets/Textures/UI/ui_btn_blank.png?fileID=2800000&amp;guid=41948b4cc6087644b983dce55b466d50&amp;type=3#ui_btn_blank&quot;); background-size: 408px 90px; -unity-font-definition: url(&quot;project://database/Assets/TextMesh%20Pro/Fonts/Bungee-Regular.ttf?fileID=12800000&amp;guid=b8a509d3b3ce60847bbafb5a38462ecf&amp;type=3#Bungee-Regular&quot;); color: rgb(247, 213, 32); width: 407px; height: 90px; align-self: center; font-size: 44px; margin-top: 10px; border-top-width: 0; border-right-width: 0; border-bottom-width: 0; border-left-width: 0;" />
15+
<engine:Button text="Low" name="settingPanelButton" class="menuButton" style="margin-top: 25px; background-size: 321px 65px;" />
16+
</engine:VisualElement>
17+
<engine:VisualElement name="quitPanelRoot" class="panel" style="flex-grow: 1; transform-origin: center;">
18+
<engine:Label text="Return To Menu?" name="returnLabel" class="settingsLabel label" />
19+
<engine:Button text="Confirm" name="confirmButton" class="menuButton" style="margin-top: 30px; background-size: 321px 65px;" />
20+
<engine:Button text="Cancel" name="cancelButton" class="menuButton" style="background-size: 321px 65px;" />
1221
</engine:VisualElement>
13-
<engine:VisualElement name="quitPanelRoot" style="flex-grow: 1;" />
14-
</engine:VisualElement>
15-
<engine:VisualElement name="buttonRoot" style="height: 161px; width: 118px; align-items: center; transform-origin: right top; right: -90%; top: 0;">
16-
<engine:Button name="quitButton" class="simpleButton ExitButton" style="background-size: 70% 70%; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
17-
<engine:Button name="settingsButton" class="simpleButton settingsButton" style="background-size: 70% 70%; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
1822
</engine:VisualElement>
1923
</engine:UXML>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace Unity.BossRoom.Gameplay.UI
5+
{
6+
/// <summary>
7+
/// Controls the special Canvas that has the settings icon and the settings window.
8+
/// The window itself is controlled by UISettingsPanel; the button is controlled here.
9+
/// </summary>
10+
public class OldUISettingsCanvas : MonoBehaviour { [SerializeField] private GameObject m_SettingsPanelRoot;
11+
12+
[SerializeField]
13+
GameObject m_QuitPanelRoot;
14+
15+
void Awake()
16+
{
17+
// hide the settings window at startup (this is just to handle the common case where an artist forgets to disable the window in the prefab)
18+
DisablePanels();
19+
}
20+
21+
void DisablePanels()
22+
{
23+
m_SettingsPanelRoot.SetActive(false);
24+
m_QuitPanelRoot.SetActive(false);
25+
}
26+
27+
/// <summary>
28+
/// Called directly by the settings button in the UI prefab
29+
/// </summary>
30+
public void OnClickSettingsButton()
31+
{
32+
m_SettingsPanelRoot.SetActive(!m_SettingsPanelRoot.activeSelf);
33+
m_QuitPanelRoot.SetActive(false);
34+
}
35+
36+
/// <summary>
37+
/// Called directly by the quit button in the UI prefab
38+
/// </summary>
39+
public void OnClickQuitButton()
40+
{
41+
m_QuitPanelRoot.SetActive(!m_QuitPanelRoot.activeSelf);
42+
m_SettingsPanelRoot.SetActive(false);
43+
}
44+
}
45+
}

Assets/Scripts/Gameplay/UI/OldUISettingsCanvas.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: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,110 @@
1-
using System;
21
using UnityEngine;
2+
using UnityEngine.UIElements;
3+
using Unity.BossRoom.Utils;
4+
using Unity.BossRoom.Audio;
35

46
namespace Unity.BossRoom.Gameplay.UI
57
{
68
/// <summary>
7-
/// Controls the special Canvas that has the settings icon and the settings window.
8-
/// The window itself is controlled by UISettingsPanel; the button is controlled here.
9+
/// Controls the special Canvas that has the settings icons and the settings window.
10+
/// The window itself is controlled by UISettingsPanel; the buttons are controlled here.
911
/// </summary>
1012
public class UISettingsCanvas : MonoBehaviour
1113
{
1214
[SerializeField]
13-
private GameObject m_SettingsPanelRoot;
15+
UIDocument uiDocument; // Reference to the UIDocument asset
1416

15-
[SerializeField]
16-
private GameObject m_QuitPanelRoot;
17+
VisualElement settingsPanelRoot;
18+
VisualElement quitPanelRoot;
19+
Button settingsButton;
20+
Button quitButton;
21+
Slider masterVolumeSlider;
22+
Slider musicVolumeSlider;
1723

1824
void Awake()
1925
{
20-
// hide the settings window at startup (this is just to handle the common case where an artist forgets to disable the window in the prefab)
26+
// Retrieve the root VisualElement from the UIDocument
27+
var root = uiDocument.rootVisualElement;
28+
29+
// Query the panels by their names or assigned USS classes
30+
settingsPanelRoot = root.Q<VisualElement>("settingsPanelRoot");
31+
quitPanelRoot = root.Q<VisualElement>("quitPanelRoot");
32+
quitButton = root.Q<Button>("quitButton");
33+
settingsButton = root.Q<Button>("settingsButton");
34+
masterVolumeSlider = root.Q<Slider>("masterVolume");
35+
musicVolumeSlider = root.Q<Slider>("musicVolume");
36+
37+
// Ensure panels are hidden at startup
2138
DisablePanels();
39+
40+
settingsButton.SetEnabled(true);
41+
quitButton.SetEnabled(true);
42+
// Bind the buttons to their respective method using new input system
43+
settingsButton.clicked += OnClickSettingsButton;
44+
quitButton.clicked += OnClickQuitButton;
45+
46+
// Bind the sliders to their respective methods
47+
masterVolumeSlider.value = ClientPrefs.GetMasterVolume();
48+
masterVolumeSlider.RegisterValueChangedCallback(evt => OnMasterVolumeSliderChanged(evt.newValue));
49+
musicVolumeSlider.value = ClientPrefs.GetMusicVolume();
50+
musicVolumeSlider.RegisterValueChangedCallback(evt => OnMusicVolumeSliderChanged(evt.newValue));
51+
52+
2253
}
2354

2455
void DisablePanels()
2556
{
26-
m_SettingsPanelRoot.SetActive(false);
27-
m_QuitPanelRoot.SetActive(false);
57+
settingsPanelRoot.style.display = DisplayStyle.None;
58+
quitPanelRoot.style.display = DisplayStyle.None;
2859
}
2960

3061
/// <summary>
31-
/// Called directly by the settings button in the UI prefab
62+
/// Called directly by the settings button in the UI Through a manual event binding
3263
/// </summary>
3364
public void OnClickSettingsButton()
3465
{
35-
m_SettingsPanelRoot.SetActive(!m_SettingsPanelRoot.activeSelf);
36-
m_QuitPanelRoot.SetActive(false);
66+
Debug.Log("Settings button pressed");
67+
// settingsButton is pressed
68+
if (settingsPanelRoot != null)
69+
{
70+
bool isVisible = settingsPanelRoot.style.display == DisplayStyle.Flex;
71+
settingsPanelRoot.style.display = isVisible ? DisplayStyle.None : DisplayStyle.Flex;
72+
}
73+
74+
if (quitPanelRoot != null)
75+
{
76+
quitPanelRoot.style.display = DisplayStyle.None;
77+
}
3778
}
3879

3980
/// <summary>
40-
/// Called directly by the quit button in the UI prefab
81+
/// Called directly by the quit button in the UI manual button here
4182
/// </summary>
4283
public void OnClickQuitButton()
4384
{
44-
m_QuitPanelRoot.SetActive(!m_QuitPanelRoot.activeSelf);
45-
m_SettingsPanelRoot.SetActive(false);
85+
if (quitPanelRoot != null)
86+
{
87+
bool isVisible = quitPanelRoot.style.display == DisplayStyle.Flex;
88+
quitPanelRoot.style.display = isVisible ? DisplayStyle.None : DisplayStyle.Flex;
89+
}
90+
91+
if (settingsPanelRoot != null)
92+
{
93+
settingsPanelRoot.style.display = DisplayStyle.None;
94+
}
95+
}
96+
97+
private void OnMasterVolumeSliderChanged(float newValue)
98+
{
99+
ClientPrefs.SetMasterVolume(newValue);
100+
AudioMixerConfigurator.Instance.Configure();
46101
}
47102

103+
private void OnMusicVolumeSliderChanged(float newValue)
104+
{
105+
ClientPrefs.SetMusicVolume(newValue);
106+
AudioMixerConfigurator.Instance.Configure();
107+
}
48108
}
49109
}
110+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:cd3a24fdc467d2bb584ca578f24068db6028a8ec5105ced71f2cdad96e097d43
2+
oid sha256:23f534cbf21906dcc5c2de517f2c6cc5a273e98a66d57bf3d86b5226635f57d2
33
size 27731

0 commit comments

Comments
 (0)