Version: 2017.2
public static bool showMixedValue ;

説明

次のコントロールが与える編集する複数の異なる値の Appearance を作成します。

これはカスタムのエディターを作成するときや複数のオブジェクトの編集をサポートしながら 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