Created
December 24, 2019 17:33
-
-
Save ayutaz/510b7a3e2a91db5d1f88dff686a3b8ec to your computer and use it in GitHub Desktop.
Twityを使い,UnityでTwitterを使う(特定のワードを検索をする,VR空間上に生成して表示する) 続き
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Twity.DataModels.Responses; | |
using UnityEngine.UI; | |
public class EventHandler : MonoBehaviour { | |
private config key; | |
public GameObject prefab; | |
GameObject temp; | |
private Text userName; | |
private Text content; | |
void Start () { | |
key = GameObject.Find("Config").GetComponent<config>(); | |
Twity.Oauth.consumerKey = key.GetConsumerKey(); | |
Twity.Oauth.consumerSecret = key.GetConsumerSecret(); | |
Twity.Oauth.accessToken = key.GetAccessToken(); | |
Twity.Oauth.accessTokenSecret = key.GetAccessTokenSecret(); | |
Dictionary<string, string> parameters = new Dictionary<string, string>(); | |
parameters ["q"] = "悠遠物語"; | |
parameters ["count"] = 30.ToString();; | |
StartCoroutine (Twity.Client.Get ("search/tweets", parameters, Callback)); | |
} | |
void Callback(bool success, string response) { | |
if (success) { | |
SearchTweetsResponse Response = JsonUtility.FromJson<SearchTweetsResponse> (response); | |
// Debug.Log(Response.statuses[2].text); | |
for(int i = 0;i <Response.statuses.Length;i++){ | |
// テキストの配列に入っているテキストを表示する | |
// string text = Response.statuses[i].text; | |
Debug.Log("ツイート内容:"+Response.statuses[i].text); | |
Debug.Log("名前:" + Response.statuses[i].user.name); | |
CreateWindow(Response.statuses[i].user.name,Response.statuses[i].text); | |
} | |
} else { | |
Debug.Log (response); | |
} | |
} | |
void CreateWindow(string name,string content){ | |
// 床の範囲は -3 <= x,z <= 3になっている | |
temp = Instantiate (prefab, new Vector3(Random.Range(-3.0f,3.0f),-0.7f,Random.Range(-3.0f,3.0f)), Quaternion.identity); | |
temp.GetComponent<TextChange>().Change(name,content); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class TextChange : MonoBehaviour { | |
public Text n; | |
public Text c; | |
// Use this for initialization | |
public void Change(string _n,string _c){ | |
n.text = _n; | |
c.text = _c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment