I would like to render gizmo for my object, but only if it or any of its descendants are selected. As far as I can tell, my choices are to use OnDrawGizmos, which will ALWAYS draw the gizmo, or OnDrawGizmosSelected, which will not draw the gizmo if I select a child. Does anyone know a way to draw a gizmo if an object or any of its descendants are selected?
You could do this in your child object
void OnDrawGizmosSelected()
{
this.transform.parent.SendMessage("OnDrawGizmosSelected");
}
I would use the OnDrawGizmos method but check the Selection to only draw the gizmo if your object, or one of its children, is selected.
Edit - You could also use OnDrawGizmosSelected but then add that script to all children objects as well. Unless there is a reason why you cannot add it to the children. In that case, I'd do what I stated above.