/// <summary> /// Searches child scene objects for <see cref="Bone"/> components and returns any found ones. /// </summary> private Bone[] FindChildBones() { Stack <SceneObject> todo = new Stack <SceneObject>(); todo.Push(SceneObject); List <Bone> bones = new List <Bone>(); while (todo.Count > 0) { SceneObject currentSO = todo.Pop(); Bone bone = currentSO.GetComponent <Bone>(); if (bone != null) { bone.SetParent(this, true); bones.Add(bone); } int childCount = currentSO.GetNumChildren(); for (int i = 0; i < childCount; i++) { SceneObject child = currentSO.GetChild(i); if (child.GetComponent <Animation>() != null) { continue; } todo.Push(child); } } return(bones.ToArray()); }
/// <summary> /// Searches child scene objects for Collider components and attaches them to the rigidbody. Make sure to call /// <see cref="ClearColliders"/> if you need to clear old colliders first. /// </summary> private void UpdateColliders() { Stack <SceneObject> todo = new Stack <SceneObject>(); todo.Push(SceneObject); while (todo.Count > 0) { SceneObject currentSO = todo.Pop(); if (currentSO.GetComponent <Collider>() != null) { Collider[] colliders = currentSO.GetComponents <Collider>(); foreach (var entry in colliders) { if (!entry.IsValidParent(this)) { continue; } if (entry.native == null) { continue; } entry.SetRigidbody(this, true); entry.native.Rigidbody = native; children.Add(entry); native.AddCollider(entry); } } int childCount = currentSO.GetNumChildren(); for (int i = 0; i < childCount; i++) { SceneObject child = currentSO.GetChild(i); if (child.GetComponent <Rigidbody>() != null) { continue; } todo.Push(child); } } }