public uint Adopt(Action <Breakable> onDestroy, Action <Breakable, List <Breakable> > onBreak, Action <Breakable> onActivate, Action <Breakable> onDeactivate, Action <Breakable> onAdopt) { this.nrOfDecendants = 0; //// Set the actions this.onDestroy = onDestroy; this.onBreak = onBreak; this.onActivate = onActivate; this.onDeactivate = onDeactivate; // Call on adopt if (onAdopt != null) { onAdopt(this); } //// Adopt the children // Get the children foreach (Transform childTransform in transform) { // Increment the number of decendants this.nrOfDecendants += 1; // If the child exists, get the Breakable module Breakable childBreakable = childTransform.gameObject.GetComponent <Breakable>(); // If the module exists, adopt it with Adopt function if (childBreakable != null) { this.children.Add(childBreakable); this.nrOfDecendants += childBreakable.Adopt( this.onChildDestroy, this.onBreak, this.onActivate, this.onDeactivate, onAdopt ); } } return(this.nrOfDecendants); }