protected void CreateCellGroupPrefab()
        {
            var go = new GameObject(scrollRect.name + "_CellGroupPrefab", typeof(RectTransform));

            // Additional reminder of the "add recttransform in awake" bug explained in InitIfNeeded()
            if (!(go.transform is RectTransform))
            {
                Debug.LogException(new UnityException("SRIA: Don't call SRIA.Init() outside MonoBehaviour.Start()!"));
            }

            go.SetActive(false);
            go.transform.SetParent(scrollRect.transform, false);
            if (scrollRect.horizontal)
            {
                _TheOnlyGroupPrefab = go.AddComponent <VerticalLayoutGroup>();                // groups are columns in a horizontal scrollview
            }
            else
            {
                _TheOnlyGroupPrefab = go.AddComponent <HorizontalLayoutGroup>();                // groups are rows in a vertical scrollview
            }
            _TheOnlyGroupPrefab.spacing = contentSpacing;
            _TheOnlyGroupPrefab.childForceExpandWidth  = cellWidthForceExpandInGroup;
            _TheOnlyGroupPrefab.childForceExpandHeight = cellHeightForceExpandInGroup;
            _TheOnlyGroupPrefab.childAlignment         = alignmentOfCellsInGroup;
            _TheOnlyGroupPrefab.padding = groupPadding;
        }
        private void SetHorizontalOrVerticalLayoutGroupProperties(int currentLanguageIndex)
        {
            HorizontalOrVerticalLayoutGroup horizontalOrVerticalLayoutGroup = GetComponent <HorizontalOrVerticalLayoutGroup>();

            horizontalOrVerticalLayoutGroup.childAlignment     = HorizontalOrVerticalLayoutGroupProperties[currentLanguageIndex].ChildAlignment;
            horizontalOrVerticalLayoutGroup.reverseArrangement = HorizontalOrVerticalLayoutGroupProperties[currentLanguageIndex].ReverseArrangment;
        }
