예제 #1
0
 public ComputeVisibilityManager(OSA <TParams, TItemViewsHolder> adapter)
 {
     _Adapter       = adapter;
     _Params        = _Adapter.Parameters;
     _InternalState = _Adapter._InternalState;
     _ItemsDesc     = _Adapter._ItemsDesc;
 }
예제 #2
0
        protected InternalState(BaseParams sourceParams, ItemsDescriptor itemsDescriptor)
        {
            _SourceParams = sourceParams;
            _ItemsDesc    = itemsDescriptor;

            var lg = sourceParams.Content.GetComponent <LayoutGroup>();

            if (lg && lg.enabled)
            {
                lg.enabled = false;
                Debug.Log("LayoutGroup on GameObject " + lg.name + " has beed disabled in order to use OSA");
            }

            var contentSizeFitter = sourceParams.Content.GetComponent <ContentSizeFitter>();

            if (contentSizeFitter && contentSizeFitter.enabled)
            {
                contentSizeFitter.enabled = false;
                Debug.Log("ContentSizeFitter on GameObject " + contentSizeFitter.name + " has beed disabled in order to use OSA");
            }

            var layoutElement = sourceParams.Content.GetComponent <LayoutElement>();

            if (layoutElement)
            {
                GameObject.Destroy(layoutElement);
                Debug.Log("LayoutElement on GameObject " + contentSizeFitter.name + " has beed DESTROYED in order to use OSA");
            }

            //if (sourceParams.IsHorizontal)
            //{
            //	layoutInfo.startEdge = RectTransform.Edge.Left;
            //	layoutInfo.endEdge = RectTransform.Edge.Right;
            //	layoutInfo.transvStartEdge = RectTransform.Edge.Top;
            //	//getRTCurrentSizeFn = root => root.rect.width;
            //}
            //else
            //{
            //	layoutInfo.startEdge = RectTransform.Edge.Top;
            //	layoutInfo.endEdge = RectTransform.Edge.Bottom;
            //	layoutInfo.transvStartEdge = RectTransform.Edge.Left;
            //	//getRTCurrentSizeFn = root => root.rect.height;
            //}
        }
예제 #3
0
 internal static InternalState <TItemViewsHolder> CreateFromSourceParamsOrThrow(BaseParams sourceParams, ItemsDescriptor itemsDescriptor)
 {
     return(new InternalState <TItemViewsHolder>(sourceParams, itemsDescriptor));
 }
예제 #4
0
        protected override void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
        {
            base.CollectItemsSizes(changeMode, count, indexIfInsertingOrRemoving, itemsDesc);

            if (changeMode != ItemCountChangeMode.RESET)
            {
                return;
            }

            if (count == 0)
            {
                return;
            }

            // Randomize sizes
            int indexOfFirstItemThatWillChangeSize = 0;
            int end = indexOfFirstItemThatWillChangeSize + count;

            itemsDesc.BeginChangingItemsSizes(indexOfFirstItemThatWillChangeSize);
            for (int i = indexOfFirstItemThatWillChangeSize; i < end; ++i)
            {
                itemsDesc[i] = UnityEngine.Random.Range(_Params.DefaultItemSize / 3, _Params.DefaultItemSize * 3);
            }
            itemsDesc.EndChangingItemsSizes();
        }
예제 #5
0
        /// <inheritdoc/>
        protected override void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
        {
            base.CollectItemsSizes(changeMode, count, indexIfInsertingOrRemoving, itemsDesc);

            // CollectItemsSizes is called whenever the items count changes, but before the view is actually updated.
            // The reason we need it here is that when inserting an item, it's initial size will be _Params.DefaultItemSize
            // (which is taken from the prefab's actual size), but we want it to be NON_EXPANDED_SIZE (which is close to zero),
            // so we can expand it after.
            // It's not something very important, but it looks a bit odd without it

            if (changeMode != ItemCountChangeMode.INSERT)
            {
                return;
            }

            if (count > 1)
            {
                // Not an animated insertion, since the count would've been 1 in that case
                return;
            }

            if (_InsertDeleteAnimation == null)
            {
                // No animation running => the item will directly appear expanded (with _Params.DefaultItemSize)
                return;
            }

            if (_InsertDeleteAnimation.itemIndex == indexIfInsertingOrRemoving)
            {
                itemsDesc.BeginChangingItemsSizes(indexIfInsertingOrRemoving);
                itemsDesc[indexIfInsertingOrRemoving] = NON_EXPANDED_SIZE;
                itemsDesc.EndChangingItemsSizes();
            }
        }