public virtual void SetLayoutVertical()
 {
     if (ScrollLayoutGroup != null && ScrollLayoutGroup.IsVertical())
     {
         ApplyElementSize();
     }
 }
 protected void ApplyElementSize()
 {
     CancelInvoke("ApplyElementSize");
     if (ScrollLayoutGroup != null && LayoutElementIndex >= 0 && _isVisible)
     {
         ScrollLayoutGroup.SetCachedElementSize(LayoutElementIndex, ScrollLayoutGroup.CalculateElementSize(transform, ScrollLayoutGroup.IsVertical()));
     }
 }
        protected override void OnDisable()
        {
            CancelInvoke();
            UnregisterEvents();
            base.OnDisable();

            //Recalculate element size ignoring this element position (object disabled)
            if (!gameObject.activeSelf && ScrollLayoutGroup != null)
            {
                ScrollLayoutGroup.SetCachedElementsLayoutDirty();
            }

            _previousActiveSelf = gameObject.activeSelf;
        }
        protected override void OnEnable()
        {
            if (ScrollLayoutGroup != null)
            {
                RegisterEvents();
            }
            base.OnEnable();

            if (_started && gameObject.activeInHierarchy && enabled)
            {
                //ApplyElementSize();
                //Force recalculate element
                if (!_previousActiveSelf && ScrollLayoutGroup != null)
                {
                    ScrollLayoutGroup.SetCachedElementsLayoutDirty();
                }
            }

            _previousActiveSelf = gameObject.activeSelf;
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(15);
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Recalculate Elements Layout", GUILayout.Width(200)))
                {
                    serializedObject.Update();
                    foreach (var v_target in targets)
                    {
                        ScrollLayoutGroup v_castedTarget = v_target as ScrollLayoutGroup;
                        if (v_castedTarget != null)
                        {
                            v_castedTarget.SetCachedElementsLayoutDirty(true);
                            v_castedTarget.TryRecalculateLayout(true);
                            UnityEditor.EditorUtility.SetDirty(v_castedTarget);
                        }
                    }
                    serializedObject.ApplyModifiedProperties();
                }
                GUILayout.FlexibleSpace();
            }

            serializedObject.Update();
            DrawPropertiesExcluding(serializedObject, _elementsToIgnore);
            serializedObject.ApplyModifiedProperties();

            if (GUI.changed)
            {
                foreach (var v_target in targets)
                {
                    ScrollLayoutGroup v_castedTarget = v_target as ScrollLayoutGroup;
                    if (v_castedTarget != null)
                    {
                        v_castedTarget.SetCachedElementsLayoutDirty();
                    }
                }
            }
        }
        /*protected override void OnRectTransformDimensionsChange()
         * {
         *  base.OnRectTransformDimensionsChange();
         *  if (enabled)
         *      SetElementSizeDirty();
         * }*/

        protected override void OnTransformParentChanged()
        {
            base.OnTransformParentChanged();
            ScrollLayoutGroup = ScrollLayoutGroup.GetComponentInParent <ScrollLayoutGroup>(this, true);
            SetDirty();
        }