当前位置: 首页>>代码示例>>C#>>正文


C# Component.FindRoot方法代码示例

本文整理汇总了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;
        }
开发者ID:Gege00,项目名称:spacepuppy-unity-framework,代码行数:32,代码来源:Assertions.cs

示例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;
        }
开发者ID:Gege00,项目名称:spacepuppy-unity-framework,代码行数:22,代码来源:Assertions.cs


注:本文中的UnityEngine.Component.FindRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。