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;
        }
Beispiel #3
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();
                    }
                }
            }
        }