Exemple #3
0
        private IEnumerator CoUpdateState()
        {
            yield return(new WaitForEndOfFrame());

            m_isEnabled = m_isFree = m_region.IsFreeOrModal();
            if (!m_isFree)
            {
                Canvas  canvas      = GetComponentInParent <Canvas>();
                Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(canvas.worldCamera, transform.position);

                RectTransform rt = (RectTransform)transform;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, screenPoint, canvas.worldCamera, out m_adjustment);

                if (m_dx == 0 || m_dy == 0)
                {
                    int siblingIndex = m_region.transform.GetSiblingIndex();

                    HorizontalOrVerticalLayoutGroup layoutGroup = m_region.GetComponentInParent <HorizontalOrVerticalLayoutGroup>();
                    if (layoutGroup is HorizontalLayoutGroup)
                    {
                        if (siblingIndex == 0 && m_dx > 0)
                        {
                            m_isEnabled = true;
                        }
                        else if (siblingIndex == 1 && m_dx < 0)
                        {
                            m_isEnabled = true;
                        }
                    }
                    else
                    {
                        if (siblingIndex == 0 && m_dy < 0)
                        {
                            m_isEnabled = true;
                        }
                        else if (siblingIndex == 1 && m_dy > 0)
                        {
                            m_isEnabled = true;
                        }
                    }

                    if (m_isEnabled && m_region.transform.parent.childCount > (siblingIndex + 1) % 2)
                    {
                        m_siblingLayout = m_region.transform.parent.GetChild((siblingIndex + 1) % 2).GetComponent <LayoutElement>();
                        m_parentRT      = (RectTransform)m_region.transform.parent;
                    }
                    else
                    {
                        m_isEnabled     = false;
                        m_siblingLayout = null;
                        m_parentRT      = null;
                    }
                }
            }
            else
            {
                m_siblingLayout = null;
                m_parentRT      = null;
            }
        }
        public override IEnumerator ApplyChanges(string newJson)
        {
            referencesContainer.image.color = new Color(model.color.r, model.color.g, model.color.b, model.color.a);

            if (model.stackOrientation == StackOrientation.VERTICAL && !(layoutGroup is VerticalLayoutGroup))
            {
                Object.DestroyImmediate(layoutGroup, false);
                layoutGroup = childHookRectTransform.gameObject.AddComponent <VerticalLayoutGroup>();
            }
            else if (model.stackOrientation == StackOrientation.HORIZONTAL && !(layoutGroup is HorizontalLayoutGroup))
            {
                Object.DestroyImmediate(layoutGroup, false);
                layoutGroup = childHookRectTransform.gameObject.AddComponent <HorizontalLayoutGroup>();
            }

            layoutGroup.childControlHeight     = false;
            layoutGroup.childControlWidth      = false;
            layoutGroup.childForceExpandWidth  = false;
            layoutGroup.childForceExpandHeight = false;
            layoutGroup.spacing = model.spacing;

            referencesContainer.sizeFitter.adjustHeight = model.adaptHeight;
            referencesContainer.sizeFitter.adjustWidth  = model.adaptWidth;

            RefreshAll();
            return(null);
        }
        protected void CreateOrReinitCellGroupPrefab()
        {
            if (!_TheOnlyGroupPrefab)
            {
                var go = new GameObject(ScrollViewRT.name + "_CellGroupPrefab", typeof(RectTransform));

                // Additional reminder of the "add recttransform in awake" bug explained in InitIfNeeded()
                if (!(go.transform is RectTransform))
                {
                    Debug.LogException(new UnityException("OSA: Don't call OSA.Init() outside MonoBehaviour.Start()!"));
                }

                // TODO also integrate the new SetViewsHolderEnabled functionality here, for grids
                go.SetActive(false);
                go.transform.SetParent(ScrollViewRT, false);
                if (IsHorizontal)
                {
                    _TheOnlyGroupPrefab = go.AddComponent <VerticalLayoutGroup>();                    // groups are columns in a horizontal scrollview
                }
                else
                {
                    _TheOnlyGroupPrefab = go.AddComponent <HorizontalLayoutGroup>();                    // groups are rows in a vertical scrollview
                }
            }

            _TheOnlyGroupPrefab.spacing = grid.spacingInGroup;
            _TheOnlyGroupPrefab.childForceExpandWidth  = grid.cellWidthForceExpandInGroup;
            _TheOnlyGroupPrefab.childForceExpandHeight = grid.cellHeightForceExpandInGroup;
            _TheOnlyGroupPrefab.childAlignment         = grid.alignmentOfCellsInGroup;
            _TheOnlyGroupPrefab.padding = grid.groupPadding;
        }
        public LayoutData(HorizontalOrVerticalLayoutGroup layoutGroup)
        {
            if (layoutGroup != null)
            {
                if (layoutGroup.GetComponent <VerticalLayoutGroup>() != null)
                {
                    LayoutType = UILayout.Vertical;
                }

                if (layoutGroup.GetComponent <HorizontalLayoutGroup>() != null)
                {
                    LayoutType = UILayout.Horizontal;
                }

                spacing                = layoutGroup.spacing;
                padding                = layoutGroup.padding;
                childAlignment         = layoutGroup.childAlignment;
                childForceExpandHeight = layoutGroup.childForceExpandHeight;
                childForceExpandWidth  = layoutGroup.childForceExpandWidth;
            }
            else
            {
                new LayoutData();
            }
        }
    void GUIDrawChildrens(HorizontalOrVerticalLayoutGroup layout)
    {
        var  isHorizontal = layout is HorizontalLayoutGroup;
        Rect r;

        r = EditorGUILayout.BeginVertical();
        GUI.Box(r, GUIContent.none);
        DrawLayoutHandler(layout);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.GetControlRect(GUILayout.Width(10));
        if (!isHorizontal)
        {
            EditorGUILayout.BeginVertical();
        }
        {
            var t = layout.GetComponent <RectTransform>();
            if (!t)
            {
                t = layout.gameObject.AddComponent <RectTransform>();
            }
            inHorizontalLayout = isHorizontal;
            for (int i = 0; i < t.childCount; i++)
            {
                GUIDraw(t.GetChild(i).gameObject);
            }
        }
        EditorGUILayout.Space();
        if (!isHorizontal)
        {
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
Exemple #8
0
        public static void SetLayoutChildControlsSize(HorizontalOrVerticalLayoutGroup lg, bool width, bool height)
        {
#if UNITY_2017_1_OR_NEWER
            lg.childControlWidth  = width;
            lg.childControlHeight = height;
#endif
        }
        public void Initialize(int columnIndex)
        {
            transform.DestroyChildrenImmediate();
            cellContainers.Clear();
            this.columnIndex = columnIndex;
            if (table.horizontal)
            {
                columnLayout = gameObject.GetOrAddComponent <HorizontalLayoutGroup>();
            }
            else
            {
                columnLayout = gameObject.GetOrAddComponent <VerticalLayoutGroup>();
            }
            columnLayout.childControlWidth      = true;
            columnLayout.childControlHeight     = true;
            columnLayout.childForceExpandWidth  = true;
            columnLayout.childForceExpandHeight = true;
            columnLayout.spacing = -1f;
            ContentSizeFitter sizeFitter = gameObject.AddComponent <ContentSizeFitter>();

            sizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            sizeFitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            layoutElement            = gameObject.AddComponent <LayoutElement>();

            if (table.hasTitles)
            {
                CreateTitleCell();
            }

            CreateCells();

            Update();
        }
    /// <summary>
    /// Calculates offset needed to counter layout group's padding and spacing
    /// </summary>
    private float GetLayoutGroupOffset(HorizontalOrVerticalLayoutGroup layoutGroup)
    {
        float offset = 0;

        if (layoutGroup != null)
        {
            if (layoutGroup is HorizontalLayoutGroup)
            {
                offset += layoutGroup.padding.left;
                offset += layoutGroup.padding.right;
            }
            else if (layoutGroup is VerticalLayoutGroup)
            {
                offset += layoutGroup.padding.top;
                offset += layoutGroup.padding.bottom;
            }

            offset += layoutGroup.spacing * top.Count;
            offset += layoutGroup.spacing * bottom.Count;
            offset += layoutGroup.spacing * left.Count;
            offset += layoutGroup.spacing * right.Count;
        }

        return(offset);
    }
Exemple #11
0
    // 初始化布局
    private void InitLayout()
    {
        var contentV = GetComponentInChildren <VerticalLayoutGroup>(true);
        var contentH = GetComponentInChildren <HorizontalLayoutGroup>(true);

        _scrollRect = GetComponent <ScrollRect>();

        if (_layout == Layout.Vertical)
        {
            _scrollRect.vertical   = true;
            _scrollRect.horizontal = false;
            _scrollRect.content    = contentV.transform as RectTransform;

            contentV.gameObject.SetActive(true);
            contentH.gameObject.SetActive(false);
            _content = contentV;
        }
        else
        {
            _scrollRect.vertical   = false;
            _scrollRect.horizontal = true;
            _scrollRect.content    = contentH.transform as RectTransform;

            contentV.gameObject.SetActive(false);
            contentH.gameObject.SetActive(true);
            _content = contentH;
        }
    }
        protected override GameObject Install(GameObject go, HorizontalOrVerticalLayoutElement horzOrVert, IReadOnlyLayoutContext context)
        {
            ContentSizeFitter fitter = null;

            if (context.ParseBool(horzOrVert.FitSize))
            {
                fitter = go.AddComponent <ContentSizeFitter>();
            }

            HorizontalOrVerticalLayoutGroup group = null;

            if (horzOrVert is VerticalLayoutElement vert)
            {
                group = go.AddComponent <VerticalLayoutGroup>();
                group.childControlHeight = group.childControlWidth = context.ParseBool(vert.Flex);
                if (fitter != null)
                {
                    fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
                }
            }
            else if (horzOrVert is HorizontalLayoutElement hor)
            {
                group = go.AddComponent <HorizontalLayoutGroup>();
                group.childControlHeight = group.childControlWidth = context.ParseBool(hor.Flex);

                if (fitter != null)
                {
                    fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
                }
            }

            var padding = ParseUtils.ParsePadding(horzOrVert.Padding);

            group.padding                = new RectOffset((int)padding.w, (int)padding.y, (int)padding.x, (int)padding.z);
            group.spacing                = context.ParseFloat(horzOrVert.Spacing);
            group.childControlWidth     |= context.ParseBool(horzOrVert.ExpandWidth);
            group.childForceExpandWidth  = context.ParseBool(horzOrVert.ExpandWidth);
            group.childForceExpandHeight = context.ParseBool(horzOrVert.ExpandHeight);
            group.childControlHeight    |= context.ParseBool(horzOrVert.ExpandHeight);

            if (string.IsNullOrEmpty(horzOrVert.Align))
            {
                horzOrVert.Align = "middle";
            }

            if (string.IsNullOrEmpty(horzOrVert.VertAlign))
            {
                horzOrVert.VertAlign = "middle";
            }

            var alignment = ParseUtils.ParseAlignment(horzOrVert.Align, horzOrVert.VertAlign);

            if (alignment.HasValue)
            {
                group.childAlignment = alignment.Value;
            }

            return(go);
        }
    void Start()
    {
        layoutGroup = GetComponent <HorizontalOrVerticalLayoutGroup>();
        vertical    = layoutGroup.GetType() == typeof(VerticalLayoutGroup);
        horizontal  = layoutGroup.GetType() == typeof(HorizontalLayoutGroup);

        SetNavigation();
    }
Exemple #14
0
        public static bool GetLayoutChildControlHeight(HorizontalOrVerticalLayoutGroup lg)
        {
#if UNITY_2017_1_OR_NEWER
            return(lg.childControlHeight);
#else
            return(true);
#endif
        }
Exemple #15
0
 public void UpdateLayoutGroup(HorizontalOrVerticalLayoutGroup layoutGroup)
 {
     if (Padding.top != layoutGroup.padding.top || Padding.left != layoutGroup.padding.left || Padding.right != layoutGroup.padding.right || Padding.bottom != layoutGroup.padding.bottom)
     {
         layoutGroup.padding = Padding;
         layoutGroup.CalculateLayoutInputHorizontal();
         layoutGroup.CalculateLayoutInputVertical();
     }
 }
Exemple #16
0
    public static void SetChildControlWidth(this HorizontalOrVerticalLayoutGroup group, bool value)
    {
        if (pi_childControlWidth == null)
        {
            pi_childControlWidth = group.GetType().GetProperty("childControlWidth");
        }

        pi_childControlWidth?.SetValue(group, value, null);
    }
        /// <summary>
        /// Show indicator for the specified index in RectTransform.
        /// </summary>
        /// <param name="index">Position.</param>
        /// <param name="parent">Parent.</param>
        public virtual void Show(int index, RectTransform parent)
        {
            if (index == -1)
            {
                Hide();
                return;
            }

            CurrentLayoutGroup = parent.GetComponent <HorizontalOrVerticalLayoutGroup>();
            if (CurrentLayoutGroup == null)
            {
                Debug.LogWarning("Horizontal or Vertical Layout Group component not found on " + parent, this);
                return;
            }

            IsHorizontal = CurrentLayoutGroup is HorizontalLayoutGroup;

            var size          = IsHorizontal ? parent.rect.height : parent.rect.width;
            var base_position = CalculatePosition(index, parent);
            var position      = IsHorizontal ? new Vector2(base_position, 0f) : new Vector2(0f, -base_position);

            var rectTransform = transform as RectTransform;

            if (IsHorizontal)
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 2f);
            }
            else
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 2f);
            }

            rectTransform.pivot = new Vector2(0.5f, 0.5f);
            if (IsHorizontal)
            {
                rectTransform.anchorMin = new Vector2(0f, 0.5f);
                rectTransform.anchorMax = new Vector2(0f, 0.5f);
            }
            else
            {
                rectTransform.anchorMin = new Vector2(0.5f, 1f);
                rectTransform.anchorMax = new Vector2(0.5f, 1f);
            }

            rectTransform.anchoredPosition = position;
            rectTransform.SetParent(parent, false);
            rectTransform.SetAsLastSibling();

            LayoutElement.ignoreLayout = true;

            gameObject.SetActive(true);
        }
