예제 #1
0
    public static BannerData Create(JsonDAO jdao, ListItemModel listItemModel)
    {
        BannerData d = new BannerData(listItemModel);

        d.banner   = String.Format("{0}/{1}", GlobalDefine.GetBaseBannerUrl(), jdao.GetStr("banner"));
        d.priority = jdao.GetInt("priority");
        d.link     = jdao.GetStr("link");

#if BUILD_TYPE_DEBUG
        Debug.Log("CALL BatchData#Create banner:" + d.banner + " priority:" + d.priority);
#endif
        return(d);
    }
예제 #2
0
    IEnumerator _LoadAndShow(Type _type, System.Action setupFinish)
    {
        string url = null;

        System.Action errorAction = null;

        switch (_type)
        {
        case Type.Title:
            url         = GlobalDefine.GetTapBannerListUrl();
            errorAction = errorBannerTitle;
            break;

        case Type.Menu:
        case Type.Quest:
            url         = GlobalDefine.GetMainMenuBannerListUrl();
            errorAction = errorBannerMenu;
            break;

        default:
            errorAction = errorBannerMenu;
            break;
        }

        if (url == null)
        {
            if (errorAction != null)
            {
                errorAction();
            }

            yield break;
        }

        WWW www = new WWW(url);

        yield return(www);

#if BUILD_TYPE_DEBUG
        Debug.Log("url:" + url);
        Debug.Log("JSON:" + www.text);
#endif


        if (www.error.IsNOTNullOrEmpty())
        {
            if (errorAction != null)
            {
                errorAction();
            }
            yield break;
        }

        if (www.text.IsNullOrEmpty())
        {
            if (errorAction != null)
            {
                errorAction();
            }
            yield break;
        }

        List <BannerData> list    = new List <BannerData>();
        List <object>     objList = MiniJSON.Json.Deserialize(www.text) as List <object>;
        if (objList.Count == 0)
        {
            if (errorAction != null)
            {
                errorAction();
            }
            yield break;
        }

        int count    = 0;
        int objCount = 0;

#if UNITY_IPHONE
        Platform bannerPlatform = Platform.IOS;
#elif UNITY_ANDROID
        Platform bannerPlatform = Platform.ANDROID;
#elif UNITY_WINDOWS
        Platform bannerPlatform = Platform.WINDOWS;
#else
        Platform bannerPlatform = Platform.NONE;
#endif

        object[] banners = objList.ToArray();
        for (int bannercount = 0; bannercount < banners.Length; bannercount++)
        {
            JsonDAO jdao         = JsonDAO.Create(banners[bannercount]);
            var     timing_start = jdao.GetInt("timing_start");
            var     timing_end   = jdao.GetInt("timing_end");
            var     platform     = (Platform)jdao.GetInt("platform", (int)Platform.NONE);
            var     location     = jdao.GetList("location");

            if (platform != bannerPlatform &&
                platform != Platform.ALL)
            {
                continue;
            }

            if (timing_start != 0 &&
                timing_end != 0)
            {
                if (TimeManager.Instance.CheckWithinTime((uint)timing_start, (uint)timing_end) == false)
                {
                    continue;
                }
            }

            bool bCheckScreen = true;
            if (location.Count != 0)
            {
                bCheckScreen = false;
                for (int i = 0; i < location.Count; ++i)
                {
                    switch ((Location)System.Convert.ToInt32(location[i]))
                    {
                    case Location.HOME:
                        if (_type == Type.Menu)
                        {
                            bCheckScreen = true;
                        }
                        break;

                    case Location.QUEST:
                        if (_type == Type.Quest)
                        {
                            bCheckScreen = true;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            if (bCheckScreen == false)
            {
                continue;
            }

            var        model = new ListItemModel((uint)objCount);
            BannerData d     = BannerData.Create(jdao, model);
            m_banners.Add(model);
            objCount++;

            d.LoadTexture(() =>
            {
                count++;

                if (d.Texture != null)
                {
                    list.Add(d);
                }
                if (count == objCount)
                {
                    if (list.Count == 0)
                    {
                        if (errorAction != null)
                        {
                            errorAction();
                        }
                    }
                    else
                    {
                        carouselRotator.ResetWaitTimer();

                        list.Sort((a, b) =>
                        {
                            int ret = a.priority - b.priority;
                            return(ret != 0 ? ret : (int)a.model.index - (int)b.model.index);
                        });

                        Collection = list;

                        if (setupFinish != null)
                        {
                            setupFinish();
                        }
                    }
                }
            });
        }
    }