public static bool AssertUniqueToEntityAttrib(Component comp, bool silent = false) { var tp = comp.GetType(); var attrib = tp.GetCustomAttributes(typeof(UniqueToEntityAttribute), false).FirstOrDefault() as UniqueToEntityAttribute; if (attrib != null) { if (attrib.MustBeAttachedToRoot) { if (!comp.HasTag(SPConstants.TAG_ROOT)) { if(!silent) Assert(System.String.Format("(Entity:{1}) Component type {0} must be attached to the root gameObject.", tp.Name, comp.FindRoot().name), comp); return true; } } else { var root = comp.FindRoot(); foreach (var child in root.GetAllChildrenAndSelf()) { if (child != comp.transform && child.HasComponent(tp)) { if(!silent) Assert(System.String.Format("(Entity:{1}) Only one component of type {0} must be attached to a root or any of its children.", tp.Name, root.name), comp); return true; } } } } return false; }