Exemple #18
0
    private static void ConfigureHorizontalOrVerticalLayoutGroup(HorizontalOrVerticalLayoutGroup layoutGroup)
    {
        layoutGroup.childControlWidth  = true;
        layoutGroup.childControlHeight = true;

        layoutGroup.childScaleWidth  = false;
        layoutGroup.childScaleHeight = false;

        layoutGroup.childForceExpandWidth  = true;
        layoutGroup.childForceExpandHeight = true;
    }
Exemple #19
0
        void Start()
        {
            HorizontalOrVerticalLayoutGroup layoutGroup = GetComponent <HorizontalOrVerticalLayoutGroup> ();
            RectOffset padding = layoutGroup.padding;

            layoutGroup.padding.bottom = (int)GameUtils.ToDP(padding.bottom);
            layoutGroup.padding.left   = (int)GameUtils.ToDP(padding.left);
            layoutGroup.padding.right  = (int)GameUtils.ToDP(padding.right);
            layoutGroup.padding.top    = (int)GameUtils.ToDP(padding.top);
            layoutGroup.spacing        = (int)GameUtils.ToDP(layoutGroup.spacing);
        }
Exemple #20
0
        void Awake()
        {
            isEmpty                 = true;
            m_scrollRect            = GetComponent <ScrollRect>();
            m_scrollRect.vertical   = mDirection == Direction.Vertical;
            m_scrollRect.horizontal = mDirection == Direction.Horizontal;

            var content = m_scrollRect.content;

            if (!content)
            {
                Debug.LogError("The ScrollRect Content is null!!");
                return;
            }

            if (m_scrollRect.horizontal)
            {
                m_LayoutGroup = m_scrollRect.content.GetComponent <HorizontalLayoutGroup>();
                //if(m_LayoutGroup == null)
                //{
                //    m_LayoutGroup = m_scrollRect.content.gameObject.AddComponent<HorizontalLayoutGroup>();
                //}
                //m_LayoutGroup.childForceExpandHeight = true;
                //m_LayoutGroup.childForceExpandWidth = false;
                //var rect = (m_LayoutGroup.transform as RectTransform);
                //rect.anchorMin = Vector2.zero;
                //rect.anchorMax = Vector2.up;
                //rect.pivot = Vector2.up/2;
            }
            else
            {
                m_LayoutGroup = m_scrollRect.content.GetComponent <VerticalLayoutGroup>();
                //if (m_LayoutGroup == null)
                //{
                //    m_LayoutGroup = m_scrollRect.content.gameObject.AddComponent<VerticalLayoutGroup>();
                //}
                //m_LayoutGroup.childForceExpandHeight = false;
                //m_LayoutGroup.childForceExpandWidth = true;
                //var rect = (m_LayoutGroup.transform as RectTransform);
                //rect.anchorMin = Vector2.up;
                //rect.anchorMax = Vector2.one;
                //rect.pivot = new Vector2(0.5f, 1);
            }
            m_leftOrTopPadding = CreateEmptyPaddingElement("LeftTopPadding");
            m_leftOrTopPadding.transform.SetParent(m_scrollRect.content, false);
            m_rightOrBottomPadding = CreateEmptyPaddingElement("RightBottom");
            m_rightOrBottomPadding.transform.SetParent(m_scrollRect.content, false);
            m_visibleCells = new Dictionary <int, TableViewCell>();

            m_reusableCellContainer = new GameObject("ReusableCells", typeof(RectTransform)).GetComponent <RectTransform>();
            m_reusableCellContainer.SetParent(this.transform, false);
            m_reusableCellContainer.gameObject.SetActive(false);
            m_reusableCells = new Dictionary <string, LinkedList <TableViewCell> >();
        }
