private void ValidateToggleIsInGroup(BlockToggle toggle) { if (toggle == null || !m_Toggles.Contains(toggle)) { throw new ArgumentException(string.Format("Toggle {0} is not part of ToggleGroup {1}", new object[] { toggle, this })); } }
/// <summary> /// Unregister a toggle from the group. /// </summary> /// <param name="toggle">The toggle to remove.</param> public void UnregisterToggle(BlockToggle toggle) { if (m_Toggles.Contains(toggle)) { m_Toggles.Remove(toggle); } if (!allowSwitchOff && !AnyTogglesOn() && m_Toggles.Count != 0) { m_Toggles[0].isOn = true; NotifyToggleOn(m_Toggles[0]); } }
/// <summary> /// Register a toggle with the toggle group so it is watched for changes and notified if another toggle in the group changes. /// </summary> /// <param name="toggle">The toggle to register with the group.</param> public void RegisterToggle(BlockToggle toggle) { if (!m_Toggles.Contains(toggle)) { m_Toggles.Add(toggle); } if (!allowSwitchOff && !AnyTogglesOn()) { toggle.isOn = true; NotifyToggleOn(toggle); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUILayout.Space(); serializedObject.Update(); BlockToggle toggle = serializedObject.targetObject as BlockToggle; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_IsOnProperty); if (EditorGUI.EndChangeCheck()) { EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene); BlockToggleGroup group = m_GroupProperty.objectReferenceValue as BlockToggleGroup; toggle.isOn = m_IsOnProperty.boolValue; if (group != null && toggle.IsActive()) { if (toggle.isOn || (!group.AnyTogglesOn() && !group.allowSwitchOff)) { toggle.isOn = true; group.NotifyToggleOn(toggle); } } } EditorGUILayout.PropertyField(m_TransitionProperty); EditorGUILayout.PropertyField(m_GraphicProperty); EditorGUILayout.PropertyField(m_Rows); EditorGUILayout.PropertyField(m_Columns); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_GroupProperty); if (EditorGUI.EndChangeCheck()) { EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene); BlockToggleGroup group = m_GroupProperty.objectReferenceValue as BlockToggleGroup; toggle.group = group; } EditorGUILayout.Space(); // Draw the event notification options EditorGUILayout.PropertyField(m_OnValueChangedProperty); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Notify the group that the given toggle is enabled. /// </summary> /// <param name="toggle">The toggle that got triggered on</param> public void NotifyToggleOn(BlockToggle toggle, bool sendCallback = true) { ValidateToggleIsInGroup(toggle); // disable all toggles in the group for (var i = 0; i < m_Toggles.Count; i++) { if (m_Toggles[i] == toggle) { continue; } if (sendCallback) { m_Toggles[i].isOn = false; } else { m_Toggles[i].SetIsOnWithoutNotify(false); } } }