Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by trop · Oct 19, 2012 at 07:20 AM · uitoolkit

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges