meta data for this page
UI
This table contains various functions related to UI. Except for some parts of the main menu, all of the game's UI is handled using the functions provided in here.
objectId
All functions that are listed below expect an objectId
(transform id) as first argument. The functions will always refer to this object.
Callbacks
A large part of UI code handles interactions, i.e. actions that are taken as a response to some player UI input. Following functions will allow you to execute Lua code once the user performs a specific action.
UI.setOnClickCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the user clicks the object. Note that your object will need an Image component with raycast target enabled.
This is the preferred function for all UI callbacks. Always use this if suitable.
function UI.setOnClickCallback(objectId, callback)
UI.setOnHitCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the user hits the object. Note that your object will need an Image component with raycast target enabled.
function UI.setOnHitCallback(objectId, callback)
UI.setOnReleaseCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the mouse is released. Note that your object will need an Image component with raycast target enabled.
function UI.setOnReleaseCallback(objectId, callback)
UI.setIsDownCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called in every frame in which the mouse is down, i.e. usually repeatedly. Therefore you should only use this if you know what you are doing, and if you really need it. Note that your object will need an Image component with raycast target enabled.
function UI.setIsDownCallback(objectId, callback)
UI.setOnEnterCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the player starts hovering the object, i.e. once the mouse cursor enters the object. Note that your object will need an Image component with raycast target enabled.
function UI.setOnEnterCallback(objectId, callback)
UI.setOnExitCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the player stops hovering the object, i.e. once the mouse cursor leaves the object. Note that your object will need an Image component with raycast target enabled.
function UI.setOnExitCallback(objectId, callback)
UI.setToggleStateChangedCallback(objectId, callback)
Attaches the function callback
to the Toggle attached to this object. The function will be called every time the player clicks the toggle box. This function uses Unity's Toggle component, therefore make sure that you have attached a Toggle
component to the object.
function UI.setToggleStateChangedCallback(objectId, callback)
UI.setButtonCallback(objectId, callback)
Attaches the function callback
to the button attached to this object. The function will be called every time the button is hit. This function uses Unity's Button component, therefore make sure that you have attached a Button
component to the object.
function UI.setButtonCallback(objectId, callback)
UI.setSliderCallback(objectId, callback)
Attaches the function callback
to the slider attached to this object. The function will be called every time the user uses the slider. This function uses Unity's Slider component, therefore make sure that you have attached a Slider
component to the object.
function UI.setSliderCallback(objectId, callback)
UI.setOnInputTextChangedCallback(objectId, callback)
Attaches the function callback
to this object. The function will be called every time the user edits the text in the input field. This uses the TMP_InputField component from Unity's Text Mesh Pro package.
function UI.setOnInputTextChangedCallback(objectId, callback)
Manipulating UI elements
As a response to user input, you will usually want to modify your UI elements (e.g. display some texts, some images, etc.). Following functions allow you to alter the content of UI elements or their style.
Additionally, you can also use other functions such as instantiate
, getChild
or setActive
as outlined in the page on Nodes.
UI.getCheckboxState(objectId)
Returns whether the Toggle attached to this object is checked (true
in that case, otherwise false
). This function uses Unity's Toggle component, therefore make sure that you have attached a Toggle
component to the object.
function UI.getCheckboxState(objectId)
UI.setCheckboxState(objectId, isChecked)
Sets whether the Toggle attached to this object is checked or not, depending on isChecked
(bool). This function uses Unity's Toggle component, therefore make sure that you have attached a Toggle
component to the object.
function UI.setCheckboxState(objectId, isChecked)
UI.getLabelText(objectId)
Returns the text that is currently displayed by the TMP_Text component attached to the object.
function UI.getLabelText(objectId)
UI.setLabelText(objectId, text)
Sets the text that is displayed by the TMP_Text component attached to the object.
function UI.setLabelText(objectId, text)
UI.setLabelColor(objectId, r,g,b,a)
Sets the font color of the TMP_Text component attached to the object to the color r, g, b, a
(each as integer between 0 and 255).
function UI.setLabelColor(objectId, r,g,b,a)
UI.setHoverAnimationActive(objectId, isActive)
Currently not supported by Modding SDK
function UI.setHoverAnimationActive(objectId, isActive)
UI.getHoverAnimationActive(objectId)
Currently not supported by modding SDK
function UI.getHoverAnimationActive(objectId)
UI.getSliderValue(objectId)
Returns the current value of the Slider component attached to the object (float value, either whole numbers or decimal numbers, depending on slider settings).
function UI.getSliderValue(objectId)
UI.setSliderValue(objectId, value)
Sets the current slider value of the Slider component attached to the object to value
.
function UI.setSliderValue(objectId, value)
UI.setSliderLimits(objectId, min, max)
Sets the slider limits to min
and max
. Again, the object will need a Slider component attached to it.
function UI.setSliderLimits(objectId, min, max)
UI.getSliderLimits(objectId)
Returns the slider limits (two values, min
and max
). Again, the object will need a Slider component attached to it.
Available since update 6.1.
function UI.getSliderLimits(objectId)
UI.setSliderWholeNumbers(objectId, wholeNumbersOnly)
Sets whether the slider attached to the object will allow whole numbers only (true
) or both whole and decimal numbers (false
).
function UI.setSliderWholeNumbers(objectId, wholeNumbersOnly)
UI.setInputFieldText(objectId, text)
Sets the text of the TMP_InputField component attached to the object to text
.
function UI.setInputFieldText(objectId, text)
UI.getInputFieldText(objectId, string)
Returns the text of the TMP_InputField attached to the object.
function UI.getInputFieldText(objectId, string)
UI.setImageSprite(objectId, spriteId)
Sets the sprite of the Image component attached to the object. The sprite with id spriteId
(similar to transform ids) will be displayed.
Usually, you will want to load the sprite from an asset bundle beforehand (using Utils.loadBundleSprite
).
function UI.setImageSprite(objectId, spriteId)
UI.setImageFromSavegame(objectId, mapType)
(Added in Patch 5)
This function allows you to query either the minimap or the slopemap from the savegame's bin file and to display it in the Image component attached to the object.
- mapType
minimap
will display the minimap. - mapType
slopemap
will display the slope map.
The function is only used inside the overview menu's pages.
function UI.setImageFromSavegame(objectId, mapType)
UI.setImageBase64(objectId, base64String)
Creates the Image's sprite from a base64 string. This function is used for storing savegame thumbnails. You can encode any picture to base64 e.g. using https://www.base64-image.de (external link).
function UI.setImageBase64(objectId, base64String)
UI.setImageColor(objectId, r,g,b,a)
Sets the color of the Image component to r, g, b, a
(each component as int between 0 and 255).
function UI.setImageColor(objectId, r,g,b,a)
UI.getImageColor(objectId)
Returns the color of the Image component attached to this object (returns 4 values: r, g, b, a
).
function UI.getImageColor(objectId)
UI.setImageFillAmount(objectId, float)
Sets the fill amount of the Image, e.g. for progess bars. Check out the Unity Documentation for further information.
function UI.setImageFillAmount(objectId, float)
UI.screenshotToImage(objectId, position, rotation, fov)
Please prefer UI.screenshotToRawImage
for performance reasons. Both functions are the same, except that UI.screenshotToRawImage
will use a raw image component which is more efficient for that purpose.
function UI.screenshotToImage(objectId, position, rotation, fov)
UI.screenshotToRawImage(objectId, position, rotation, fov)
Renders an image from a custom position and displays it in the Raw Image component. Make sure the object is using a Raw Image component instead of an Image component.
position
(Vector3 table, must containx, y and z
position) specifies the camera position in world space.rotation
(Vector3 table, must containx, y and z
rotation, in degrees each) specifies the world rotation of the camera.fov
(optional) specifies the vertical field of view of the camera. If no value is specified, 60 degrees FOV will be used.
function UI.screenshotToRawImage(objectId, position, rotation, fov)
UI.rebuildLayout(objectId)
Rebuilds the layout of this object. Check Unity's LayoutRebuilder.ForceRebuildLayoutImmediate for more details. Warning: This function can be very performance-intense. Do not use it in update calls.
function UI.rebuildLayout(objectId)
UI.getSizeDelta(objectId)
Returns the object's sizeDelta. This will return two values x, y
(both float).
function UI.getSizeDelta(objectId)
UI.getAnchoredPos(objectId)
Returns the object's anchoredPosition. This will return two values x, y
(both float).
function UI.getAnchoredPos(objectId)
UI.setAnchoredPos(objectId, x, y)
Sets the object's anchoredPosition to x, y
(both float).
function UI.setAnchoredPos(objectId, x, y)
UI.setAnchoredPosX(objectId, x)
Sets the X component of the anchored position to x
(float).
function UI.setAnchoredPosX(objectId, x)
UI.setAnchoredPosY(objectId, y)
Sets the Y component of the anchored position to y
(float).
function UI.setAnchoredPosY(objectId, y)
Copyright
All contents of this page may be used for modding use for Winter Resort Simulator only. Any use exceeding this regulation is not permitted.
Copyright (C) HR Innoways, 2020. All Rights Reserved.