Exemple #21
0
    private static void DrawLayoutGroup(HorizontalOrVerticalLayoutGroup layoutGroup)
    {
        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Padding", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            Tuple <int, int, int, int> padding = VectorDrawer.DrawInt4(layoutGroup.padding.left, layoutGroup.padding.right,
                                                                       layoutGroup.padding.top, layoutGroup.padding.bottom);

            layoutGroup.padding.left   = padding.Item1;
            layoutGroup.padding.right  = padding.Item2;
            layoutGroup.padding.top    = padding.Item3;
            layoutGroup.padding.bottom = padding.Item4;
        }

        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Spacing", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            layoutGroup.spacing = NitroxGUILayout.FloatField(layoutGroup.spacing);
        }

        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Child Alignment", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            layoutGroup.childAlignment = NitroxGUILayout.EnumPopup(layoutGroup.childAlignment);
        }

        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Control Child Size", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            layoutGroup.childControlWidth  = NitroxGUILayout.BoolField(layoutGroup.childControlWidth, "Width");
            layoutGroup.childControlHeight = NitroxGUILayout.BoolField(layoutGroup.childControlHeight, "Height");
        }

        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Use Child Scale", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            layoutGroup.childScaleWidth  = NitroxGUILayout.BoolField(layoutGroup.childScaleWidth, "Width");
            layoutGroup.childScaleHeight = NitroxGUILayout.BoolField(layoutGroup.childScaleHeight, "Height");
        }

        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Child Force Expand", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
            NitroxGUILayout.Separator();
            layoutGroup.childForceExpandWidth  = NitroxGUILayout.BoolField(layoutGroup.childForceExpandWidth, "Width");
            layoutGroup.childForceExpandHeight = NitroxGUILayout.BoolField(layoutGroup.childForceExpandHeight, "Height");
        }
    }
