forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleGroup.cs
More file actions
117 lines (106 loc) · 3.48 KB
/
ToggleGroup.cs
File metadata and controls
117 lines (106 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Decompiled with JetBrains decompiler
// Type: UnityEngine.UI.ToggleGroup
// Assembly: UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 2216A18B-AF52-44A5-85A0-A1CAA19C1090
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.UI.dll
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.EventSystems;
namespace UnityEngine.UI
{
/// <summary>
/// <para>A component that represents a group of Toggles.</para>
/// </summary>
[DisallowMultipleComponent]
[AddComponentMenu("UI/Toggle Group", 32)]
public class ToggleGroup : UIBehaviour
{
private List<Toggle> m_Toggles = new List<Toggle>();
[SerializeField]
private bool m_AllowSwitchOff;
/// <summary>
/// <para>Is it allowed that no toggle is switched on?</para>
/// </summary>
public bool allowSwitchOff
{
get
{
return this.m_AllowSwitchOff;
}
set
{
this.m_AllowSwitchOff = value;
}
}
protected ToggleGroup()
{
}
private void ValidateToggleIsInGroup(Toggle toggle)
{
if ((UnityEngine.Object) toggle == (UnityEngine.Object) null || !this.m_Toggles.Contains(toggle))
throw new ArgumentException(string.Format("Toggle {0} is not part of ToggleGroup {1}", new object[2]{ (object) toggle, (object) this }));
}
/// <summary>
/// <para>Notify the group that the given toggle is enabled.</para>
/// </summary>
/// <param name="toggle"></param>
public void NotifyToggleOn(Toggle toggle)
{
this.ValidateToggleIsInGroup(toggle);
for (int index = 0; index < this.m_Toggles.Count; ++index)
{
if (!((UnityEngine.Object) this.m_Toggles[index] == (UnityEngine.Object) toggle))
this.m_Toggles[index].isOn = false;
}
}
/// <summary>
/// <para>Toggle to unregister.</para>
/// </summary>
/// <param name="toggle">Unregister toggle.</param>
public void UnregisterToggle(Toggle toggle)
{
if (!this.m_Toggles.Contains(toggle))
return;
this.m_Toggles.Remove(toggle);
}
/// <summary>
/// <para>Register a toggle with the group.</para>
/// </summary>
/// <param name="toggle">To register.</param>
public void RegisterToggle(Toggle toggle)
{
if (this.m_Toggles.Contains(toggle))
return;
this.m_Toggles.Add(toggle);
}
/// <summary>
/// <para>Are any of the toggles on?</para>
/// </summary>
public bool AnyTogglesOn()
{
return (UnityEngine.Object) this.m_Toggles.Find((Predicate<Toggle>) (x => x.isOn)) != (UnityEngine.Object) null;
}
/// <summary>
/// <para>Returns the toggles in this group that are active.</para>
/// </summary>
/// <returns>
/// <para>The active toggles in the group.</para>
/// </returns>
public IEnumerable<Toggle> ActiveToggles()
{
return this.m_Toggles.Where<Toggle>((Func<Toggle, bool>) (x => x.isOn));
}
/// <summary>
/// <para>Switch all toggles off.</para>
/// </summary>
public void SetAllTogglesOff()
{
bool allowSwitchOff = this.m_AllowSwitchOff;
this.m_AllowSwitchOff = true;
for (int index = 0; index < this.m_Toggles.Count; ++index)
this.m_Toggles[index].isOn = false;
this.m_AllowSwitchOff = allowSwitchOff;
}
}
}