Tanoda
IgnoreCollisionsInChildren.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12
13namespace Leap.Unity.Examples {
14
25 public class IgnoreCollisionsInChildren : MonoBehaviour {
26
27 void Start() {
28 IgnoreCollisionsInChildrenOf(this.transform);
29 }
30
31 public static void IgnoreCollisionsInChildrenOf(Transform t, bool ignore = true) {
32 var colliders = Pool<List<Collider>>.Spawn();
33 try {
34 t.GetComponentsInChildren<Collider>(true, colliders);
35
36 for (int i = 0; i < colliders.Count; i++) {
37 for (int j = 0; j < colliders.Count; j++) {
38 if (i == j) continue;
39
40 Physics.IgnoreCollision(colliders[i], colliders[j], ignore);
41 }
42 }
43 }
44 finally {
45 colliders.Clear();
46 Pool<List<Collider>>.Recycle(colliders);
47 }
48 }
49
50 }
51
52}
This utility script scans through its Transform's children and tells PhysX to ignore collisions betwe...
static void IgnoreCollisionsInChildrenOf(Transform t, bool ignore=true)