Beispiel #1
0
    public static IEnumerator GetStories()
    {
        WWW wWW = new WWW("http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=252490&count=8&format=json&feeds=steam_community_announcements");

        yield return(wWW);

        JSON.Object objs = JSON.Object.Parse(wWW.text);
        wWW.Dispose();
        if (objs == null)
        {
            yield break;
        }
        JSON.Array array = objs.GetObject("appnews").GetArray("newsitems");
        List <SteamNewsSource.Story> stories = new List <SteamNewsSource.Story>();

        foreach (Value value in array)
        {
            string str = value.Obj.GetString("contents", "Missing URL");
            SteamNewsSource.Story story = new SteamNewsSource.Story()
            {
                name   = value.Obj.GetString("title", "Missing Title"),
                url    = value.Obj.GetString("url", "Missing URL"),
                date   = value.Obj.GetInt("date", 0),
                text   = str,
                author = value.Obj.GetString("author", "Missing Author")
            };
            stories.Add(story);
        }
        SteamNewsSource.Stories = stories.ToArray();
    }
    public void SetStory(SteamNewsSource.Story story)
    {
        PlayerPrefs.SetInt("lastNewsDate", story.date);
        this.title.text = story.name;
        string str = ((long)(Epoch.Current - story.date)).FormatSecondsLong();

        this.date.text = string.Concat("Posted ", str, " ago");
        string str1 = Regex.Replace(story.text, "\\[img\\].*\\[\\/img\\]", string.Empty, RegexOptions.IgnoreCase);

        str1 = str1.Replace("\\n", "\n").Replace("\\r", "").Replace("\\\"", "\"");
        str1 = str1.Replace("[list]", "<color=#F7EBE1aa>");
        str1 = str1.Replace("[/list]", "</color>");
        str1 = str1.Replace("[*]", "\t\t» ");
        str1 = Regex.Replace(str1, "\\[(.*?)\\]", string.Empty, RegexOptions.IgnoreCase);
        str1 = str1.Trim();
        Match match  = Regex.Match(story.text, "url=(http|https):\\/\\/([\\w\\-_]+(?:(?:\\.[\\w\\-_]+)+))([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])");
        Match match1 = Regex.Match(story.text, "(http|https):\\/\\/([\\w\\-_]+(?:(?:\\.[\\w\\-_]+)+))([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])(.png|.jpg)");

        if (match == null)
        {
            this.button.gameObject.SetActive(false);
        }
        else
        {
            string str2 = match.Value.Replace("url=", "");
            if (str2 == null || str2.Trim().Length <= 0)
            {
                str2 = story.url;
            }
            this.button.gameObject.SetActive(true);
            this.button.onClick.RemoveAllListeners();
            this.button.onClick.AddListener(() => {
                Debug.Log(string.Concat("Opening URL: ", str2));
                Application.OpenURL(str2);
            });
        }
        this.text.text       = str1;
        this.authorName.text = string.Format("by {0}", story.author);
        if (match1 != null)
        {
            this.image.Load(match1.Value);
        }
    }