Search Unity

Setting filters on ObjectField ObjectPicker

Discussion in 'Immediate Mode GUI (IMGUI)' started by Sangemdoko, Aug 21, 2019.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    51
    Hello,

    I would like to set the filter of the objectPicker of an ObjectField in a custom Inspector. The reason is that I want to only show the assets that have a certain Asset label. The reason being that I organize my objects per category and I can easily set the category name as an asset label.

    When I create my own objectPicker I can do this using this function:
    Code (CSharp):
    1. EditorGUIUtility.ShowObjectPicker<MyScriptableObject>(null, false, string.Format("l:{0}", myCategoryName), 0);
    It would be great if there was a filter property on ObjectField so that I could do this:
    Code (CSharp):
    1. myObjectField.filter = string.Format("l:{0}", myCategoryName) ;
    If there is any way of setting the filter of the ObjectPicker when it is open from a certain ObjectField, please let me know as I haven't found a workaround yet.
     
    Xarbrough likes this.
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,286
    This sounds great, though I would want the filter to be a Func<Object, bool> so the filter can be an arbitrary check rather than just exactly a filter for an asset label.
     
  3. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    51
    That would be even better!
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    295