Real-Serious-Games/Unity-Scene-Query

Request: Support property values in queries

Zenopheus opened this issue · 3 comments

It would be great to select on game object property values. I'm not sure what the best approach is.
Some examples:

// Find all children under Foo that are enabled
var xxx = root.SelectAll("Foo[go('activeSelf') == true]");

// Find all children under Foo whose y position is less than 1
var xxx = root.SelectAll("Foo[trans('position', 'y') < 1]");

Both of these can be achieved by using LINQ as scene query returns an IEnumerable for SelectAll or a GameObject for SelectOne. In this case we will use the SelectOne and then use the Children function to get an IEnumerable of all child game objects.

So assuming foo is a root object we can do the following.

// Find all children under Foo that are enabled

var results = SceneQuery.SelectOne("/Foo")
    .Children()
    .Where(go => go.activeSelf);

// Find all children under Foo whose y position is less than 1

var results = SceneQuery.SelectOne("/Foo")
    .Children()
    .Where(go => go.transform.position.y < 1.0f);

It looks much nicer that way but unfortunately I need to do this via a string in the inspector (for non-programmers).

Sorry I missed the intended use you were looking for however Unity Scene Query was created to be used by programmers. What you are suggesting while interesting does not fall under the intended scope or our day to day use.

If you implement such a feature we are open to pull requests.