Ejemplo n.º 1
0
    public List <JsonDAO> GetJsonDAOList(string key)
    {
        List <JsonDAO> list = new List <JsonDAO>();
        string         str  = GetStr(key);

        if (str.IsNullOrEmpty())
        {
            return(list);
        }

#if BUILD_TYPE_DEBUG
        Debug.Log("KEY:" + key + " STR:" + str);
#endif
        foreach (object obj in MiniJSON.Json.Deserialize(str) as List <object> )
        {
            JsonDAO jdao = JsonDAO.Create(obj);
            list.Add(jdao);
        }

        return(list);
    }
Ejemplo n.º 2
0
 public static JsonDAO ToJsonDAO(this string json)
 {
     return(JsonDAO.Create(json));
 }
Ejemplo n.º 3
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();
                        }
                    }
                }
            });
        }
    }