Skip to content

Commit 6ba1a8c

Browse files
UI Circle Segmented
1 parent 7c84c58 commit 6ba1a8c

File tree

10 files changed

+604
-3
lines changed

10 files changed

+604
-3
lines changed

Controls/ExtensionsToggle.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Extensions Toggle
2+
3+
An enhanced Toggle component with additional features including multiple event types and toggle group support.
4+
5+
---------
6+
7+
## Contents
8+
9+
> 1 [Overview](#overview)
10+
>
11+
> 2 [Properties](#properties)
12+
>
13+
> 3 [Methods](#methods)
14+
>
15+
> 4 [Usage](#usage)
16+
>
17+
> 5 [Video Demo](#video-demo)
18+
>
19+
> 6 [See also](#see-also)
20+
>
21+
> 7 [Credits and Donation](#credits-and-donation)
22+
>
23+
> 8 [External links](#external-links)
24+
25+
---------
26+
27+
## Overview
28+
29+
The Extensions Toggle is an enhanced version of Unity's standard Toggle component. It extends the functionality with:
30+
31+
- **Unique Identification**: Each toggle can have a unique ID string for easy reference
32+
- **Dual Event System**: Both `OnValueChanged` (bool) and `OnToggleChanged` (toggle reference) events
33+
- **Enhanced Toggle Group**: Integrates seamlessly with the ExtensionsToggleGroup for managed toggle groups
34+
- **Flexible Transitions**: Supports Color Tint, Sprite Swap, and Animation transitions
35+
- **State Management**: Robust handling of on/off states with proper callback triggering
36+
37+
This component is ideal when you need more control over toggle behavior or require toggle group features beyond Unity's standard Toggle.
38+
39+
---------
40+
41+
## Properties
42+
43+
The properties of the Extensions Toggle control are as follows:
44+
45+
Property | Description
46+
-|-
47+
*Unique ID*|A string identifier for this toggle, useful for identifying which toggle was toggled in callbacks.
48+
*Interactable*|Whether this toggle can be interacted with by the user.
49+
*Toggle Transition*|How the toggle transitions between states: None or Fade.
50+
*Graphic*|The graphic element to transition (typically a checkmark or indicator).
51+
*Group*|The ExtensionsToggleGroup this toggle belongs to. Only one toggle in a group can be on at a time (if group allows).
52+
*Is On*|Whether the toggle is currently in the on state.
53+
*Toggle Transition*|The type of transition when toggling: None or Fade.
54+
*Fade Duration*|How long the fade transition takes when Is On changes.
55+
***On Value Changed*** (event)|Invoked when the toggle state changes, passes the new bool value.
56+
***On Toggle Changed*** (event)|Invoked when the toggle state changes, passes a reference to the toggle itself.
57+
58+
### Additional properties available in code
59+
60+
Property | Return Type | Description
61+
-|-|-
62+
IsOn|bool|Get or set whether the toggle is currently on.
63+
UniqueID|string|Get or set the unique identifier string.
64+
Group|ExtensionsToggleGroup|Get or set the toggle group this toggle belongs to.
65+
66+
---------
67+
68+
## Methods
69+
70+
Method | Arguments | Description
71+
-|-|-
72+
*Set*|value (bool)|Set the toggle state without triggering callbacks.
73+
*Set*|value (bool), sendCallback (bool)|Set the toggle state with optional callback triggering.
74+
*OnPointerClick*|PointerEventData|Handles left mouse click to toggle.
75+
*OnSubmit*|BaseEventData|Handles submission (Enter/Space key or gamepad button) to toggle.
76+
77+
---------
78+
79+
## Usage
80+
81+
Add the Extensions Toggle component to a GameObject:
82+
83+
"Add Component -> UI -> Extensions -> Extensions Toggle"
84+
85+
### Basic Toggle Setup
86+
87+
```csharp
88+
public ExtensionsToggle toggle;
89+
90+
void Start()
91+
{
92+
// Listen to toggle state changes
93+
toggle.onValueChanged.AddListener(OnToggleChanged);
94+
}
95+
96+
void OnToggleChanged(bool isOn)
97+
{
98+
Debug.Log("Toggle is " + (isOn ? "ON" : "OFF"));
99+
}
100+
```
101+
102+
### Using the Toggle with Unique ID
103+
104+
```csharp
105+
public ExtensionsToggle toggle;
106+
107+
void Start()
108+
{
109+
toggle.UniqueID = "sound_toggle";
110+
toggle.onToggleChanged.AddListener(OnToggleChanged);
111+
}
112+
113+
void OnToggleChanged(ExtensionsToggle toggleThatChanged)
114+
{
115+
if (toggleThatChanged.UniqueID == "sound_toggle")
116+
{
117+
AudioListener.pause = !toggleThatChanged.IsOn;
118+
}
119+
}
120+
```
121+
122+
### Using Toggle Groups
123+
124+
```csharp
125+
public ExtensionsToggle option1, option2, option3;
126+
public ExtensionsToggleGroup optionGroup;
127+
128+
void Start()
129+
{
130+
// Assign toggles to the group
131+
option1.Group = optionGroup;
132+
option2.Group = optionGroup;
133+
option3.Group = optionGroup;
134+
135+
// Only one toggle can be on at a time
136+
optionGroup.onToggleGroupChanged.AddListener(OnOptionSelected);
137+
}
138+
139+
void OnOptionSelected(bool anyToggleOn)
140+
{
141+
if (anyToggleOn)
142+
{
143+
var selected = optionGroup.SelectedToggle;
144+
Debug.Log("Selected option: " + selected.UniqueID);
145+
}
146+
}
147+
```
148+
149+
### Programmatic Toggle Control
150+
151+
```csharp
152+
public ExtensionsToggle toggle;
153+
154+
void Update()
155+
{
156+
if (Input.GetKeyDown(KeyCode.Space))
157+
{
158+
// Toggle the state
159+
toggle.IsOn = !toggle.IsOn;
160+
}
161+
}
162+
```
163+
164+
---------
165+
166+
## Video Demo
167+
168+
Coming soon...
169+
170+
---------
171+
172+
## See also
173+
174+
* [ExtensionsToggleGroup](/Controls/ExtensionsToggleGroup.md)
175+
* [UIButton](/Controls/UIButton.md)
176+
* [Selector](/Controls/Selector.md)
177+
178+
---------
179+
180+
## Credits and Donation
181+
182+
Unity UI Extensions Contributors
183+
184+
---------
185+
186+
## External links
187+
188+
[Unity Toggle Documentation](https://docs.unity3d.com/Manual/script-Toggle.html)

Controls/ExtensionsToggleGroup.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Extensions Toggle Group
2+
3+
An enhanced ToggleGroup component that manages a group of ExtensionsToggle components, ensuring only one toggle is active at a time.
4+
5+
---------
6+
7+
## Contents
8+
9+
> 1 [Overview](#overview)
10+
>
11+
> 2 [Properties](#properties)
12+
>
13+
> 3 [Methods](#methods)
14+
>
15+
> 4 [Usage](#usage)
16+
>
17+
> 5 [Video Demo](#video-demo)
18+
>
19+
> 6 [See also](#see-also)
20+
>
21+
> 7 [Credits and Donation](#credits-and-donation)
22+
>
23+
> 8 [External links](#external-links)
24+
25+
---------
26+
27+
## Overview
28+
29+
The Extensions Toggle Group is an enhanced version of Unity's standard ToggleGroup that manages ExtensionsToggle components. It ensures that only one toggle in the group can be on at a time (unless `AllowSwitchOff` is enabled) and provides events for monitoring group state changes.
30+
31+
Key features include:
32+
33+
- **Enforced Single Selection**: Only one toggle can be selected at a time
34+
- **Optional Multi-Off Mode**: When enabled, all toggles can be off
35+
- **Dual Event System**: Separate events for group state changes and individual toggle changes
36+
- **Active Toggles Enumeration**: Access all currently active toggles in the group
37+
- **Programmatic Control**: Methods to query and control toggle states
38+
39+
---------
40+
41+
## Properties
42+
43+
The properties of the Extensions Toggle Group control are as follows:
44+
45+
Property | Description
46+
-|-
47+
*Allow Switch Off*|When true, allows all toggles in the group to be off. When false, at least one toggle must be on.
48+
***On Toggle Group Changed*** (event)|Invoked when any toggle in the group changes state, passes whether any toggles are on.
49+
***On Toggle Group Toggle Changed*** (event)|Invoked when a toggle in the group changes, passes the new boolean state.
50+
51+
### Additional properties available in code
52+
53+
Property | Return Type | Description
54+
-|-|-
55+
AllowSwitchOff|bool|Get or set whether all toggles can be off.
56+
SelectedToggle|ExtensionsToggle|Get the currently selected toggle, or null if none selected.
57+
58+
---------
59+
60+
## Methods
61+
62+
Method | Arguments | Description
63+
-|-|-
64+
*NotifyToggleOn*|toggle (ExtensionsToggle)|Internally called when a toggle becomes on. Turns off all other toggles in the group.
65+
*RegisterToggle*|toggle (ExtensionsToggle)|Register an ExtensionsToggle to be managed by this group.
66+
*UnregisterToggle*|toggle (ExtensionsToggle)|Unregister an ExtensionsToggle from this group.
67+
*AnyTogglesOn*|N/A|Returns true if at least one toggle in the group is on.
68+
*ActiveToggles*|N/A|Returns an enumerable collection of all toggles that are currently on.
69+
*SetAllTogglesOff*|N/A|Turns off all toggles in the group.
70+
71+
---------
72+
73+
## Usage
74+
75+
Add the Extensions Toggle Group component to a GameObject, typically the parent of the toggles:
76+
77+
"Add Component -> UI -> Extensions -> Extensions Toggle Group"
78+
79+
### Basic Group Setup
80+
81+
```csharp
82+
public ExtensionsToggleGroup toggleGroup;
83+
public ExtensionsToggle[] toggles;
84+
85+
void Start()
86+
{
87+
// The toggles should have their Group property set to this group
88+
// This can be done in the inspector or programmatically:
89+
foreach (var toggle in toggles)
90+
{
91+
toggle.Group = toggleGroup;
92+
}
93+
94+
// Listen to group changes
95+
toggleGroup.onToggleGroupChanged.AddListener(OnGroupChanged);
96+
}
97+
98+
void OnGroupChanged(bool anyToggleOn)
99+
{
100+
Debug.Log("Any toggle on: " + anyToggleOn);
101+
}
102+
```
103+
104+
### Accessing the Selected Toggle
105+
106+
```csharp
107+
public ExtensionsToggleGroup toggleGroup;
108+
109+
void Update()
110+
{
111+
if (Input.GetKeyDown(KeyCode.E))
112+
{
113+
var selected = toggleGroup.SelectedToggle;
114+
if (selected != null)
115+
{
116+
Debug.Log("Currently selected: " + selected.UniqueID);
117+
}
118+
}
119+
}
120+
```
121+
122+
### Allowing Multiple Off State
123+
124+
```csharp
125+
public ExtensionsToggleGroup toggleGroup;
126+
127+
void Start()
128+
{
129+
// Allow all toggles to be off
130+
toggleGroup.AllowSwitchOff = true;
131+
132+
// Now users can click the selected toggle again to deselect it
133+
}
134+
```
135+
136+
### Querying Active Toggles
137+
138+
```csharp
139+
public ExtensionsToggleGroup toggleGroup;
140+
141+
void CheckActiveToggles()
142+
{
143+
var activeToggles = toggleGroup.ActiveToggles();
144+
foreach (var toggle in activeToggles)
145+
{
146+
Debug.Log("Active toggle: " + toggle.UniqueID);
147+
}
148+
}
149+
```
150+
151+
### Controlling Toggles Programmatically
152+
153+
```csharp
154+
public ExtensionsToggleGroup toggleGroup;
155+
public ExtensionsToggle[] optionToggles;
156+
157+
void SelectOption(int index)
158+
{
159+
if (index >= 0 && index < optionToggles.Length)
160+
{
161+
optionToggles[index].IsOn = true;
162+
// Other toggles in the group will automatically turn off
163+
}
164+
}
165+
166+
void DeselectAll()
167+
{
168+
if (toggleGroup.AllowSwitchOff)
169+
{
170+
toggleGroup.SetAllTogglesOff();
171+
}
172+
}
173+
```
174+
175+
---------
176+
177+
## Video Demo
178+
179+
Coming soon...
180+
181+
---------
182+
183+
## See also
184+
185+
* [ExtensionsToggle](/Controls/ExtensionsToggle.md)
186+
* [UIButton](/Controls/UIButton.md)
187+
* [SegmentedControl](/Controls/SegmentedControl.md)
188+
189+
---------
190+
191+
## Credits and Donation
192+
193+
Unity UI Extensions Contributors
194+
195+
---------
196+
197+
## External links
198+
199+
[Unity ToggleGroup Documentation](https://docs.unity3d.com/Manual/script-ToggleGroup.html)

0 commit comments

Comments
 (0)