A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.unity3d.com/Manual/../ScriptReference/EditorGUIUtility.ShowObjectPicker.html below:

Unity - Scripting API: EditorGUIUtility.ShowObjectPicker

EditorGUIUtility.ShowObjectPicker Suggest a change Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close Your name Your email Suggestion*

Cancel

Declaration

public static void

ShowObjectPicker

(

Object obj

, bool

allowSceneObjects

, string

searchFilter

, int

controlID

);

Parameters Parameter Description obj The object to be selected by default. allowSceneObjects Is selection of Scene objects allowed, or should it only show assets. searchFilter The default search filter to apply. This is the initial search query text that applies when the object picker is opened. controlID The id of the control to set. This is useful if you are showing more than one of these. You can get the value at a later time. Description

Show the object picker from code.

<T>: The type of objects that are available to pick in the object picker.

Once the user interacts with the object picker, it responds by sending ExecuteCommand events back to the OnGUI that called this function. The messages are:

Here is an example of how it could be called for any control during an OnGUI call:

static void CallShowPicker<T>(UnityEngine.Object currentObjectValue, int currentControlId) where T : UnityEngine.Object
{
    // Show an object picker with the `currentObjectValue` selected. We pass true to allow
    // scene objects. We set the initial search query string to an empty string. The `currentControlId`
    // is passed to us during the OnGUI call, for any object field or other control that needs to show the object picker.
    EditorGUIUtility.ShowObjectPicker<T>(currentObjectValue, true, "", currentControlId);
}

Here is how an object field that uses the previous method could be setup during an OnGUI call:

public static void DoObjectField(Rect position, SerializedProperty property, Type objType, GUIContent label)
{
    label = EditorGUI.BeginProperty(position, label, property);
    // Generate a controlId for this object field. Use a unique hint integer for correct matching of controls.
    var controlId = GUIUtility.GetControlID("Example_EditorGUIUtility_ShowObjectPicker".GetHashCode(), FocusType.Keyboard, position);
    position = EditorGUI.PrefixLabel(position, controlId, label);
    DoObjectField(position, position, controlId, objType, property);
    EditorGUI.EndProperty();
}

Finally, here is how you could handle the ExecuteCommand events during an OnGUI call:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4