All Projects → Real-Serious-Games → Unity Scene Query

Real-Serious-Games / Unity Scene Query

Licence: mit
A library to traverse and query the Unity scene to find particular objects, uses something similar to CSS selectors to identify game objects.

Projects that are alternatives of or similar to Unity Scene Query

Unity Wireframe
General purpose wireframe shaders for use in Unity.
Stars: ✭ 378 (+500%)
Mutual labels:  unity, unity3d, game-development
Ecs
LeoECS is a fast Entity Component System (ECS) Framework powered by C# with optional integration to Unity
Stars: ✭ 578 (+817.46%)
Mutual labels:  unity, unity3d, game-development
Verticaldissolve
Procedural vertical dissolve shader. Highly customizable. Tweak edge color, noisiness & waviness, rim light, emission scrolling and more.
Stars: ✭ 434 (+588.89%)
Mutual labels:  unity, unity3d, game-development
Ksframework
QQ Group:538722494,KSFramework = KEngine + SLua(or xLua) , Unity3D Framework/Toolsets focus on hot reload
Stars: ✭ 1,119 (+1676.19%)
Mutual labels:  unity, unity3d, game-development
C Sharp Promise
Promises library for C# for management of asynchronous operations.
Stars: ✭ 870 (+1280.95%)
Mutual labels:  unity, unity3d, game-development
Unity2d Components
A constantly evolving array of Unity C# components for 2D games, including classes for pixel art cameras, events & messaging, saving & loading game data, collision handlers, object pools, and more.
Stars: ✭ 375 (+495.24%)
Mutual labels:  unity, unity3d, game-development
Texturepanner
This repository hosts a shader for Unity3D whose main goal is to facilitate the creation of neon-like signs, conveyor belts and basically whatever based on scrolling textures
Stars: ✭ 528 (+738.1%)
Mutual labels:  unity, unity3d, game-development
Spheredissolve
Customizable procedural spherical dissolve shader for Unity3D, for all your customizable procedural spherical dissolve needs!
Stars: ✭ 311 (+393.65%)
Mutual labels:  unity, unity3d, game-development
Number Wizard Ui Original
Introducing basic User Interface in the Complete Unity C# Developer 2D course (http://gdev.tv/cudgithub)
Stars: ✭ 18 (-71.43%)
Mutual labels:  unity, unity3d, game-development
Radialprogressbar
Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc!
Stars: ✭ 714 (+1033.33%)
Mutual labels:  unity, unity3d, game-development
Factory
Factory for object creation and dependency injection. Works with normal C# apps or under Unity3d
Stars: ✭ 50 (-20.63%)
Mutual labels:  unity, unity3d, game-development
X Postprocessing Library
Unity Post Processing Stack Library | Unity引擎的高品质后处理库
Stars: ✭ 1,079 (+1612.7%)
Mutual labels:  unity, unity3d, game-development
Game Networking Resources
A Curated List of Game Network Programming Resources
Stars: ✭ 4,208 (+6579.37%)
Mutual labels:  unity, unity3d, game-development
Starforce
This is a demo made with Game Framework.
Stars: ✭ 375 (+495.24%)
Mutual labels:  unity, unity3d, game-development
Crystalai
A Utility AI for C# and Unity
Stars: ✭ 328 (+420.63%)
Mutual labels:  unity, unity3d, game-development
Fontainebleaudemo
Fontainebleau demo
Stars: ✭ 524 (+731.75%)
Mutual labels:  unity, unity3d, game-development
Ecsrx
A reactive take on the ECS pattern for .net game developers
Stars: ✭ 288 (+357.14%)
Mutual labels:  unity, unity3d, game-development
Libplanet
Blockchain core in C#/.NET for persistent peer-to-peer online games
Stars: ✭ 293 (+365.08%)
Mutual labels:  unity, unity3d, game-development
Unitygameframework
This is literally a game framework, based on Unity game engine. It encapsulates commonly used game modules during development, and, to a large degree, standardises the process, enhances the development speed and ensures the product quality.
Stars: ✭ 617 (+879.37%)
Mutual labels:  unity, unity3d, game-development
Beaverandfairies
Stars: ✭ 14 (-77.78%)
Mutual labels:  unity, unity3d, game-development

Unity Scene Query

NuGet

A library to traverse and query the Unity scene to find particular game objects.

A query language is used to identify game objects, it looks something similar to CSS selectors.

For in depth coverage please read the article on What Could Possibly Go Wrong.

Examples

This repo contains some examples.

More examples of scene traversal: https://github.com/Real-Serious-Games/Unity-Scene-Traversal-Examples.

More examples of scene query: https://github.com/Real-Serious-Games/Unity-Scene-Query-Examples.

Setup in Unity

Include the DLL or source code in your Unity project.

