T
Tinus

  • Jul 20, 2022
  • Joined Jul 20, 2022
  • Anthony
    dtappe

    Hi, I have a similar issue, where I add and remove ResponsiveContainer child components.
    Don't know if this helps but I made these changes that currently solves my issue.
    and also prevents continuous Resize() update calls.

    Update to ResponsiveItem.cs

        [ExecuteAlways]
        public class ResponsiveItem : MonoBehaviour
        {
            public ResponsiveContainer.ResponsiveItemData settings;
    
            private void OnEnable()
            {
                InvokeParentsOnTransformChildrenChanged();
            }
    
            private void OnDisable()
            {
                InvokeParentsOnTransformChildrenChanged();
            }
            
            private void OnRectTransformDimensionsChange()
            {
                InvokeParentsOnTransformChildrenChanged();
            }
    
            private void InvokeParentsOnTransformChildrenChanged()
            {
                var containers = GetComponentsInParent<ResponsiveContainer>();
                foreach (var container in containers)
                {
                    container.OnTransformChildrenChanged();
                }
            }
        }

    Update to ResponsiveContainer.cs (line 52 to 71) in v1.0.2

            void Start()
            {
                Init();
                Resize(!Application.isPlaying);
            }
    
            private bool transformChildrenChanged;
            public void OnTransformChildrenChanged()
            {
                if (container != null)
                {
                    activeChildren = GetChildrenFirstDepth(container);
                    activeChildCount = activeChildren.Count;
                }
    
                transformChildrenChanged = true;
            }
    
            /// <summary>
            /// Initialize the component
            /// </summary>
            private void Init()
            {
                container = GetComponent<RectTransform>();
                activeChildren = GetChildrenFirstDepth(container);
                activeChildCount = activeChildren.Count;
            }
    
            void Update()
            {
                if (!transformChildrenChanged)
                    return;
                transformChildrenChanged = false;
                
                // Force resize only when not playing
                Resize(!Application.isPlaying);
            }

    Oh. PS.
    I added a "Assembly Definition" - Exoa.Responsive.asmdef to the Exoa -> ResponsiveUI root folder.
    this was required to add it as a Assembly Definition Reference in one of my project files that also has it's own Assembly Definition.