UnityQuery is a small, lightweight C# library designed to increase productivity with Unity3D.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Documentation
Media
Source/UnityQuery
.gitignore
CONTRIBUTING.md
FAQ.md
LICENSE
README.md

README.md

UnityQuery

UnityQuery is a small, lightweight C# library designed to increase productivity with Unity3D.

Each and every one of us has written these small utility and extension methods we're using and re-writing over and over again with each new project. UnityQuery aims to collect the most general, versatile and helpful of these code snippets for re-use, and is inspired by recent work at the Slash Framework and by LINQ to GameObject by Yoshifumi Kawai.

If you're missing any of your personal favorites, we'd love to see it - please refer to the Contributing file!

Features

  • Hierarchy queries (e.g. GetChildren, GetDescendants, OnLayer, IsAncestor, GetRoot, ...)
  • Hierarchy manipulation (e.g. DestroyChildren)
  • Component-wise vector swizzling (e.g. v.XZ)
  • Changing single vector or color components while preserving immutability
  • Picking (e.g. object at mouse position)
  • Collection extensions (e.g. ContainsAll, GetValueOrDefault, IsNullOrEmpty, SequenceToString)
  • Logs with timestamps and object names

Getting UnityQuery

You can either

Usage

Just import the UnityQuery namespace and you're good to go!

using UnityQuery;

The library adds many hierarchy queries to your game objects.

// Select all descendants(children, grandchildren, etc.).
foreach (var descendant in this.gameObject.GetDescendants())
{
    // ...
}

You can freely re-combine these queries with other library methods.

// Change the layers of all default layer descendants to UI.
this.gameObject
    .GetDescendants()
    .OnLayer("Default")
    .AsQuery()
    .SetLayers("UI");

Right now, all of the UnityQuery methods are implemented as extension methods.

// u = (1, 2, 3)
Vector3 u = new Vector3(1, 2, 3);

// v = (1, 3)
Vector2 v = u.XZ();

That means, you can use all of them as syntatic sugar without having to recall where they're located.

var o = Camera.main.PickObject();

Note there's also a Cheat Sheet available for you.

Development Cycle

We know that using a library like UnityQuery in production requires you to be completely sure about stability and compatibility. Thus, new releases of UnityQuery are created using Semantic Versioning. In short:

  • Version numbers are specified as MAJOR.MINOR.PATCH.
  • MAJOR version increases indicate incompatible changes with respect to the public UnityQuery API.
  • MINOR version increases indicate new functionality that are backwards-compatible.
  • PATCH version increases indicate backwards-compatible bug fixes.

Bugs & Feature Requests

We are sorry that you've experienced issues or are missing a feature! After verifying that you are using the latest version of UnityQuery and having checked whether a similar issue has already been reported, feel free to open a new issue. In order to help us resolving your problem as fast as possible, please include the following details in your report:

  • Steps to reproduce
  • What happened?
  • What did you expect to happen?

After being able to reproduce the issue, we'll look into fixing it immediately.

Contributors

(in no particular order)

License

UnityQuery is released under the MIT license.