Toggle Group
A Toggle Group is not a visible UI control but rather a way to modify the behavior of a set of Toggles. Toggles that belong to the same group are constrained so that only one of them can switched on at a time - pressing one of them to switch it on automatically switches the others off.
Toggle Group不是一個可見的UI空間而是修改一組Toggles的行為的方法。屬於同一個Toggle Group的Toggle在同一時間只有一個可以處於打開狀態 - 點擊一個Toggle並打開它會自動關閉其它已經打開的Toggle
A Toggle Group
一個復選框組
Properties
屬性
Property: | Function: |
---|---|
Allow Switch Off | Is it allowed that no toggle is switched on? If this setting is enabled, pressing the toggle that is currently switched on will switch it off, so that no toggle is switched on. If this setting is disabled, pressing the toggle that is currently switched on will not change its state. |
屬性 | 功能 |
---|---|
Allow Switch Off | 勾選這個選項會允許所有Toggle都處於關閉的狀態。 如果這個設置是開啟的,按下當前打開的Toggle會關閉掉它, 這時候是沒有Toggle處於選中狀態的。如果沒有勾選, 那么點擊已經打開的Toggle不會改變它的狀態 |
Description
描述
The Toggle Group is setup by dragging the Toggle Group object to the Group property of each of the Toggles in the group.
通過將Toggle Group對象拖動到每個Toggle的Group屬性來設置Toggle Group
Toggle Groups are useful anywhere the user must make a choice from a mutually exclusive set of options. Common examples include selecting player character types, speed settings (slow, medium, fast, etc), preset colors and days of the week. You can have more than one Toggle Group object in the scene at a time, so you can create several separate groups if necessary.
Toggle Group在用戶必須從一組互斥的選項中做出選擇的任何地方都是有用的。 常見的例子包括選擇玩家角色類型,速度設置(慢,中,快等),預設顏色和星期幾。 同一時間可以在場景中擁有多個Toggle Group,因此您可以根據需要創建多個單獨的組。
Unlike other UI elements, an object with a Toggle Group component does not need to be a child of a Canvas object, although the Toggles themselves still do.
不像其它UI元素,具有Toggle Group組件的對象不需要是Canvas對象的孩子節點,盡管Toggle本身是要在Canvas下的
Note that the Toggle Group will not enforce its constraint right away if multiple toggles in the group are switched on when the scene is loaded or when the group is instantiated. Only when a new toggle is swicthed on are the others switched off. This means it’s up to you to ensure that only one toggle is switched on from the beginning.
請注意,如果在加載場景或實例化組時Toggle Group中的多個Toggle是打開的狀態,Toggle Group將不會立即強制執行其約束。 只有當新的Toggle切換時,Toggle才會被關閉。 這意味着你要確定一開始只有一個Toggle是打開的狀態