Exemple #22
0
        protected virtual void SetLayoutParams(HorizontalOrVerticalLayoutGroup layout)
        {
            if (layout == null)
            {
                return;
            }

            layout.childControlWidth      = false;
            layout.childControlHeight     = false;
            layout.childForceExpandWidth  = true;
            layout.childForceExpandHeight = true;
        }
Exemple #23
0
 void Awake()
 {
     layoutGroup = GetComponent <HorizontalOrVerticalLayoutGroup> ();
     if (layoutGroup)
     {
         childAlignment = layoutGroup.childAlignment;
     }
     else
     {
         Debug.Log("no layout group");
     }
 }
    private void SetLayout(HorizontalOrVerticalLayoutGroup layoutGroup, LayoutData layoutData)
    {
        if (layoutGroup == null)
        {
            return;
        }

        layoutGroup.childForceExpandHeight = layoutData.childForceExpandHeight;
        layoutGroup.childForceExpandWidth  = layoutData.childForceExpandWidth;
        layoutGroup.padding        = layoutData.padding;
        layoutGroup.childAlignment = layoutData.childAlignment;
        layoutGroup.spacing        = layoutData.spacing;
    }
Exemple #25
0
    private void ConfigureContentContainer(ContentContainer container, GameObject containerGameObject, bool bgColor = false)
    {
        LayoutGroup component = containerGameObject.GetComponent <LayoutGroup>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            UnityEngine.Object.DestroyImmediate(component);
        }
        if (Game.Instance.unlocks.IsUnlocked(container.lockID) || string.IsNullOrEmpty(container.lockID))
        {
            switch (container.contentLayout)
            {
            case ContentContainer.ContentLayout.Horizontal:
            {
                component = containerGameObject.AddComponent <HorizontalLayoutGroup>();
                component.childAlignment = TextAnchor.MiddleLeft;
                HorizontalOrVerticalLayoutGroup obj2 = component as HorizontalOrVerticalLayoutGroup;
                bool childForceExpandHeight          = (component as HorizontalOrVerticalLayoutGroup).childForceExpandWidth = false;
                obj2.childForceExpandHeight = childForceExpandHeight;
                (component as HorizontalOrVerticalLayoutGroup).spacing = 8f;
                break;
            }

            case ContentContainer.ContentLayout.Vertical:
            {
                component = containerGameObject.AddComponent <VerticalLayoutGroup>();
                HorizontalOrVerticalLayoutGroup obj = component as HorizontalOrVerticalLayoutGroup;
                bool childForceExpandHeight         = (component as HorizontalOrVerticalLayoutGroup).childForceExpandWidth = false;
                obj.childForceExpandHeight = childForceExpandHeight;
                (component as HorizontalOrVerticalLayoutGroup).spacing = 8f;
                break;
            }

            case ContentContainer.ContentLayout.Grid:
                component = containerGameObject.AddComponent <GridLayoutGroup>();
                (component as GridLayoutGroup).constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
                (component as GridLayoutGroup).constraintCount = 4;
                (component as GridLayoutGroup).cellSize        = new Vector2(128f, 180f);
                (component as GridLayoutGroup).spacing         = new Vector2(6f, 6f);
                break;
            }
        }
        else
        {
            component = containerGameObject.AddComponent <VerticalLayoutGroup>();
            HorizontalOrVerticalLayoutGroup obj3 = component as HorizontalOrVerticalLayoutGroup;
            bool childForceExpandHeight          = (component as HorizontalOrVerticalLayoutGroup).childForceExpandWidth = false;
            obj3.childForceExpandHeight = childForceExpandHeight;
            (component as HorizontalOrVerticalLayoutGroup).spacing = 8f;
        }
    }
 void DrawLayoutHandler(HorizontalOrVerticalLayoutGroup layout)
 {
     {
         bool isHorizontal = layout is HorizontalLayoutGroup;
         GUILayout.Space(10);
         EditorGUILayout.BeginHorizontal();
         EditorGUI.BeginChangeCheck();
         if (GUILayout.Button("<>", GUILayout.Width(30)))
         {
             Selection.activeGameObject = layout.gameObject;
         }
         if (GUILayout.Button(isHorizontal ? "H" : "V", GUILayout.Width(30)))
         {
             var space   = layout.spacing;
             var padding = layout.padding;
             var obj     = layout.gameObject;
             Undo.DestroyObjectImmediate(layout);
             if (isHorizontal)
             {
                 Undo.AddComponent(obj, typeof(VerticalLayoutGroup));
             }
             else
             {
                 Undo.AddComponent(obj, typeof(HorizontalLayoutGroup));
             }
             layout.spacing = space;
             layout.padding = padding;
         }
         var rS = EditorGUILayout.GetControlRect(GUILayout.MinWidth(30));
         if (rS.width < 100)
         {
             layout.spacing = EditorGUI.FloatField(rS, layout.spacing);
         }
         else
         {
             layout.spacing = EditorGUI.Slider(rS, layout.spacing, 0, 100f);
         }
         var r = EditorGUILayout.GetControlRect(GUILayout.Width(50));
         if (GUI.Button(r, "+"))
         {
             OnAddInside = true;
             EditorUtility.DisplayCustomMenu(r, addContext, -1, new EditorUtility.SelectMenuItemFunction(OnAddPopup), layout.gameObject);
         }
         if (EditorGUI.EndChangeCheck())
         {
             EditorUtility.SetDirty(layout);
         }
         EditorGUILayout.EndHorizontal();
     }
 }
