Singularity/Library/PackageCache/com.unity.ugui@1.0.0/Editor/UI/ToggleEditor.cs
2024-05-06 11:45:45 -07:00

81 lines
2.9 KiB
C#

using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Toggle), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Toggle Component.
/// Extend this class to write a custom editor for a component derived from Toggle.
/// </summary>
public class ToggleEditor : SelectableEditor
{
SerializedProperty m_OnValueChangedProperty;
SerializedProperty m_TransitionProperty;
SerializedProperty m_GraphicProperty;
SerializedProperty m_GroupProperty;
SerializedProperty m_IsOnProperty;
protected override void OnEnable()
{
base.OnEnable();
m_TransitionProperty = serializedObject.FindProperty("toggleTransition");
m_GraphicProperty = serializedObject.FindProperty("graphic");
m_GroupProperty = serializedObject.FindProperty("m_Group");
m_IsOnProperty = serializedObject.FindProperty("m_IsOn");
m_OnValueChangedProperty = serializedObject.FindProperty("onValueChanged");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
Toggle toggle = serializedObject.targetObject as Toggle;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_IsOnProperty);
if (EditorGUI.EndChangeCheck())
{
if (!Application.isPlaying)
EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene);
ToggleGroup group = m_GroupProperty.objectReferenceValue as ToggleGroup;
toggle.isOn = m_IsOnProperty.boolValue;
if (group != null && group.isActiveAndEnabled && toggle.IsActive())
{
if (toggle.isOn || (!group.AnyTogglesOn() && !group.allowSwitchOff))
{
toggle.isOn = true;
group.NotifyToggleOn(toggle);
}
}
}
EditorGUILayout.PropertyField(m_TransitionProperty);
EditorGUILayout.PropertyField(m_GraphicProperty);
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_GroupProperty);
if (EditorGUI.EndChangeCheck())
{
if (!Application.isPlaying)
EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene);
ToggleGroup group = m_GroupProperty.objectReferenceValue as ToggleGroup;
toggle.group = group;
}
EditorGUILayout.Space();
// Draw the event notification options
EditorGUILayout.PropertyField(m_OnValueChangedProperty);
serializedObject.ApplyModifiedProperties();
}
}
}