- Home /
how to put downloaded images into UIButton using UIToolkit
hi! i wonder how to put downloaded images inside a UI Button.
heres my code:
using LitJson;
using UnityEngine;
using System.Collections;
using System.Text;
using Prime31;
using System.Collections.Generic;
public class LoadJSON_FBFriends : MonoBehaviour
{
private bool _movedContainer;
public Material loadImageMaterial;
private UIToolkit myToolkit;
UIButton touchable,b1;
private string userId;
private Dictionary<string, string> friends;
ArrayList friendsList;
public GUIStyle friendsFontStyle;
void Start()
{
var scrollable = new UIScrollableVerticalLayout( 0 );
scrollable.alignMode = UIAbstractContainer.UIContainerAlignMode.Center;
scrollable.position = new Vector3( 0, 3, 0 );
var width = UI.scaleFactor * 800;
scrollable.setSize( width, Screen.height / 0.10f );
for( var i = 0; i < 13; i++ )
{
if( i == 13 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 12 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0);
}
else if( i % 11 == 0 )
{
touchable = UIButton.create( "FriendsAvatar.png", "FriendsAvatar.png", 0, 0);
}
else if( i % 10 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 9 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 8 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 7 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 6 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 5 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 4 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 3 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else if( i % 2 == 0 )
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0 );
}
else
{
touchable = UIButton.create( "FriendsListBox.png", "FriendsListBox.png", 0, 0);
}
//loadImage(touchable, i);
StartCoroutine(getImage(touchable, i));
scrollable.addChild(touchable);
}
}
IEnumerator getImage(UIButton uib, int i)
{
ConverterScript ss = new ConverterScript();
string url = "https://graph.facebook.com/xxxxxxx/friends?limit=13&fields=first_name,picture&access_token=xxxxxx";
WWW www = new WWW(url);
yield return www;
Texture2D tex = new Texture2D(128, 128);
tex = www.texture;
ProcessFriendsDisplay(www.text);
uib.manager.renderer.material.mainTextureScale = new Vector2(18.0f, 20.4f);
uib.manager.renderer.material.mainTexture = tex;
}
public void ProcessFriendsDisplay(string jsonString)
{
JsonData jsonFriends = JsonMapper.ToObject(jsonString);
ConverterScript fbfriends = new ConverterScript();
friendsList = new ArrayList();
for(int i = 0; i<jsonFriends["data"].Count; i++)
{
fbfriends.picture = jsonFriends["data"][i]["picture"]["data"]["url"].ToString();
Debug.Log (fbfriends.picture + i);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Accessing C# Delegate from Javascript 1 Answer
Is it possible to draw objects on the canvas before the ui elements runtime? 0 Answers
How do I update an image on a visual element at runtime in ui toolkit? 0 Answers
image stretched when packing textures in large size 1 Answer
Can't resolve UnityEngine.UIElements.UIDocument type with UIToolkit 1 Answer