将JSON网址图片解析为Scrollview-Unity

时间:2018-07-21 14:27:29

标签: json unity3d scrollview

我正在一个统一的项目中,我必须从JSON文件解析图像URL列表,并将其作为源图像添加到动态变化的scrollview内容中。我创建了可序列化的类和动态spwaner,它们将动态滚动滚动视图上的按钮。如何使用我拥有的当前JSON图像URL填充此列表。谢谢

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;

[System.Serializable]
public class Person
{
	public string name;
	public Sprite icon;
}

public class CreateScrollList : MonoBehaviour
{

	public GameObject namePrefab;
	public List<Person> personList;

	public Transform contentPanel;

	// Use this for initialization
	void Start()
	{

		PopulateList();
	}

	void PopulateList()
	{
		foreach (var person in personList)
		{
			GameObject newPerson = Instantiate(namePrefab) as GameObject;
			NamePrefab generatedName = newPerson.GetComponent<NamePrefab>();
			generatedName.nameLabel.text = person.name;
			generatedName.icon = person.icon;
			newPerson.transform.SetParent(contentPanel);

		}
	}
}

{
  "array": [
    "https://cdn1.iconfinder.com/data/icons/hawcons/32/699297-icon-68-document-file-app-512.png",
    "https://d1gzq6u422bfcj.cloudfront.net/workflow_icons/99b9a7050c2f46b4b0b657e4ab0bedf4.png",
    "https://cfcdnpull-creativefreedoml.netdna-ssl.com/wp-content/uploads/2016/06/New-instagram-icon.jpg"
  ]
}

0 个答案:

没有答案