本文整理匯總了C#中UnityEngine.Component.FindRoot方法的典型用法代碼示例。如果您正苦於以下問題:C# Component.FindRoot方法的具體用法?C# Component.FindRoot怎麽用?C# Component.FindRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UnityEngine.Component
的用法示例。
在下文中一共展示了Component.FindRoot方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AssertUniqueToEntityAttrib
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;
}
示例2: AssertRequireComponentInEntityAttrib
public static bool AssertRequireComponentInEntityAttrib(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(RequireComponentInEntityAttribute), true))
{
RequireComponentInEntityAttribute attrib = obj as RequireComponentInEntityAttribute;
foreach (var reqType in attrib.Types)
{
if (!comp.EntityHasComponent(reqType))
{
missingCompType = reqType;
if(!silent) Assert(System.String.Format("(Entity:{2}) Component type {0} requires the entity to also have a component of type {1}.", tp.Name, reqType.Name, comp.FindRoot().name), comp);
return true;
}
}
}
return false;
}