akadoc/Assets/scripts/CreateScrollList.cs

70 lines
1.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using System.Collections;
[System.Serializable]
public class Item{
public string name;
public Sprite icon;
public string message;
Button.ButtonClickedEvent clickEvent;
}
public class CreateScrollList : MonoBehaviour {
public GameObject sampleButton;
public List<Item> itemList;
public Transform contentPanel;
public Image portrait;
public ScrollRect scrollrect;
GameObject chat_input;
TchatAnim tchatAnim;
string message_old;
// Use this for initialization
void Start () {
//PopulateList ();
chat_input = GameObject.Find ("tchat_complet");
tchatAnim = chat_input.GetComponent<TchatAnim> ();
}
void PopulateList(){
foreach (var item in itemList) {
GameObject newButton = Instantiate (sampleButton) as GameObject;
SampleButton button = newButton.GetComponent <SampleButton> ();
button.nameLabel.text = item.name;
button.icon.sprite = item.icon;
button.message.text = item.message;
newButton.transform.SetParent (contentPanel);
button.gameObject.SetActive(true);
}
}
// Update is called once per frame
void Update () {
scrollrect.verticalNormalizedPosition = 0;
if (Input.GetKeyDown ("space")&& tchatAnim.message != message_old) {
GameObject myNewButton = Instantiate (sampleButton) as GameObject;
SampleButton button = myNewButton.GetComponent<SampleButton> ();
button.nameLabel.text="perceval";
button.message.text = tchatAnim.message;
button.icon.sprite= portrait.sprite;
button.gameObject.SetActive(true);
myNewButton.transform.SetParent(contentPanel);
message_old= tchatAnim.message;
}
}
}