enumeration
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseOptions for controlling how nested ScrollView handles scrolling when reaching the limits of the scrollable area.
This Enum is only relevant when used for a ScrollView that is nested inside another ScrollView.
The following example demonstrates how to use the NestedInteractionKind enum to control the behavior of a nested ScrollView.
using System; using UnityEngine; using UnityEngine.UIElements;
[RequireComponent(typeof(UIDocument))] public class ScrollView_NestedInteraction_Example : MonoBehaviour { // To use this example in runtime, add a UIDocument component to your Scene and attach a UXML file to the UIDocument component. // The UXML file can be empty. public UIDocument uiDocument; public int numberOfPotions = 10;
Label[] labels; string[] otherItems = { "Shield", "Sword", "Helmet", "Boots", "Gloves" };
void Start() { // Inner ScrollView for the list of potions. var potionInventoryScrollView = new ScrollView { name = "MyPotionsInventory" }; potionInventoryScrollView.style.height = 200; var potionsInventoryColor = new Color(0.65f, 0.3f, 0.2f, 1f);
// Outer ScrollView for the entire inventory, which includes the inner ScrollView. var fullInventoryScrollView = new ScrollView { name = "MyFullInventory" }; fullInventoryScrollView.style.height = 250; var fullInventoryColor = new Color(0.2f, 0.3f, 0.65f, 1f);
// Create a toggle to use NestedInteractionKind.StopScrolling instead of NestedInteractionKind.ForwardScrolling, // which is the default behavior for scroll wheel input. var toggle = new Toggle("Potions ScrollView: Use NestedInteractionKind.StopScrolling instead of NestedInteractionKind.ForwardScrolling"); toggle.RegisterValueChangedCallback( (evt => potionInventoryScrollView.nestedInteractionKind = evt.newValue ? ScrollView.NestedInteractionKind.StopScrolling : ScrollView.NestedInteractionKind.ForwardScrolling ));
// Create a list of labels representing potions. labels = new Label[numberOfPotions]; for (int i = 0; i < numberOfPotions; i++) { var label = new Label { text = " Unnamed Potion #" + (i) }; label.style.backgroundColor = potionsInventoryColor; potionInventoryScrollView.Add(label); }
var potionsInventoryTitle = new Label { text = "Potions Inventory" }; potionsInventoryTitle.style.unityFontStyleAndWeight = FontStyle.Bold; potionsInventoryTitle.style.fontSize = 20; potionsInventoryTitle.style.color = potionsInventoryColor; potionsInventoryTitle.style.unityTextAlign = TextAnchor.MiddleCenter;
var fullInventoryTitle = new Label { text = "Full Inventory" }; fullInventoryTitle.style.unityFontStyleAndWeight = FontStyle.Bold; fullInventoryTitle.style.fontSize = 25; fullInventoryTitle.style.color = fullInventoryColor; fullInventoryTitle.style.unityTextAlign = TextAnchor.MiddleCenter;
fullInventoryScrollView.Add(potionsInventoryTitle); fullInventoryScrollView.Add(potionInventoryScrollView);
// Create a list of labels representing other items. foreach (var item in otherItems) { var label = new Label { text = item }; label.style.backgroundColor = fullInventoryColor; fullInventoryScrollView.Add(label); }
uiDocument.rootVisualElement.Add(toggle); uiDocument.rootVisualElement.Add(fullInventoryTitle); uiDocument.rootVisualElement.Add(fullInventoryScrollView); } }
Default | Automatically selects the behavior according to the context in which the UI runs. For touch input, typically mobile devices, NestedInteractionKind.StopScrolling is used. For scroll wheel input, NestedInteractionKind.ForwardScrolling is used. |
StopScrolling | Scrolling capture will remain in the scroll view if it initiated the drag. |
ForwardScrolling | Scrolling will continue to the parent when no movement is possible in the scrolled direction. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.