Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

My Library of Editor Extensions

Discussion in 'Scripting' started by dracolytch, Nov 20, 2019.

  1. dracolytch


    Jan 1, 2016
    Hey folks,

    As I find need for little editor extensions, I add them to my little library. I'm putting this out in the public in case someone else finds them as useful as I do (or hey, it'd be cool to have them integrated into the engine) Some example useful syntax below:

    Code (CSharp):
    1. // Want to know if a layermask contains a specific layer?
    2. LayerMask.MaskContains(collision.gameObject.layer)
    Code (CSharp):
    1. // Only do something if a component exists, way more convenient than null checking
    2. // I use this syntax all the time now
    3.         gameObject.GetComponent<Rigidbody>(rb =>
    4.         {
    5.             rb.SetDensity(1f);
    6.         });

    Code (CSharp):
    1. // Send an error message if it doesn't exist
    2.         gameObject.GetComponentRequired<Rigidbody>(rb =>
    3.         {
    4.             rb.SetDensity(1f);
    5.         });
    Also pre-canned event types for ints, floats, colors, etc. These are all very simple but handy routines that help keep my code cleaner and to the point.
    BlakeSchreurs, palex-nx and Stardog like this.