Exemple #27
0
    protected override void Awake()
    {
        _inputField = GetComponent <InputField>();
        _inputField.onValueChanged.AddListener(new UnityAction <string>(ResizeInput));
        _rectTransform = GetComponent <RectTransform>();
        CanvasScaler canvasScaler = GetComponentInParent <CanvasScaler>();

        if (canvasScaler)
        {
            _canvasScaleFactor = canvasScaler.scaleFactor;
        }
        _layoutElement     = GetComponent <LayoutElement>();
        _parentLayoutGroup = transform.parent.GetComponent <HorizontalOrVerticalLayoutGroup>();
    }
Exemple #28
0
    void Awake()
    {
        FindObjectOfType <Game>().UpdateBoardAction += UpdateDataValues;

        rowLayoutGroup = rowDataHolder.GetComponent <VerticalLayoutGroup>();
        colLayoutGroup = colDataHolder.GetComponent <HorizontalLayoutGroup>();

        rowLayoutGroup.spacing = CellSize * CellScale.y;
        colLayoutGroup.spacing = CellSize * CellScale.x;

        rowLayoutGroup.padding.top  = Mathf.RoundToInt(rowLayoutGroup.spacing / 2);
        colLayoutGroup.padding.left = Mathf.RoundToInt(colLayoutGroup.spacing / 2);

        GenerateDataValues();
    }
