Adding Support for Scrollable Containers#54
Merged
ElChupos merged 9 commits intoFacepunch:masterfrom Apr 11, 2024
Merged
Conversation
Implementation of Unity's ScrollRect, including a Mask & ChildCanvas for better performance Added Scrollbar support, allowing the customization of color, thickness Added mask softness for RectMask2D added in Unity 2019.4.20 Added Update support for Scrollviews Added enable support for scrollbars no Selective Update support for individual Scrollbars as they are in a sub json object, could be added by replicating the ShouldUpdateField with the sub object
reversed offsetmax fix because alot of UIs rely on it
4 tasks
this PR addresses issues i identified while modding this PR into the game for testing, other than these changes it works as expected with the test JSON provided (after it is updated)
updated scroll example to actually look the part in the client really appreciating whoever put Assets/Icons/rust.png instead of Assets/Content/UI/UI.Background.Tile.psd as the default sprite for RawImages btw
retains the same functionality
if a scrollview was indirectly destroyed its entry would remain causing subsequent lookups for the same name to not return anything. disabled the scrollview redirect when looking for a panel to update, this allows the code to correctly find and update the GameObject containing the scrollview instead of its content
Will be better for future tests
Unsure what unity version this was added in but we don't currently support this property
Contributor
|
This looks great, thanks for the addition. I made a couple of minor changes and updated it with the latest RPC syntax from the core Rust game. In terms of tests, I think it would be a good habit going forwards to put them into the new Tests folder - that way we can easily load up a new feature to see how it works and check for any regressions down the line. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adding Scrollable Containers with Unity's ScrollRect
Adding Scrollable Containers Allows us to Create Cleaner UIs & Remove Strain from the Server. its a versatile component that can be used on anything from lists, to sidescrollers or to create dragable components
The Breakdown
in order to create a scrollable component 3 things are needed: the ScrollRect, the Mask & the Content. this component creates all of them while exposing most values to the json object,
this component creates a child game object for the content and redirects any children to be parented under this content object, this is required for the ScrollRect to work
For Added Performance it also adds a new Canvas to the Object containing the ScrollRect, as this will reduce redraws of the entire UI when the content gets scrolled or moves
the JSON representation
the json representation is made to expose as many options as possible, most are optional:
{ "type":"UnityEngine.UI.ScrollView", "vertical": true, // Enables or Disables vertical scrolling & dragging "horizontal": true, // Enables or Disables horizontal scrolling & dragging, can be used together "movementType": "Elastic", // MovementType, can be set to "Elastic", "Clamped" or "Unrestricted" "elasticity": 0.25, // how much the container bounces back when reaching the end, only applies to Elastic "inertia": true, // defines if the content continues to move after scrolling/dragging has stopped "decelerationRate": 0.3, // only used with inertia, higher decelRate = stops faster (visually) "scrollSensitivity": 3.0, // multiplier when using the scroll wheel, a higher will be better for most usecases "maskSoftness": "0 0", // applies a fadeout to the x & y of the RectMask2D's borders "contentTransform": { // this controlls the content's size, the content does not dynamically scale as you add objects to the scrollview so make sure to plan ahead "anchormin": "0 0", "anchormax": "1 1", "offsetmin": "0 -200", "offsetmax": "0 0" }, "horizonalScrollbar" : { // holds properties for a scrollbar, omit if you dont want a scrollback "invert" : false, // inverts the scrollbar to go bottom up instead ot top down "autoHide": false, // hides the scrollbar if the content doesn't need a scrollbar, shifts the viewport to the side "handleSprite": "assets/content/ui/ui.rounded.tga", // the built in sprite to use for the draggable part of the scrollbar "size": 20, // the thickness of the scrollbar "handleColor": "0.15 0.15 0.15 1", // the normal collor of the handle "highlightColor": "0.17 0.17 0.17 1", // the color when the scrollview is hovered "pressedColor": "0.2 0.2 0.2 1", // the color while the handle is clicked "trackSprite": "assets/content/ui/ui.background.tile.psd", // the sprite of the Scrollbar track "trackColor": "0.09 0.09 0.09 1" // the color of the track }, "verticalScrollbar" : { ... } // same schema as horizontal, both can be used at once }