Include the namespace in your code:

using RSG.Scene.Query;

Instantiate SceneTraversal and/or SceneQuery depending on what you want to use:

var sceneTraversal = new SceneTraversal();

var sceneQuery = new SceneQuery();

Scene Traversal

Enumerate root objects in the hierarchy:

foreach (var gameObject in sceneTraversal.RootNodes())
{
	// ...
}

Enumerate all objects using a pre-order tree traveral:

foreach (var gameObject in sceneTraversal.PreOrderHierarchy())
{
	// ...
}

There are also functions for bread-first (BreadthFirst), post-order (PostOrderHierarchy) and just leaf nodes (HierarchyLeafNodes).

Enumerate children of a particular game object:

GameObject someGameObject = ...
foreach (var childGameObject in sceneTraversal.Children(someGameObject)) 
{
	// ..
}

Enumerate all descendents (children, grand-children, etc) of a particular game object:

GameObject someGameObject = ...
foreach (var descendentGameObject in sceneTraversal.Descendents(someGameObject)) 
{
	// ..
}

Enumerate all ancestors (parent, grand-parent, etc) of a particular game object:

GameObject someGameObject = ...
foreach (var ancestorGameObject in sceneTraversal.Ancestors(someGameObject)) 
{
	// ..
}

Game Object Selectors

The query language allows you to identify the game objects to find.

If you are a language nerd please see the EBNF(-ish) grammar at the of the readme, otherwise I'll try and explain it in simpler terms here.

Game object(s) can be queried by name simply by specifying the name, for example to query for all objects named pickup-truck use:

pickup-truck

Note that the queries are case-insensitive.

A question mark activates the regular expression matching. You can use this to for partial name matching, for example to query for all objects that contain truck:

?truck

The question mark is much more powerful than just partial name matching. It can match using the full power of .NET regular expressions. For example to patch all game objects whose names start with pickup and end in truck (with anything in between):

?^pickup.*truck$

A leading slash matches objects that are at the root of the hierarchy, for example to query for a game object pickup-truck that is a root object:

/pickup-truck

Slashes can also be used, like a file-system path, to specify a path through the Unity hierarchy to particular game object(s), for instance to find all game objects named pickup-truck that are under active which is under vehicles:

/vehicles/active/pickup-truck

The greater-than symbol can be used in place of slashes to find particular game object(s) that are nested somewhere under other game objects, for example to find game objects named pickup-truck anywhere in the hierarchy under objects called vehicles:

vehicles>pickup-truck

We can query for game object(s) by Unity layer or tag by placing a fullstop before the layer/tag name:

.vehicle

Layers and tags can be combined for a more restrictive query:

.vehicle.driveable

The game object name can be also be combined with layers and tags for an even more restrictive query:

pickup-truck.vehicle.driveable

An exclamation mark can be added to invert the query, for example this will query for anything that is not a vehicle:

!.vehicle

A hash character can be used to query for a single object by unique-id, this could be more useful but Unity game object IDs seem to change arbitrarily when you aren't expecting it:

#543253

Note that only a single name, partial name or id can be used in any compound selector. The following is illegal:

pickup-truck sports-coupe

However name/id can be combined with tags and layers as previously illustrated.

Multiple names can be used with the slash or greater-than operators so these will denote a parent-child relation between different objects.

Query for Single Game Object

SelectOne returns the first game object that matches your specified selector.

Example of getting a game object by name:

var myTruck = sceneQuery.SelectOne("pickup-truck");
if (myTruck != null) 
{
	// found it!
}

Query for Multiple Game Objects

SelectAll is used to enumerate the collection of game objects that matches your specified selector.

Example of getting a game object by name and layers:

var myTrucks = sceneQuery.SelectAll("pickup-truck.vehicle.driveable");
foreach (var truck in myTrucks)
{
	// got a truck!
}

EBNF

The grammar for the query language specified in EBNF(-ish) format.

 query 
   = descendents_selector
   ;

 descendents_selector
   = ['/'] compound_selector { ('/' | '>') compound_selector }
   ;

 compound_selector
   = selector { selector }
   ;

 selector
   = '.' matcher            -> Match by layer or tag.
   | UNIQUE_ID              -> Match by unique id.
   | '!' selector           -> Invert query and matching everything except...
   |  matcher               -> Match a game object.
   ;

 matcher
   = name                   -> Match exact name.
   | '?' name               -> Match partial name/regular expression.
   ;   

 name
   = character_sequence
   | quoted_character_sequence
   ;

 quoted_character_sequence
   = '"' character_sequence_with_spaces '"'
   ;

 UNIQUE_ID
   = '#' character_sequence
   ;

Road map

  • Operators for AND and OR.
  • Possibly need parenthesis to resolve precedence.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].