Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hierarchy search field filters legend

Discussion in 'Editor & General Support' started by Neogene, Jul 14, 2015.

  1. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    93
    Hi,

    is available a list of supported "filters"/"keys" for the Hierarchy search field?

    I want to spot am "Invalid AABB result" probably due to a negative scale for a UGUI component but there are too many and i want to get a list of only rect transform UGI components (the top will be only those with a neg scale).

    thank you.
     
  2. Sarinen

    Sarinen

    Joined:
    Nov 4, 2014
    Posts:
    6
    You can search any component in the scene by entering the name of a component, so in your case it would be RectTransform.
     
    Neogene likes this.
  3. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    93
    Thank you, i'm searching a way to do a search like: "field name".value<x
     
  4. Sarinen

    Sarinen

    Joined:
    Nov 4, 2014
    Posts:
    6
    I don't think there is a built-in functionality like this, but you could probably write a simple editor script, just iterate through game objects on the scene -> get component you want -> check values -> add to selection. Something like this:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class cSelectWithValue : EditorWindow
    7. {
    8.     [ MenuItem("Custom/Select with value") ]
    9.     public static void SelectWithValue()
    10.     {
    11.         Selection.objects = new Object[0];
    12.         m_Selection.Clear ();
    13.         m_ScrollPosition = new Vector2 ();
    14.         EditorWindow.GetWindow<cSelectWithValue>(false, "Select with value", true);
    15.     }
    16.  
    17.     static string m_FieldValue = "";
    18.     static List<Object> m_Selection = new List<Object> ();
    19.     static Vector2 m_ScrollPosition = new Vector2();
    20.  
    21.     void OnGUI()
    22.     {
    23.         EditorGUILayout.Space();
    24.  
    25.         EditorGUILayout.BeginHorizontal ();
    26.         EditorGUILayout.LabelField ("Search for value (less than): ");
    27.  
    28.         m_FieldValue = EditorGUILayout.TextField (m_FieldValue);
    29.  
    30.         EditorGUILayout.EndHorizontal ();
    31.         EditorGUILayout.Space ();
    32.  
    33.         if( GUILayout.Button ("Select") )
    34.         {
    35.             float fValue = 0.0f;
    36.  
    37.             if( float.TryParse( m_FieldValue, out fValue ) )
    38.             {
    39.                 m_Selection.Clear();
    40.                 FindAndSelect( fValue );
    41.             }
    42.         }
    43.  
    44.         EditorGUILayout.BeginVertical ();
    45.         m_ScrollPosition = EditorGUILayout.BeginScrollView ( m_ScrollPosition );
    46.  
    47.         if( m_Selection.Count > 0 )
    48.         {
    49.             for( int i = 0; i < m_Selection.Count; i++ )
    50.             {
    51.                 EditorGUILayout.ObjectField(m_Selection[i].name, (Object)m_Selection[i], typeof(GameObject), true);
    52.             }
    53.         }
    54.  
    55.         EditorGUILayout.EndScrollView ();
    56.         EditorGUILayout.EndVertical ();
    57.     }
    58.  
    59.     static void FindAndSelect( float fValue )
    60.     {
    61.         GameObject[] objectsOnScene = GameObject.FindObjectsOfType<GameObject>();
    62.  
    63.         for( int i = 0; i < objectsOnScene.Length; i++ )
    64.         {
    65.             RectTransform rectTransform = objectsOnScene[i].GetComponent<RectTransform>();
    66.  
    67.             if( rectTransform && rectTransform.localScale.x < fValue )
    68.             {
    69.                 m_Selection.Add( objectsOnScene[i] );
    70.             }
    71.         }
    72.     }
    73. }
     
    Last edited: Jul 14, 2015
    Neogene likes this.
  5. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    93
    Really nice i'll test asap!
     
  6. Sarinen

    Sarinen

    Joined:
    Nov 4, 2014
    Posts:
    6
    Just keep in mind that it can find only active game objects.
     
  7. webster

    webster

    Joined:
    Jun 8, 2013
    Posts:
    21
    Any way to make this more generic? Like any string value on any component matching a given string?