コード例 #1
0
        public static bool AssertRequireLikeComponentAttrib(Component comp, out System.Type missingCompType, bool silent = false)
        {
            if (comp == null) throw new System.ArgumentNullException("comp");
            missingCompType = null;

            var tp = comp.GetType();
            foreach (var obj in tp.GetCustomAttributes(typeof(RequireLikeComponentAttribute), true))
            {
                RequireLikeComponentAttribute attrib = obj as RequireLikeComponentAttribute;
                foreach (var reqType in attrib.Types)
                {
                    if (!comp.HasLikeComponent(reqType))
                    {
                        missingCompType = reqType;
                        if(!silent) Assert(System.String.Format("(GameObject:{2}) Component type {0} requires the gameobject to also have a component of type {1}.", tp.Name, reqType.Name, comp.gameObject.name), comp);
                        return true;
                    }
                }
            }

            return false;
        }