Example #1
0
        public override void BindData(int currentIndex, Room data)
        {
            _data = data;
            if (data == null)
            {
                // 如果没有数据的话,应该怎么显示房间按钮呢?
                // 房间可以不显示,但是是不是要显示在线人数。
                return;
            }

            // 载入人数和底注。
            BaseMoney.SetCurrency(_data.base_money, CurrencyType.GOLDEN_EGG);
            PlayerCount.text = "" + data.current_player_num;

            // 载入房间图片。
            if (string.IsNullOrEmpty(data.room_pic))
            {
                RoomPic.Reset();
            }
            else
            {
                var resourcePath = GetAssetBundleByPicNameMap.GetAssetBundleName(data.room_pic);
                RoomPic.SetTargetPic(data.room_pic, resourcePath, data.room_pic_url);
            }

            if (data.type == RoomType.Ad)
            {
                RoomContainer.SetActive(false);
                TagContainer.SetActive(false);
                var hintItem = data.hint_item;
                if (hintItem != null && !string.IsNullOrEmpty(hintItem.content_pic))
                {
                    var contentPic = _resourceCache.LoadSpriteFromLocalFile(hintItem.content_pic);
                    if (!contentPic)
                    {
                        if (!string.IsNullOrEmpty(hintItem.content_pic_url) &&
                            !_resourceCache.ContainsDownloadTask(hintItem.content_pic))
                        {
                            _resourceCache.StartDownload(
                                hintItem.content_pic,
                                hintItem.content_pic_url,
                                ContentType.Image);
                        }
                    }
                }
            }
            else
            {
                RoomContainer.SetActive(true);
                TagContainer.SetActive(true);
            }

            // 设置标签。
            if (!string.IsNullOrEmpty(data.tag))
            {
                if (!Tag1Group.activeSelf)
                {
                    Tag1Group.SetActive(true);
                }

                Tag1.text = data.tag;
            }
            else
            {
                if (Tag1Group.activeSelf)
                {
                    Tag1Group.SetActive(false);
                }
            }

            if (!string.IsNullOrEmpty(data.tag1))
            {
                if (!Tag2Group.activeSelf)
                {
                    Tag2Group.SetActive(true);
                }

                Tag2.text = data.tag1;
            }
            else
            {
                if (Tag2Group.activeSelf)
                {
                    Tag2Group.SetActive(false);
                }
            }

            if (!Button.gameObject.activeSelf)
            {
                Button.gameObject.SetActive(true);
            }
        }
Example #2
0
        /// <summary>
        /// 设置目标图片  从 cache中找 -> 用initSprite 赋值 -> 从Assetbundle中找 —> 从url下载
        /// </summary>
        /// <param name="picName"></param>
        /// <param name="resourcePath"></param>
        /// <param name="url"></param>
        /// <param name="nativeSize"></param>
        /// <param name="initSprite"></param>
        /// <param name="onCompleteListener"></param>
        /// <returns></returns>
        public bool SetTargetPic(
            string picName,
            string resourcePath,
            string url                    = null,
            bool nativeSize               = false,
            Sprite initSprite             = null,
            OnComplete onCompleteListener = null)
        {
            PicName             = picName;
            ResourcePath        = resourcePath;
            NativeSize          = nativeSize;
            _onCompleteListener = onCompleteListener;

            LastCheckTime = 0;

            if (!ContentImage)
            {
                // 如果没有内容图片,则直接切换到完成状态。
                SwitchToStatus(StatusComplete);
                return(true);
            }

            //先从Cache中取图片
            var sprite = _resourceCache.LoadSpriteFromCache(PicName);

            if (sprite)
            {
                ContentImage.sprite = sprite;
                if (nativeSize)
                {
                    ContentImage.SetNativeSize();
                }

                SwitchToStatus(StatusComplete);
                return(true);
            }

            if (initSprite != null)
            {
                if (ContentImage)
                {
                    ContentImage.sprite = initSprite;
                    if (nativeSize)
                    {
                        ContentImage.SetNativeSize();
                    }

                    if (!ContentImage.gameObject.activeSelf)
                    {
                        ContentImage.gameObject.SetActive(true);
                    }
                }

                if (WaitingImage && WaitingImage.gameObject.activeSelf)
                {
                    WaitingImage.gameObject.SetActive(false);
                }

                SwitchToStatus(StatusComplete);
                return(true);
            }

            SwitchToStatus(StatusChecking, initSprite != null);

            if (!string.IsNullOrEmpty(ResourcePath))
            {
                _downLoadByUrl = false;
                _resource.StartLoadResource(ResourcePath, PicName);
            }
            else
            {
                if (!string.IsNullOrEmpty(url))
                {
                    _downLoadByUrl = true;
                    if (!_resourceCache.ContainsDownloadTask(picName))
                    {
                        _resourceCache.StartDownload(picName, url, ContentType.Image);
                    }
                }
            }

            return(false);
        }