Exemple #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIWidgets.StandardLayoutBridge"/> class.
        /// </summary>
        /// <param name="layout">Layout.</param>
        /// <param name="defaultItem">Default item.</param>
        /// <param name="updateContentSizeFitter">Update ContentSizeFitter on direction change.</param>
        public StandardLayoutBridge(HorizontalOrVerticalLayoutGroup layout, RectTransform defaultItem, bool updateContentSizeFitter = true)
        {
            Utilites.UpdateLayout(layout);

            Layout                  = layout;
            DefaultItem             = defaultItem;
            UpdateContentSizeFitter = updateContentSizeFitter;

            isHorizontal = layout is HorizontalLayoutGroup;

            var firstFillerGO        = new GameObject("FirstFiller");
            var firstFillerTransform = firstFillerGO.transform as RectTransform;

            if (firstFillerTransform == null)
            {
                firstFillerTransform = firstFillerGO.AddComponent <RectTransform>();
            }
            firstFillerTransform.SetParent(Layout.transform, false);
            firstFillerTransform.localScale = Vector3.one;
            FirstFiller = firstFillerGO.AddComponent <LayoutElement>();

            var lastFillerGO        = new GameObject("LastFiller");
            var lastFillerTransform = lastFillerGO.transform as RectTransform;

            if (lastFillerTransform == null)
            {
                lastFillerTransform = lastFillerGO.AddComponent <RectTransform>();
            }
            lastFillerTransform.SetParent(Layout.transform, false);
            lastFillerTransform.localScale = Vector3.one;
            LastFiller = lastFillerGO.AddComponent <LayoutElement>();

            var size = GetItemSize();

            if (IsHorizontal)
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
            }
            else
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
            }

            fitter = Layout.GetComponent <ContentSizeFitter>();
        }
