SUIDropdown
| 函数 | RefreshShownValue | Refreshes the text and image (if available) of the currently selected option.If you have modified the list of options, you should call this method afterwards to ensure that the visual state of the dropdown corresponds to the updated options. |
| 函数 | AddOptions | Add multiple options to the options of the Dropdown. |
| 函数 | ClearOptions | Clear the list of options in the Dropdown. |
| 函数 | Show | Show the dropdown list. |
| 函数 | Hide | Hide the dropdown list. |
| 函数 | OnValueChanged | Bind a function to handle the event that is invoked when when a user has clicked one of the options in the dropdown list. |
| 函数 | SetValueByText | Attempts to set the dropdown to the first option in the dropdown list that matches the inputted text. |
| 属性 | Interactable | Is this UIDropdown interactable? |
| 属性 | Template | The Rect Transform of the template for the dropdown list. |
| 属性 | CaptionText | The Text component to hold the text of the currently selected option. |
| 属性 | CaptionImage | The Image component to hold the image of the currently selected option. |
| 属性 | ItemText | The Text component to hold the text of the item. |
| 属性 | ItemImage | The Image component to hold the image of the item. |
| 属性 | OptionsAsText | The list of possible options. (Text) |
| 属性 | OptionsAsSprites | The list of possible options. (Sprites) |
| 属性 | Value | The Value is the index number of the current selection in the Dropdown. 0 is the first option in the Dropdown, 1 is the second, and so on. |
| 属性 | NormalColor | – |
| 属性 | HighlightedColor | – |
| 属性 | PressedColor | – |
| 属性 | DisabledColor | – |
| 属性 | ColorMultiplier | – |
| 属性 | GameObject | – |
函数
RefreshShownValue
Refreshes the text and image (if available) of the currently selected option.If you have modified the list of options, you should call this method afterwards to ensure that the visual state of the dropdown corresponds to the updated options.
返回值
void
示例
Space.Host.ExecutingObject.UIDropdown.RefreshShownValue()
AddOptions
Add multiple options to the options of the Dropdown.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| options | string[] | – |
| options | Table | – |
| optionsSprites | SResource[] | – |
返回值
void
示例
Space.Host.ExecutingObject.UIDropdown.AddOptions({"option1","option2","option3"})
ClearOptions
Clear the list of options in the Dropdown.
返回值
void
示例
Space.Host.ExecutingObject.UIDropdown.ClearOptions()
Show
Show the dropdown list.
返回值
void
示例
Space.Host.ExecutingObject.UIDropdown.Show()
Hide
Hide the dropdown list.
返回值
void
示例
Space.Host.ExecutingObject.UIDropdown.Hide()
OnValueChanged
Bind a function to handle the event that is invoked when when a user has clicked one of the options in the dropdown list.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| callback | Closure | – |
返回值
void
示例
function AFunction()
--
end
Space.Host.ExecutingObject.UIDropdown.OnValueChanged(AFunction)
SetValueByText
Attempts to set the dropdown to the first option in the dropdown list that matches the inputted text. Returns true if found, false if no matches found.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| text | string | – |
返回值
bool
示例
Space.Host.ExecutingObject.UIDropdown.SetValueByText("Value Text")
--Populating a UIDropdown and making a selection using value's text
dropDown=Space.Host.GetReference("DropDown").UIDropdown
options = {"Room 1", "Room 2", "Room 3", "Room 4"}
dropDown.AddOptions(options)
dropDown.SetValueByText("Room 3")
属性
Interactable
Is this UIDropdown interactable?
示例
Space.Host.ExecutingObject.UIDropdown.Interactable = true
--clicking this object will toggle a UIDropdown's interactable status
thisGameObject = Space.Host.ExecutingObject
dropdown = Space.Host.GetReference("dropdown").UIDropdown
--make sure to add this reference to the Scripting Runtime component
OnClick = function()
dropdown.Interactable = not dropdown.Interactable
end
thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
Template
The Rect Transform of the template for the dropdown list.
示例
aReferenceToAGameObject = Space.Host.GetReference("reference name")
Space.Host.ExecutingObject.UIDropdown.Template = aReferenceToAGameObject
CaptionText
The Text component to hold the text of the currently selected option.
示例
captionText = Space.Host.ExecutingObject.UIDropdown.CaptionText
captionText.Text = "new caption"
CaptionImage
The Image component to hold the image of the currently selected option.
示例
aReferenceToAGameObject = Space.Host.GetReference("reference name")
Space.Host.ExecutingObject.UIDropdown.CaptionImage = aReferenceToAGameObject.UIImage
ItemText
The Text component to hold the text of the item.
示例
aReferenceToAGameObject = Space.Host.GetReference("reference name")
Space.Host.ExecutingObject.UIDropdown.CaptionImage = aReferenceToAGameObject.UIText
ItemImage
The Image component to hold the image of the item.
示例
iaReferenceToAGameObject = Space.Host.GetReference("reference name")
Space.Host.ExecutingObject.UIDropdown.CaptionImage = aReferenceToAGameObject.UIImage
OptionsAsText只读
The list of possible options. (Text)
示例
optionsText = Space.Host.ExecutingObject.UIDropdown.OptionsAsText
OptionsAsSprites只读
The list of possible options. (Sprites)
示例
optionsSprites = Space.Host.ExecutingObject.UIDropdown.OptionsAsSprites
Value
The Value is the index number of the current selection in the Dropdown. 0 is the first option in the Dropdown, 1 is the second, and so on.
示例
Space.Host.ExecutingObject.UIDropdown.Value= 2
NormalColor
示例
Space.Host.ExecutingObject.UIDropdown.NormalColor = Color.Red
HighlightedColor
示例
Space.Host.ExecutingObject.UIDropdown.HighlightedColor = Color.Red
PressedColor
示例
Space.Host.ExecutingObject.UIDropdown.PressedColor = Color.Red
DisabledColor
示例
Space.Host.ExecutingObject.UIDropdown.DisabledColor = Color.Red
ColorMultiplier
示例
Space.Host.ExecutingObject.UIDropdown.ColorMultiplier = Color.Red
GameObject只读
示例
Space.Host.ExecutingObject.UIDropdown.GameObject = Color.Red



