=================================== GameObject and Component Extensions =================================== These extensions are quality of life features for Components and GameObjects. Currently there are only a few extensions, but in the future more features will make their way into Nut Library. These extensions are chainable. Overview -------- * :ref:`CompareParent` * :ref:`Parent, Unparent, and SetActive` * :ref:`Get Help ` **EXTENSIONS** -------------- CompareParent ------------- * ``bool CompareParent(GameObject/Component other)`` Compares the parents of both objects and returns true if they match eachother. .. code-block:: csharp :linenos: using NutTools; using UnityEngine; public class MyClass: MonoBehaviour { public GameObject obj; void MyMethod() { if (this.CompareParent(obj)) { // Do stuff… } } } Parent, Unparent, and SetActive ------------------------------- There are many variations of these extensions. They are chainable, as can be seen in the example below. * ``Parent(Transform parent)`` Sets the object's parent to "parent". * ``Unparent()`` Sets the object's parent to the scene of the root, which is essentially "null". * ``SetActive(bool state)`` - **Component-Only** Sets the component's GameObject's active state. * ``ParentAndSetActive(Transform parent, bool state)`` Sets both the object's parent and active state. * ``UnparentAndSetActive(bool state)`` Sets the object's parent to «null» and the active state to «state». .. code-block:: csharp :linenos: using NutTools; using UnityEngine; public class MyClass: MonoBehaviour { public GameObject obj; public Transform parent; void MyMethod() { obj.Parent(parent); this.Unparent(); // "this" is a component in this case (MyClass), so it's also possible to use extensions like this. obj.ParentAndSetActive(transform, false); obj.UnparentAndSetActive(true); parent.SetActive(true); // Transform is a component as well, so it's possible to call SetActive on it too. this.SetActive(false) .Parent(parent); // Chained command example. } } **** **GET HELP** ------------ `Join this Discord server `_ to get help from the community, suggest new features, and vote on future updates! .. seealso:: * :ref:`Array and List Extensions ` * :ref:`GameObject and Component Extensions ` * :ref:`Physics Extensions ` * :ref:`Texture Extensions ` * :ref:`Value Extensions ` * :ref:`Transform.SetParent()` * :ref:`GameObject.SetActive()`