Skip to content

Commit f2c2982

Browse files
committed
docs: add latest feature documentation
1 parent 512b6f6 commit f2c2982

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

README.md

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ openupm add com.mygamedevtools.extensions
5858
Usage
5959
---
6060

61-
This package is focused in 3 main areas: Extensions, Simple Tools and Attributes. The purpose of these tools, are to improve the overall Unity Editor experience
61+
This package is focused in 3 main areas: Extensions, Tooling and Attributes. The purpose of these tools, are to improve the overall Unity Editor experience
6262
with simple, reliable and maintainable solutions.
6363

6464
### :large_blue_diamond: Attributes
@@ -106,7 +106,7 @@ public class MyClass : MonoBehaviour
106106
}
107107
```
108108

109-
### :large_blue_diamond: Tools
109+
### :large_blue_diamond: Tooling
110110

111111
We have **two** tools available:
112112

@@ -154,7 +154,7 @@ public static class CheatsEnabler
154154

155155
### :large_blue_diamond: Extensions
156156

157-
We have a total of **2** extensions available:
157+
We have a total of **3** extensions available:
158158

159159
#### :large_orange_diamond: Debug Extensions
160160

@@ -198,10 +198,9 @@ public class MyClass : MonoBehaviour
198198
}
199199
```
200200

201-
##### :diamond_shape_with_a_dot_inside: Destroy Objects
201+
##### :diamond_shape_with_a_dot_inside: Destroy Components
202202

203-
Destroys any given array of `UnityEngine.Object` inherited objects, like `MonoBehaviour`, `Component` or `GameObject` types. Pretty cool, right?
204-
You can also use its siblings: `DestroyAllComponentsOfType` and `DestroyAllChildrenComponentsOfType`
203+
Destroys the given component type instances in a `UnityEngine.GameObject` or its children.
205204

206205
```csharp
207206
public class MyClass : MonoBehaviour
@@ -210,15 +209,44 @@ public class MyClass : MonoBehaviour
210209
GameObject[] myObjectsToDestroy;
211210

212211
void Start()
213-
{
214-
GameObjectExtensions.DestroyObjects(myObjectsToDestroy);
215-
212+
{
216213
gameObject.DestroyAllComponentsOfType<BoxCollider>();
217214
gameObject.DestroyAllChildrenComponentsOfType<SphereCollider>();
218215
}
219216
}
220217
```
221218

219+
##### :diamond_shape_with_a_dot_inside: Get Root Game Objects
220+
221+
Gets the root game objects of a scene, or optionally all scenes.
222+
223+
```cs
224+
public class MyClass : MonoBehaviour
225+
{
226+
void Start()
227+
{
228+
List<GameObject> allRootObjects = GameObjectExtensions.GetRootGameObjects(true);
229+
}
230+
}
231+
```
232+
233+
##### :diamond_shape_with_a_dot_inside: Has Layer
234+
235+
Checks if a `LayerMask` contains the given layer index. Useful for physics validations.
236+
237+
```cs
238+
public class MyClass : MonoBehaviour
239+
{
240+
[SerializeField]
241+
LayerMask _mask;
242+
243+
void Start()
244+
{
245+
Debug.Log(_mask.HasLayer(gameObject.layer));
246+
}
247+
}
248+
```
249+
222250
##### :diamond_shape_with_a_dot_inside: Delay Call
223251

224252
Delays an Action after a given amount of time. You can delay in seconds, frames or physics (fixed) frames.
@@ -244,6 +272,51 @@ public class MyClass : MonoBehaviour
244272
}
245273
```
246274

275+
#### :large_orange_diamond: Object Extensions
276+
277+
##### :diamond_shape_with_a_dot_inside: Destroy Objects
278+
279+
Destroy a given array of `UnityEngine.Object`, which could be GameObjects, Components, MonoBehaviours and really any type that inherits from `UnityEngine.Object`. Keep in mind that the object is actually destroyed between the end of the current frame and the beginning of the next one.
280+
281+
```cs
282+
public class MyClass : MonoBehaviour
283+
{
284+
[SerializeField]
285+
Object[] _objectsToDestroy;
286+
287+
void Start()
288+
{
289+
ObjectExtensions.DestroyObjects(_objectsToDestroy);
290+
}
291+
}
292+
```
293+
294+
##### :diamond_shape_with_a_dot_inside: Find Implementation(s) of Type
295+
296+
This is meant to find `interface` implementations. It works like a `FindObjectOfType`, but for `interface`. You can also use the `TryFindImplementationOfType` to return a bool. Keep in mind that the `interface` implementation will also need to inherit from `MonoBehaviour` in order to be found, since it will be searched within GameObject's components.
297+
298+
```cs
299+
public interface IActionable {}
300+
301+
public class MyAction : MonoBehaviour, IActionable {}
302+
303+
public class MyClass : MonoBehaviour
304+
{
305+
void Start()
306+
{
307+
// Common usage
308+
IActionable implementation = this.FindImplementationOfType<IActionable>();
309+
// Explicit usage
310+
IActionable implementation = ObjectExtensions.FindImplementationOfType<IActionable>();
311+
// Try usage
312+
bool implementationExists = ObjectExtensions.TryFindImplementationOfType<IActionable>(out IActionable implementation);
313+
314+
// For multiple implementations
315+
List<IActionable> implementations = ObjectExtensions.FindImplementationsOfType<IActionable>();
316+
}
317+
}
318+
```
319+
247320
---
248321

249322
Don't hesitate to create [issues](https://github.com/mygamedevtools/extensions/issues) for suggestions and bugs. Have fun!

0 commit comments

Comments
 (0)