diff --git a/.gitignore b/.gitignore index 4aa5c03..9bc69fc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ # Please do not add editor specific ignore lines to this file. Unity best practices # documentation regarding this can be found at # https://github.com/Applifier/unity-ads-documentation/wiki/Conventions#gitignore + +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 27d190a..02ee7f1 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,22 @@ You must follow the steps in the UI Toolkit user manual to create the examples. ## Editor UI examples - [Get started with UI Toolkit](https://docs.unity3d.com/Documentation/Manual/UIE-simple-ui-toolkit-workflow.html) +- [Relative and absolute positioning C# example](https://docs.unity3d.com/Manual/UIE-relative-absolute-positioning-example.html) +- [Create a Custom Inspector ](https://docs.unity3d.com/Documentation/Manual/UIE-HowTo-CreateCustomInspector.html) ## Runtime UI examples - [Get started with runtime UI](https://docs.unity3d.com/Documentation/Manual/UIE-get-started-with-runtime-ui.html) +- [Move elements at runtime](https://docs.unity3d.com/6000.1/Documentation/Manual/UIE-move-elements-at-runtime.html) -## Tabbed menu examples - -- [Create a tabbed menu for runtime](https://docs.unity3d.com/Documentation/Manual/UIE-create-tabbed-menu-for-runtime.html) - ## Custom controls examples - [Create a slide toggle custom control](https://docs.unity3d.com/Documentation/Manual/UIE-slide-toggle.html) - [Create a radial progress indicator](https://docs.unity3d.com/Documentation/Manual/UIE-radial-progress.html) - [Create a bindable custom control](https://docs.unity3d.com/Documentation/Manual/UIE-create-bindable-custom-control.html) - [Create a custom style for a custom control](https://docs.unity3d.com/Documentation/Manual/UIE-create-custom-style-custom-control.html) +- [Create a custom control with two attributes](https://docs.unity3d.com/Manual/UIB-structuring-ui-custom-elements.html) ## Basic binding examples @@ -42,11 +42,15 @@ You must follow the steps in the UI Toolkit user manual to create the examples. - [Bind a custom control](https://docs.unity3d.com/Documentation/Manual/UIE-bind-custom-control.html) - [Bind a custom control to custom data type](https://docs.unity3d.com/Documentation/Manual/UIE-bind-to-custom-data-type.html) -## UXML element examples - -- [Toggle](https://docs.unity3d.com/Manual/UIE-uxml-element-Toggle.html) -- [ListView](https://docs.unity3d.com/Manual/UIE-uxml-element-ListView.html) +## UI controls examples +- [Use Toggle to create a conditional UI](https://docs.unity3d.com/Documentation/Manual/UIE-create-a-conditional-ui.html) +- [Wrap content inside a scroll view](https://docs.unity3d.com/Manual/UIE-wrap-content-inside-scrollview.html) +- [Create list and tree views](https://docs.unity3d.com/2022.1/Documentation/Manual/UIE-ListView-TreeView.html) +- [Create a complex list view](https://docs.unity3d.com/2022.1/Documentation/Manual/UIE-create-list-view-complex.html) +- [Create a list view runtime UI](https://docs.unity3d.com/Documentation/Manual/UIE-HowTo-CreateRuntimeUI.html) +- [Create a pop-up windows](https://docs.unity3d.com/Manual/UIE-create-a-popup-window.html) +- [Create a tabbed menu for runtime](https://docs.unity3d.com/Documentation/Manual/UIE-create-tabbed-menu-for-runtime.html) ## Transition examples @@ -54,13 +58,20 @@ You must follow the steps in the UI Toolkit user manual to create the examples. - [Transition events](https://docs.unity3d.com/Manual/UIE-Transition-Events.html) - [Create looping transitions](https://docs.unity3d.com/2022.1/Documentation/Manual/UIE-transition-event-loop-example.html) -# List and tree view examples -- [Create list and tree views](https://docs.unity3d.com/2022.1/Documentation/Manual/UIE-ListView-TreeView.html) -- [Create a list view runtime UI](https://docs.unity3d.com/Documentation/Manual/UIE-HowTo-CreateRuntimeUI.html) - -# Drag-and-drop UI examples +## Drag-and-drop UI examples - [Create a drag-and-drop UI inside a custom Editor window](https://docs.unity3d.com/Documentation/Manual/UIE-create-drag-and-drop-ui.html) - [Create a drag-and-drop UI to drag between Editor windows](https://docs.unity3d.com/Documentation/Manual/UIE-drag-across-windows.html) +## Vector UI examples + +- [Create a pie chart in the Editor and runtime UI](https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-pie-chart.html) +- [Use Vector API to create a radial progress indicator](https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-radial-progress-use-vector-api.html) + +## Text examples + +- [Get started with text](https://docs.unity3d.com/Manual/UIE-get-started-with-text.html) +- [Add hyperlinks in text](https://docs.unity3d.com/Documentation/Manual/ui-systems/add-hyperlinks-in-text.html) + + diff --git a/bind-to-list/Editor/GameSwitchListEditor.cs b/bind-to-list/Editor/GameSwitchListEditor.cs index 025f9cc..6bf197c 100644 --- a/bind-to-list/Editor/GameSwitchListEditor.cs +++ b/bind-to-list/Editor/GameSwitchListEditor.cs @@ -1,24 +1,36 @@ +using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; +using UnityEditor.UIElements; -namespace UIToolkitExamples +public class ListViewBindingExample : EditorWindow { - [CustomEditor(typeof(GameSwitchListAsset))] - public class GameSwitchListEditor : Editor + [SerializeField] + private VisualTreeAsset m_VisualTreeAsset = default; + + [SerializeField] + private GameSwitchListAsset gameSwitchList; + + [MenuItem("UI Toolkit Examples/ListView SerializedObject Binding Example")] + public static void ShowExample() { - [SerializeField] - VisualTreeAsset m_ItemAsset; + ListViewBindingExample wnd = GetWindow(); + wnd.titleContent = new GUIContent("ListView Binding SerializedObject Example"); + } - [SerializeField] - VisualTreeAsset m_EditorAsset; + public void CreateGUI() + { + VisualElement root = rootVisualElement; + m_VisualTreeAsset.CloneTree(root); - public override VisualElement CreateInspectorGUI() + var listView = root.Q(); + if (listView != null && gameSwitchList != null) { - var root = m_EditorAsset.CloneTree(); - var listView = root.Q(); - listView.makeItem = m_ItemAsset.CloneTree; - return root; + // Set the items source. + listView.itemsSource = gameSwitchList.switches; + // Bind the ListView to the GameSwitchListAsset serialized object. + listView.Bind(new SerializedObject(gameSwitchList)); } } -} \ No newline at end of file +} diff --git a/bind-to-list/Editor/game_switch_list_editor.uxml b/bind-to-list/Editor/game_switch_list_editor.uxml deleted file mode 100644 index d6aa61c..0000000 --- a/bind-to-list/Editor/game_switch_list_editor.uxml +++ /dev/null @@ -1,10 +0,0 @@ - - - \ No newline at end of file diff --git a/bind-to-list/GameSwitch.cs b/bind-to-list/GameSwitch.cs deleted file mode 100644 index dbbb2bf..0000000 --- a/bind-to-list/GameSwitch.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -[Serializable] -public struct GameSwitch -{ - public string name; - public bool enabled; -} \ No newline at end of file diff --git a/bind-to-list/GameSwitchListAsset.cs b/bind-to-list/GameSwitchListAsset.cs index c8129cc..8f25bdc 100644 --- a/bind-to-list/GameSwitchListAsset.cs +++ b/bind-to-list/GameSwitchListAsset.cs @@ -1,23 +1,28 @@ +using System; using System.Collections.Generic; +using System.Diagnostics; using UnityEngine; - -namespace UIToolkitExamples + +[CreateAssetMenu(fileName = "GameSwitchListAsset.asset", menuName = "GameSwitchListAsset")] +public class GameSwitchListAsset : ScriptableObject { - [CreateAssetMenu(menuName = "UIToolkitExamples/GameSwitchList")] - public class GameSwitchListAsset : ScriptableObject + public List switches = new(); + + public void Reset() { - public List switches; + switches = new List{ + new() { name = "Use Local Server", enabled = false }, + new() { name = "Show Debug Menu", enabled = false }, + new() { name = "Show FPS Counter", enabled = true }, + }; + } - public void Reset() - { - switches = new() - { - new() { name = "Use Local Server", enabled = false }, - new() { name = "Show Debug Menu", enabled = false }, - new() { name = "Show FPS Counter", enabled = true }, - }; - } + public bool IsSwitchEnabled(string switchName) => switches.Find(s => s.name == switchName).enabled; - public bool IsSwitchEnabled(string switchName) => switches.Find(s => s.name == switchName).enabled; + [Serializable] + public struct GameSwitch + { + public bool enabled; + public string name; } -} \ No newline at end of file +} diff --git a/bind-to-list/game_switch.uxml b/bind-to-list/game_switch.uxml index 06530f1..6e263f1 100644 --- a/bind-to-list/game_switch.uxml +++ b/bind-to-list/game_switch.uxml @@ -1,6 +1,6 @@ - - - - - - \ No newline at end of file + + + + + + diff --git a/bind-to-list/game_switch_list_editor.uxml b/bind-to-list/game_switch_list_editor.uxml new file mode 100644 index 0000000..07d843b --- /dev/null +++ b/bind-to-list/game_switch_list_editor.uxml @@ -0,0 +1,4 @@ + + + + diff --git a/bind-uxml-template/Editor/GameSwitchesEditor.cs b/bind-uxml-template/Editor/GameSwitchesEditor.cs index 3c60315..7d40f3e 100644 --- a/bind-uxml-template/Editor/GameSwitchesEditor.cs +++ b/bind-uxml-template/Editor/GameSwitchesEditor.cs @@ -1,18 +1,30 @@ +using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; +using UnityEditor.UIElements; -namespace UIToolkitExamples +public class UXMLTemplateBindingExample : EditorWindow { - [CustomEditor(typeof(GameSwitchesAsset))] - public class GameSwitchesEditor : Editor + [SerializeField] + private VisualTreeAsset m_VisualTreeAsset = default; + + [SerializeField] + private GameSwitchesAsset gameSwitch; + + [MenuItem("UI Toolkit Examples/UXML Template Binding Example")] + public static void ShowExample() + { + UXMLTemplateBindingExample wnd = GetWindow(); + wnd.titleContent = new GUIContent("UXML Template Binding Example"); + } + + public void CreateGUI() { - [SerializeField] - VisualTreeAsset visualTreeAsset; + VisualElement root = rootVisualElement; + m_VisualTreeAsset.CloneTree(root); - public override VisualElement CreateInspectorGUI() - { - return visualTreeAsset.CloneTree(); - } + root.Bind(new SerializedObject(gameSwitch)); + } } \ No newline at end of file diff --git a/bind-uxml-template/Editor/game_switches_editor.uxml b/bind-uxml-template/Editor/game_switches_editor.uxml deleted file mode 100644 index b9571ac..0000000 --- a/bind-uxml-template/Editor/game_switches_editor.uxml +++ /dev/null @@ -1,6 +0,0 @@ - -