Пример #1
0
        /// <summary>
        /// 指定したLayoutTargetComponentに関係するLayoutTargetを全て更新する。
        ///
        /// 更新対象は以下のものになります。
        /// - targetが所属しているGameObject階層の中でLayoutTargetComponentがアタッチされているGameObject階層以下の全LayoutTargetComponent
        /// </summary>
        /// <param name="target"></param>
        public static void UpdateLayoutHierachy(LayoutTargetComponent target)
        {
            var root = target.transform.GetParentEnumerable()
                       .Select(_p => _p.GetComponent <LayoutTargetComponent>())
                       .LastOrDefault(_p => _p != null);

            if (root == null)
            {
                root = target;
            }

            var layoutTargets = root.transform.GetHierarchyEnumerable()
                                .Select(_t => _t.GetComponent <LayoutTargetComponent>())
                                .Where(_t => _t != null);

            foreach (var t in layoutTargets)
            {
                t.LayoutTarget.IsAutoUpdate = false;
            }

            foreach (var t in layoutTargets)
            {
                LayoutTargetComponentEditor.UpdateSelf(t);
            }
        }
 static Vector3 GetAnchorAreaSize(LayoutTargetComponent layoutTargetComponent)
 {
     if (layoutTargetComponent.LayoutTarget.Parent == null)
     {
         var parent = layoutTargetComponent.transform.parent;
         if (parent.TryGetComponent <LayoutTargetComponent>(out var parentLayoutTarget))
         {
             layoutTargetComponent.LayoutTarget.SetParent(parentLayoutTarget.LayoutTarget);
             return(layoutTargetComponent.LayoutTarget.AnchorAreaSize());
         }
         else if (parent.transform is RectTransform)
         {
             var parentR = parent.transform as RectTransform;
             var self    = layoutTargetComponent.LayoutTarget;
             return(parentR.rect.size.Mul(self.AnchorMax - self.AnchorMin));
         }
         else
         {
             return(Vector3.zero);
         }
     }
     else
     {
         return(layoutTargetComponent.LayoutTarget.AnchorAreaSize());
     }
 }
        public static void UpdateSelf(LayoutTargetComponent t)
        {
            t.LayoutTarget.IsAutoUpdate = false;
            t.AutoDetectUpdater();
            t.UpdateLayoutTargetHierachy();
            t.LayoutTarget.FollowParent();

            t.LayoutTarget.ClearLayouts();
            foreach (var layout in t.GetComponents <ILayoutComponent>())
            {
                t.LayoutTarget.AddLayout(layout.LayoutInstance);
            }

            foreach (var layout in t.LayoutTarget.Layouts)
            {
                layout.UpdateLayout();
            }

            t.CopyToTransform();
        }
        static Vector3 GetLayoutSize(LayoutTargetComponent layoutTargetComponent)
        {
            var self      = layoutTargetComponent.LayoutTarget;
            var localSize = Vector3.zero;

            if (layoutTargetComponent.LayoutTarget.Parent == null)
            {
                var parent = layoutTargetComponent.transform.parent;
                if (parent == null)
                {
                }
                else if (parent.TryGetComponent <LayoutTargetComponent>(out var parentLayoutTarget))
                {
                    localSize = parentLayoutTarget.LayoutTarget.LocalSize;
                }
                else if (parent.transform is RectTransform)
                {
                    var parentR = parent.transform as RectTransform;
                    localSize = parentR.rect.size;
                }
            }
            else
            {
                localSize = layoutTargetComponent.LayoutTarget.Parent.LocalSize;
            }

            if (self.LayoutInfo.LayoutSize.x >= 0)
            {
                localSize.x = Mathf.Min(localSize.x, self.LayoutInfo.LayoutSize.x);
            }
            if (self.LayoutInfo.LayoutSize.y >= 0)
            {
                localSize.y = Mathf.Min(localSize.y, self.LayoutInfo.LayoutSize.y);
            }
            if (self.LayoutInfo.LayoutSize.z >= 0)
            {
                localSize.z = Mathf.Min(localSize.z, self.LayoutInfo.LayoutSize.z);
            }
            return(localSize);
        }
 static LayoutTargetObject GetParentLayoutTarget(LayoutTargetComponent layoutTargetComponent)
 {
     if (layoutTargetComponent.LayoutTarget.Parent == null)
     {
         var parent = layoutTargetComponent.transform.parent;
         if (parent.TryGetComponent <LayoutTargetComponent>(out var parentLayoutTarget))
         {
             return(parentLayoutTarget.LayoutTarget);
         }
         else if (parent.transform is RectTransform)
         {
             var parentR = parent.transform as RectTransform;
             return(LayoutTargetComponent.RectTransformUpdater.Create(parentR) as LayoutTargetObject);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(layoutTargetComponent.LayoutTarget.Parent as LayoutTargetObject);
     }
 }