Exemple #30
0
        void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
        {
            if (!m_region.CanResize)
            {
                return;
            }
            if (!m_isEnabled)
            {
                return;
            }

            if (m_isFree)
            {
                Vector2 position = eventData.position;
                Camera  camera   = eventData.pressEventCamera;

                RectTransform rt = (RectTransform)transform;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, position, camera, out m_adjustment);
            }
            if (m_forceRebuildLayoutImmediate)
            {
                List <HorizontalOrVerticalLayoutGroup> lgList = new List <HorizontalOrVerticalLayoutGroup>();
                Region[] regions = m_region.Root.GetComponentsInChildren <Region>();
                for (int i = 0; i < regions.Length; ++i)
                {
                    HorizontalOrVerticalLayoutGroup lg = regions[i].ChildrenPanel.GetComponent <HorizontalOrVerticalLayoutGroup>();
                    if (lg != null)
                    {
                        lgList.Add(lg);
                    }
                    lg = regions[i].Content.GetComponent <HorizontalOrVerticalLayoutGroup>();
                    if (lg != null)
                    {
                        lgList.Add(lg);
                    }
                }
                m_layoutGroups = lgList.ToArray();
            }

            if (BeginResize != null)
            {
                BeginResize(this, m_region);
            }

            m_isDragging = true;
        }