-
Notifications
You must be signed in to change notification settings - Fork 136
Feat: Multiplayer Use Cases UI toolkit implementation [MTT-7497] #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Elfi0Kuhndorf
merged 21 commits into
develop
from
feat/multiplayer-use-cases-ui-toolkit-implementation
Jul 1, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b0fd6d5
first draft of UIToolkit
Elfi0Kuhndorf 4dc0326
WIP adjusting NetworkManagerUI with UI toolkit and starting to connec…
Elfi0Kuhndorf cf5cffc
moving UI Toolkit related files into UI toolkit folder, also NetworkM…
Elfi0Kuhndorf 313f90f
deleting old UI from scenes and adjusting NetworkManagerUI.cs to make…
Elfi0Kuhndorf dc99897
Merge branch 'develop' into feat/multiplayer-use-cases-ui-toolkit-imp…
Elfi0Kuhndorf 9c92673
removed some redundant assets and code in NetworkManagerUI.cs
Elfi0Kuhndorf 307c832
revert scene and NetworkManagerUI prefab changes
Elfi0Kuhndorf 62a9924
fix NetworkManagerUI.prefab and fix style classes
Elfi0Kuhndorf e03b3e1
add SetNetworkPortAndAddress back to StartClient function
Elfi0Kuhndorf 352d5cd
removed unneeded UIElementsSchema
Elfi0Kuhndorf ac01dca
simplify code in NetworkManagerUI.cs and include UIElementsUtils
Elfi0Kuhndorf c2c1a3a
make the UI some percentage bit smaller (adjusting the uxml sheet of …
Elfi0Kuhndorf a6dbfc5
utilizing UIElementsUtils for simplifying code, (WIP) trying to highl…
Elfi0Kuhndorf e2e960a
added highlights for buttons, fixed serverOverlay (adjusting size), a…
Elfi0Kuhndorf 9ae7d23
WIP adjusting script to use old method for highlighting and disabling
Elfi0Kuhndorf 91c8087
WIP hovering does still not work
Elfi0Kuhndorf 925ff8a
fix: added validation of IP and port address
Elfi0Kuhndorf 82a8ed4
fix: color changes through button interactions work now
Elfi0Kuhndorf b979ee9
fix: added Styleclasses instead of color fields to implement color ch…
Elfi0Kuhndorf ac4bf2d
fix: scaling of UI changes depending on screen size
Elfi0Kuhndorf 2c9ff06
Merge branch 'develop' into feat/multiplayer-use-cases-ui-toolkit-imp…
Elfi0Kuhndorf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,875 changes: 46 additions & 1,829 deletions
1,875
Experimental/MultiplayerUseCases/Assets/Common/Prefabs/NetworkManagerUI.prefab
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
Experimental/MultiplayerUseCases/Assets/Common/Prefabs/NetworkManagerUI_Toolkit.prefab
This file contains hidden or 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,50 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1 &6992812452127128618 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| serializedVersion: 6 | ||
| m_Component: | ||
| - component: {fileID: 4183923682644896075} | ||
| - component: {fileID: 4429985340320126427} | ||
| m_Layer: 0 | ||
| m_Name: NetworkManagerUI_Toolkit | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &4183923682644896075 | ||
| Transform: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 6992812452127128618} | ||
| serializedVersion: 2 | ||
| m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | ||
| m_LocalPosition: {x: 0, y: 0, z: 0} | ||
| m_LocalScale: {x: 1, y: 1, z: 1} | ||
| m_ConstrainProportionsScale: 0 | ||
| m_Children: [] | ||
| m_Father: {fileID: 0} | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!114 &4429985340320126427 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 6992812452127128618} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0} | ||
| m_Name: | ||
| m_EditorClassIdentifier: | ||
| m_PanelSettings: {fileID: 11400000, guid: bb97c42b0da64184d8f6ef64e0c20845, type: 2} | ||
| m_ParentUI: {fileID: 0} | ||
| sourceAsset: {fileID: 9197481963319205126, guid: 54eac630072f2954eab32aa476089063, type: 3} | ||
| m_SortingOrder: 1 |
7 changes: 7 additions & 0 deletions
7
Experimental/MultiplayerUseCases/Assets/Common/Prefabs/NetworkManagerUI_Toolkit.prefab.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 hidden or 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
152 changes: 152 additions & 0 deletions
152
Experimental/MultiplayerUseCases/Assets/Common/Scripts/UIElementsUtils.cs
This file contains hidden or 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,152 @@ | ||
| using System; | ||
| using System.IO; | ||
| #if UNITY_EDITOR | ||
| using UnityEditor; | ||
| #endif | ||
| using UnityEngine.UIElements; | ||
|
|
||
| namespace Unity.Netcode.Samples.MultiplayerUseCases.Common | ||
| { | ||
| /// <summary> | ||
| /// An utility class for common UIElements setup method | ||
| /// </summary> | ||
| public static class UIElementsUtils | ||
| { | ||
| #if UNITY_EDITOR | ||
| static readonly string k_UIFilesPathInTemplate = Path.Combine("Assets", Path.Combine("Editor", "UI")); | ||
|
|
||
| /// <summary> | ||
| /// Loads an UXML file from an editor folder | ||
| /// </summary> | ||
| /// <param name="fileName">The name fo the file to load</param> | ||
| /// <returns></returns> | ||
| public static VisualTreeAsset LoadUXML(string fileName) | ||
| { | ||
| string path = $"{Path.Combine(k_UIFilesPathInTemplate, fileName)}.uxml"; | ||
| return AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(path); | ||
| } | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Initializes a Button | ||
| /// </summary> | ||
| /// <param name="buttonName">Name of the button in the document</param> | ||
| /// <param name="onClickAction">method to execute on click</param> | ||
| /// <param name="isEnabled">Is the button enabled?</param> | ||
| /// <param name="parent">Parent of the button</param> | ||
| /// <param name="text">Text to display on the button</param> | ||
| /// <param name="tooltip">Tooltip of the button</param> | ||
| /// <param name="showIfEnabled">Enables the element if it supposed to be enabled</param> | ||
| /// <returns>The initialized button</returns> | ||
| public static Button SetupButton(string buttonName, Action onClickAction, bool isEnabled, VisualElement parent, string text = "", string tooltip = "", bool showIfEnabled = true) | ||
| { | ||
| Button button = parent.Query<Button>(buttonName); | ||
| button.SetEnabled(isEnabled); | ||
| button.clickable = new Clickable(() => onClickAction?.Invoke()); | ||
| button.text = text; | ||
| button.tooltip = string.IsNullOrEmpty(tooltip) ? button.text : tooltip; | ||
|
|
||
| if (showIfEnabled && isEnabled) | ||
| { | ||
| Show(button); | ||
| } | ||
|
|
||
| return button; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes an EnumField | ||
| /// </summary> | ||
| /// <typeparam name="T">Type of the values in the EnumField</typeparam> | ||
| /// <param name="enumName">Name of the EnumField in the document</param> | ||
| /// <param name="text">Text to display on the EnumField's label</param> | ||
| /// <param name="onValueChanged">method to execute when the vlaue of EnumField changes</param> | ||
| /// <param name="parent">Parent of the EnumField</param> | ||
| /// <param name="defaultValue">Default vlaue of the Enumfield</param> | ||
| /// <returns>The initialized EnumField</returns> | ||
| public static EnumField SetupEnumField<T>(string enumName, string text, EventCallback<ChangeEvent<Enum>> onValueChanged, VisualElement parent, T defaultValue) where T : Enum | ||
| { | ||
| EnumField uxmlField = parent.Q<EnumField>(enumName); | ||
| uxmlField.label = text; | ||
| uxmlField.Init(defaultValue); | ||
| uxmlField.value = defaultValue; | ||
| uxmlField.RegisterCallback(onValueChanged); | ||
| return uxmlField; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a Toggle | ||
| /// </summary> | ||
| /// <param name="name">Name of the toggle</param> | ||
| /// <param name="label">Text of the toggle's label</param> | ||
| /// <param name="text">Text of the toggle</param> | ||
| /// <param name="defaultValue">Default value of the toggle</param> | ||
| /// <param name="onValueChanged">Method to call when the value of the toggle changes</param> | ||
| /// <param name="parent">Parent of the toggle</param> | ||
| /// <returns>The initializedToggle</returns> | ||
| public static Toggle SetupToggle(string name, string label, string text, bool defaultValue, EventCallback<ChangeEvent<bool>> onValueChanged, VisualElement parent) | ||
| { | ||
| Toggle uxmlField = parent.Q<Toggle>(name); | ||
| uxmlField.label = label; | ||
| uxmlField.text = text; | ||
| uxmlField.value = defaultValue; | ||
| uxmlField.SetEnabled(true); | ||
| uxmlField.RegisterCallback(onValueChanged); | ||
| return uxmlField; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes an IntegerField | ||
| /// </summary> | ||
| /// <param name="name">Name of the IntegerField</param> | ||
| /// <param name="value">Start value of the IntegerField</param> | ||
| /// <param name="onValueChanged">Method to call when the value changes</param> | ||
| /// <param name="parent">Parent of the IntegerField</param> | ||
| /// <returns>The initialized IntegerField</returns> | ||
| public static IntegerField SetupIntegerField(string name, int value, EventCallback<ChangeEvent<int>> onValueChanged, VisualElement parent) | ||
| { | ||
| IntegerField uxmlField = parent.Q<IntegerField>(name); | ||
| uxmlField.value = value; | ||
| uxmlField.SetEnabled(true); | ||
| uxmlField.RegisterCallback(onValueChanged); | ||
| return uxmlField; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes an StringField | ||
| /// </summary> | ||
| /// <param name="name">Name of the StringField</param> | ||
| /// <param name="label">Text of the StringField's label</param> | ||
| /// <param name="value">Start value of the StringField</param> | ||
| /// <param name="onValueChanged">Method to call when the value changes</param> | ||
| /// <param name="parent">Parent of the StringField</param> | ||
| /// <returns>The initialized StringField</returns> | ||
| public static TextField SetupStringField(string name, string label, string value, EventCallback<ChangeEvent<string>> onValueChanged, VisualElement parent) | ||
| { | ||
| TextField uxmlField = parent.Q<TextField>(name); | ||
| uxmlField.label = label; | ||
| uxmlField.value = value; | ||
| uxmlField.SetEnabled(true); | ||
| uxmlField.RegisterCallback(onValueChanged); | ||
| return uxmlField; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Makes a visual element invisible | ||
| /// </summary> | ||
| /// <param name="element">The element</param> | ||
| public static void Hide(VisualElement element) | ||
| { | ||
| element.style.display = DisplayStyle.None; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Makes a visual element visible | ||
| /// </summary> | ||
| /// <param name="element">The element</param> | ||
| public static void Show(VisualElement element) | ||
| { | ||
| element.style.display = DisplayStyle.Flex; | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Experimental/MultiplayerUseCases/Assets/Common/Scripts/UIElementsUtils.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.