示例#1
0
        public static float GetLayoutProperty(RectTransform rect, System.Func<ILayoutElement, float> property, float defaultValue, out ILayoutElement source)
        {
            source = null;
            if (rect == null)
                return 0;
            float min = defaultValue;
            int maxPriority = System.Int32.MinValue;
            var components = ComponentListPool.Get();
            rect.GetComponents(typeof(ILayoutElement), components);

            for (int i = 0; i < components.Count; i++)
            {
                var layoutComp = components[i] as ILayoutElement;
                if (layoutComp is Behaviour && !(layoutComp as Behaviour).enabled)
                    continue;

                int priority = layoutComp.layoutPriority;
                // If this layout components has lower priority than a previously used, ignore it.
                if (priority < maxPriority)
                    continue;
                float prop = property(layoutComp);
                // If this layout property is set to a negative value, it means it should be ignored.
                if (prop < 0)
                    continue;

                // If this layout component has higher priority than all previous ones,
                // overwrite with this one's value.
                if (priority > maxPriority)
                {
                    min = prop;
                    maxPriority = priority;
                    source = layoutComp;
                }
                // If the layout component has the same priority as a previously used,
                // use the largest of the values with the same priority.
                else if (prop > min)
                {
                    min = prop;
                    source = layoutComp;
                }
            }

            ComponentListPool.Release(components);
            return min;
        }
示例#2
0
 public static float GetLayoutProperty(RectTransform rect, Func<ILayoutElement, float> property, float defaultValue, out ILayoutElement source)
 {
   source = (ILayoutElement) null;
   if ((UnityEngine.Object) rect == (UnityEngine.Object) null)
     return 0.0f;
   float num1 = defaultValue;
   int num2 = int.MinValue;
   List<Component> list = ListPool<Component>.Get();
   rect.GetComponents(typeof (ILayoutElement), list);
   for (int index = 0; index < list.Count; ++index)
   {
     ILayoutElement layoutElement = list[index] as ILayoutElement;
     if (!(layoutElement is Behaviour) || ((Behaviour) layoutElement).isActiveAndEnabled)
     {
       int layoutPriority = layoutElement.layoutPriority;
       if (layoutPriority >= num2)
       {
         float num3 = property(layoutElement);
         if ((double) num3 >= 0.0)
         {
           if (layoutPriority > num2)
           {
             num1 = num3;
             num2 = layoutPriority;
             source = layoutElement;
           }
           else if ((double) num3 > (double) num1)
           {
             num1 = num3;
             source = layoutElement;
           }
         }
       }
     }
   }
   ListPool<Component>.Release(list);
   return num1;
 }
 private static bool ValidLayoutGroup(RectTransform parent, List<Component> comps)
 {
   if ((UnityEngine.Object) parent == (UnityEngine.Object) null)
     return false;
   parent.GetComponents(typeof (ILayoutGroup), comps);
   LayoutRebuilder.StripDisabledBehavioursFromList(comps);
   return comps.Count > 0;
 }
 private static bool ValidController(RectTransform layoutRoot, List<Component> comps)
 {
   if ((UnityEngine.Object) layoutRoot == (UnityEngine.Object) null)
     return false;
   layoutRoot.GetComponents(typeof (ILayoutController), comps);
   LayoutRebuilder.StripDisabledBehavioursFromList(comps);
   return comps.Count > 0;
 }
 private void PerformLayoutCalculation(RectTransform rect, UnityAction<Component> action)
 {
   if ((UnityEngine.Object) rect == (UnityEngine.Object) null)
     return;
   List<Component> list = ListPool<Component>.Get();
   rect.GetComponents(typeof (ILayoutElement), list);
   LayoutRebuilder.StripDisabledBehavioursFromList(list);
   if (list.Count > 0)
   {
     for (int index = 0; index < rect.childCount; ++index)
       this.PerformLayoutCalculation(rect.GetChild(index) as RectTransform, action);
     for (int index = 0; index < list.Count; ++index)
       action(list[index]);
   }
   ListPool<Component>.Release(list);
 }