Exemplo n.º 1
0
        /// <summary>Creates a viewsholder, depending on the type of the model at index <paramref name="itemIndex"/></summary>
        /// <seealso cref="OSA{TParams, TItemViewsHolder}.CreateViewsHolder(int)"/>
        protected override SimpleBaseVH CreateViewsHolder(int itemIndex)
        {
            var modelType = Data[itemIndex].CachedType;

            if (modelType == typeof(GreenModel))
            {
                var vh = new GreenVH();
                vh.Init(_Params.greenPrefab, _Params.Content, itemIndex);

                return(vh);
            }

            if (modelType == typeof(OrangeModel))
            {
                var vh = new OrangeVH();
                vh.Init(_Params.orangePrefab, _Params.Content, itemIndex);

                return(vh);
            }

            if (modelType == typeof(AdModel))
            {
                var vh = new AdVH();
                vh.Init(_Params.adPrefab, _Params.Content, itemIndex);
                vh.Clicked += OnAdClicked;
                return(vh);
            }

            // If you want to avoid ifs, you could use a dictionary with model type as key and a Func<int, SimpleBaseHV> as value
            // which would point to a separate method for each model type. Then here simply return _Map[modelType](itemIndex)

            throw new InvalidOperationException("Unrecognized model type: " + modelType.Name);
        }
Exemplo n.º 2
0
        void OnAdClicked(AdVH vh)
        {
            var adModel = Data[vh.ItemIndex] as AdModel;

            Debug.Log("Ad clicked: item #" + vh.ItemIndex + ", ID = " + adModel.adID);
        }