开始一个新的代码块以检查 GUI 更改。
将此与 EditorGUI.EndChangeCheck 结合使用,以创建一个代码块,该代码块检查 GUI 状态是否仅针对该块中包含的控件发生了更改。
此方法与 GUI.changed 不同,后者对 GUI 状态的任何更改都返回 true。BeginChangeCheck() 将检查限制到一组特定的控件。
using UnityEditor;
public class ExampleWindow : EditorWindow { float sliderValue = 0; string labelText = "-";
[MenuItem("Window/Example Window")] static void Init() { var example = (ExampleWindow)EditorWindow.GetWindow(typeof(ExampleWindow)); example.Show(); }
void OnGUI() { EditorGUILayout.LabelField("New value", labelText);
// Start a code block to check for GUI changes EditorGUI.BeginChangeCheck();
sliderValue = EditorGUILayout.Slider(sliderValue, 0, 1);
// End the code block and update the label if a change occurs. // Note: This indicates user interaction with the slider but does not guarantee that a SerializedProperty has changed. // To have the updated value, call serializedObject.ApplyModifiedProperties(). if (EditorGUI.EndChangeCheck()) { labelText = sliderValue.ToString(); } } }