BaseModel CreateNewModel(int id)
        {
            BaseModel model;
            Rect      prefabRect;
            float     initialSize;

            if (UnityEngine.Random.Range(0, 2) == 0)
            {
                prefabRect  = _Params.expandablePrefab.rect;
                initialSize = _Params.scrollRect.horizontal ? prefabRect.width : prefabRect.height;
                model       = new ExpandableModel()
                {
                    imageURL = C.GetRandomSmallImageURL(), nonExpandedSize = initialSize
                };
            }
            else
            {
                prefabRect  = _Params.bidirectionalPrefab.rect;
                initialSize = _Params.scrollRect.horizontal ? prefabRect.width : prefabRect.height;
                model       = new BidirectionalModel()
                {
                    value = UnityEngine.Random.Range(-5f, 5f)
                };
            }
            model.id = id;

            return(model);
        }
Example #2
0
        BaseModel CreateRandomModel(int id)
        {
            BaseModel model;
            Rect      prefabRect;
            float     initialSize;
            var       parameters = _Adapters[0].Parameters;

            if (UnityEngine.Random.Range(0, 2) == 0)
            {
                prefabRect  = parameters.expandablePrefab.rect;
                initialSize = parameters.IsHorizontal ? prefabRect.width : prefabRect.height;
                model       = new ExpandableModel()
                {
                    imageURL = DemosUtil.GetRandomSmallImageURL(), nonExpandedSize = initialSize
                };
            }
            else
            {
                prefabRect  = parameters.bidirectionalPrefab.rect;
                initialSize = parameters.IsHorizontal ? prefabRect.width : prefabRect.height;
                model       = new BidirectionalModel()
                {
                    value = UnityEngine.Random.Range(-5f, 5f)
                };
            }
            model.id = id;

            return(model);
        }
Example #3
0
        /// <summary>Callback from UI Button. Parses the text in <see cref="countText"/> as an int and sets it as the new item count, deleting the old models & randomly creating enough new ones, then refreshing all the views</summary>
        public void UpdateItems()
        {
            int newCount;

            int.TryParse(countText.text, out newCount);


            // Generating some random models
            var newModels = new BaseModel[newCount];

            for (int i = 0; i < newCount; ++i)
            {
                BaseModel model;
                string    titleValue = "[" + i + "]";
                Rect      prefabRect;
                if (UnityEngine.Random.Range(0, 2) == 0)
                {
                    model = new ExpandableModel()
                    {
                        title = titleValue, imageURL = C.GetRandomSmallImageURL()
                    };
                    prefabRect = adapterParams.expandablePrefab.rect;
                }
                else
                {
                    model = new BidirectionalModel()
                    {
                        title = titleValue, value = UnityEngine.Random.Range(-5f, 5f)
                    };
                    prefabRect = adapterParams.bidirectionalPrefab.rect;
                }
                model.visualSize = adapterParams.scrollRect.horizontal ? prefabRect.width : prefabRect.height;

                newModels[i] = model;
            }

            adapterParams.data.Clear();
            adapterParams.data.AddRange(newModels);

            // Just notify the adapter the data changed, so it can refresh the views (even if the count is the same, this must be done)
            _Adapter.ChangeItemCountTo(newModels.Length);
        }