相変わらずUnityでゲーム以外を作ってます。
使い方間違えてる気がしてならない。
yahooニュースから記事のタイトルを引っ張ってきて、前後に分割。
その後、適当に組み合わせるという適当ニュースリーダー。
メーカーのほうがいいかな?
動いてるのはこんな感じ。
今回はデスクトップアプリ。
小さいのでデスクトップの端にでもどうぞ。
一応macとlinux版も用意したけど、環境が無いので動作確認してません。
普通に動くだろうとは思うけど…。
ソースコードはこんな感じ。
using UnityEngine; using UnityEngine.UI; using System; using System.Collections; using System.Xml; public class tex : MonoBehaviour { [SerializeField] string str; ArrayList words1 = new ArrayList(); ArrayList words2 = new ArrayList(); XmlDocument doc = new XmlDocument(); DateTime odt; string[] urls = {@"http://news.yahoo.co.jp/pickup/domestic/rss.xml", @"http://news.yahoo.co.jp/pickup/world/rss.xml", @"http://news.yahoo.co.jp/pickup/economy/rss.xml", @"http://news.yahoo.co.jp/pickup/entertainment/rss.xml", @"http://news.yahoo.co.jp/pickup/sports/rss.xml", @"http://news.yahoo.co.jp/pickup/computer/rss.xml", @"http://news.yahoo.co.jp/pickup/science/rss.xml", @"http://news.yahoo.co.jp/pickup/local/rss.xml"}; void Awake() { // PC向けビルドだったらサイズ変更 if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.LinuxPlayer) { Screen.SetResolution(300, 300, false); } odt = DateTime.Now; } // Use this for initialization void Start() { StartCoroutine("getdd"); StartCoroutine("make"); } // Update is called once per frame void Update () { if (odt.Hour != DateTime.Now.Hour) { StartCoroutine("getdd"); odt = DateTime.Now; } } IEnumerator make() { while (true) { yield return new WaitForSeconds(3.0f); string n = words1[UnityEngine.Random.Range(0, words1.Count)] + " " + words2[UnityEngine.Random.Range(0, words2.Count)]; this.GetComponent<Text>().text = n; } } IEnumerator getdd() { for (int j = 0; j < urls.Length; j++) { WWW net = new WWW(urls[j]); yield return net; doc.LoadXml(net.text); XmlNodeList docl = doc.GetElementsByTagName("title"); for (int i = 1; i < docl.Count; i++) { string[] ss = docl[i].InnerText.Split(' '); if (ss.Length == 2) { words1.Add(ss[0]); words2.Add(ss[1]); } } } } }

- 出版社/メーカー: Yahoo Japan Corp.
- 発売日: 2014/03/12
- メディア: アプリ
- この商品を含むブログを見る