Version: 2017.1

EditorGUI.showMixedValue

切换到手册
public static bool showMixedValue ;

描述

使后续控件呈现出编辑多个不同值的外观。

如果您想要创建自定义编辑器,在 GUI 中以非标准方式表示值, 同时还支持多对象编辑,此属性可能会非常有用。

// This example shows a custom inspector for an object "MyVessel".
// MyVessel has a boolean variable isFast but we want to show it
// as a dropdown instead of as a toggle.

enum SpeedOption { Slow, Fast }

@CustomEditor (MyVessel) @CanEditMultipleObjects class MyVesselEditor extends Editor { var isFastProp : SerializedProperty;

function OnEnable () { isFastProp = serializedObject.FindProperty ("isFast"); }

function OnInspectorGUI () { serializedObject.Update ();

// Show the isFast boolean the standard way - as a toggle: EditorGUILayout.PropertyField (isFastProp);

// Show the isFast boolean as a dropdown using the SpeedOption enum defined above:

// Check if the value was changed inside this block EditorGUI.BeginChangeCheck ();

// If the isFast property represent multiple different values, the dropdown should show that: EditorGUI.showMixedValue = isFastProp.hasMultipleDifferentValues;

// Convert the isFast boolean to an enum value var speedOptionEnumValue : SpeedOption; if (isFastProp.boolValue == true) speedOptionEnumValue = SpeedOption.Fast; else speedOptionEnumValue = SpeedOption.Slow;

// Present the enum value in a dropdown: speedOptionEnumValue = EditorGUILayout.EnumPopup ("Speed", speedOptionEnumValue);

// Set showMixedValue to false so it doesn't affect the following controls, if any: EditorGUI.showMixedValue = false;

// If the value was changed inside this block, apply the new value to all the objects: if (EditorGUI.EndChangeCheck ()) isFastProp.boolValue = (speedOptionEnumValue == SpeedOption.Fast ? true : false);

serializedObject.ApplyModifiedProperties (); } }
// This is the MyVessel script used above

var isFast : boolean = false;

function Update () { // Update logic here... }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961