Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LINQ to GameObject

Discussion in 'Assets and Asset Store' started by neuecc, Jan 21, 2015.

  1. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    LINQ to GameObject is GameObject extensions for Unity.
    You can traverse GameObject hierarchy tree easily and you can add GameObject to hierarchy structure easily.
    This library is free and opensource on GitHub.


    All traverse methods return IEnumerable<GameObject> and deferred exectuion. For example

    Code (CSharp):
    1. origin.Ancestors();   // Container, Root
    2. origin.Children();    // Sphere_A, Sphere_B, Group, Sphere_A, Sphere_B
    3. origin.Descendants(); // Sphere_A, Sphere_B, Group, P1, Group, Sphere_B, P2, Sphere_A, Sphere_B
    4. origin.BeforeSelf(); // C1, C2
    5. origin.AfterSelf();  // C3, C4
    Now available on the Asset Store(FREE)
    http://u3d.as/content/neuecc/linq-to-game-object

    Source and Issue tracking.
    https://github.com/neuecc/LINQ-to-GameObject-for-Unity

    Please ask me any questions in this thread.
     
  2. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    you're just a Monster-man! :)
     
  3. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Today accepted update release, ver 1.2!

    This release completely compatibled uGUI's RectTransform.
    You can Add/Move RectTransform.
     
  4. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Today accepted update release, ver 1.3!

    Destroy use SetParent(null) after UNITY 4.6.
    It can avoid runtime warning.
     
  5. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    372
    How does this look in terms of GC? Mono's implementation of LINQ has typically been quite average in the past.
     
  6. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    All traverse methods implement by using yield return.
    Its implementation is simple.
    But you maybe use with LINQ to Objects on Mono implements.
    Performance is same as.
    If you worried about it, always use ToList() at first...
     
  7. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Hi, I've uploaded ver 2.0!

    More useful but including some breaking changes(and changes icon)

    * Add/Move methods can accept `Component` and returns T as self component type
    * Rename Add(IEnumerbale) methods to AddRange
    * Changes Destroy was added `bool detachParent` option and default does not detach from parent.
    * Changes Add was added `bool setLayer` and default does not set layer.
    * AddRanges returns `T[]` instead of `List<T>`
    * Remove GameObjectBuilder
     
  8. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Today accepted ver 2.1.2
    I've tried crazy hand optimized struct enumerator and optimize helper(ToArrayNonAlloc).

    * Optimized Traverse methods with hand optimized struct enumerator
    * Add ToArrayNonAlloc for non allocate query
    * Add ForEach to LINQ to GameObject's enumerable
    * First, FirstOrDefault, ToArray, OfComponent, Destroy was optimized when use directly
    * Braking Changes: remove name filter of traverse methods.

    LINQ to GameObject now aims both power of LINQ and **performance** of iteration.
    LINQ to GameObject guarantees no gc allocate if run on optimized path.
    see the ReadMe's performance section https://github.com/neuecc/LINQ-to-GameObject-for-Unity#performance-tips
     
  9. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Today accepted new version,but sorry I create package by 5.5 beta.
    I need to use Unity 5.0, I'll re-package and upload soon.
     
  10. neuecc

    neuecc

    Joined:
    Apr 20, 2014
    Posts:
    114
    Published 2.2 on AssetStore.

    ```
    Add: Descendants/DescendantsSelf(descendIntoChildren) overload
    Add: IEnumerable.Destroy(detachParent) overload
    Performance Optimize: Children().ToArray() by use fixed array
    Performance Optimize: Children().Destroy(detachParent) by use transform.DetachChildren
    ```

    I've started medium in English, I've written more details about this update.
    https://medium.com/@neuecc/update-unirx-5-4-1-and-linq-to-gameobject-2-2-d89005be55f6#.d99uucqfj
    Please check it and follow me.
     
    ggzerosum and CheekySparrow78 like this.
  11. ggzerosum

    ggzerosum

    Joined:
    Sep 26, 2017
    Posts:
    32
    I Love your coding style. Keep it up
     
  12. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Surprisingly, this package still works perfectly in Unity 2020.1.

    It's great for constructing GameObjects at runtime, piece by piece, in order to apply specific ECS authoring components to child objects easily.